View Javadoc

1   /*******************************************************************************
2    * Copyright (c) 2011 Michael Mimo Moratti.
3    *  
4    * Michael Mimo Moratti licenses this file to you under the Apache License, version 2.0
5    * (the "License"); you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at:
7    *     http://www.apache.org/licenses/LICENSE-2.0
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
11   * License for the specific language governing permissions and limitations
12   * under the License.
13   *******************************************************************************/
14  package ch.mimo.netty.handler.codec.icap;
15  
16  import org.jboss.netty.channel.ChannelDownstreamHandler;
17  import org.jboss.netty.channel.ChannelEvent;
18  import org.jboss.netty.channel.ChannelHandlerContext;
19  import org.jboss.netty.channel.ChannelUpstreamHandler;
20  
21  /**
22   * A combination of @see {@link IcapRequestDecoder} and @see {@link IcapResponseEncoder}
23   * which enables easier server side ICAP implementation.
24   * 
25   * @author Michael Mimo Moratti (mimo@mimo.ch)
26   *
27   * @see IcapRequestDecoder
28   * @see IcapResponseEncoder
29   * @see IcapClientCodec
30   */
31  public class IcapServerCodec implements ChannelUpstreamHandler, ChannelDownstreamHandler {
32  
33  	private final IcapRequestDecoder decoder;
34  	private final IcapResponseEncoder encoder = new IcapResponseEncoder();
35  	
36  	public IcapServerCodec() {
37  		this(4096,8192,8192,8192);
38  	}
39  	
40  	/**
41  	 * @see IcapMessageDecoder IcapMessageDecoder constructor for more details.
42  	 * 
43  	 * @param maxInitialLineLength
44  	 * @param maxIcapHeaderSize
45  	 * @param maxHttpHeaderSize
46  	 * @param maxChunkSize
47  	 */
48  	public IcapServerCodec(int maxInitialLineLength, int maxIcapHeaderSize, int maxHttpHeaderSize, int maxChunkSize) {
49  		decoder = new IcapRequestDecoder(maxInitialLineLength,maxIcapHeaderSize,maxHttpHeaderSize,maxChunkSize);
50  	}
51  	
52  	@Override
53  	public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
54  		encoder.handleDownstream(ctx, e);
55  	}
56  
57  	@Override
58  	public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
59  		decoder.handleUpstream(ctx, e);
60  	}
61  
62  }