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 IcapRequestEncoder} and @see {@link IcapResponseDecoder}
23   * which enables easier client side ICAP implementation.
24   * 
25   * @author Michael Mimo Moratti (mimo@mimo.ch)
26   *
27   * @see IcapRequestEncoder
28   * @see IcapResponseDecoder
29   * @see IcapServerCodec
30   */
31  public class IcapClientCodec implements ChannelUpstreamHandler, ChannelDownstreamHandler {
32  
33  	private final IcapRequestEncoder encoder = new IcapRequestEncoder();
34  	private final IcapResponseDecoder decoder;
35  	
36  	/**
37  	 * @see IcapMessageDecoder IcapMessageDecoder constructor for more details.
38  	 * 
39  	 * @param maxInitialLineLength
40  	 * @param maxIcapHeaderSize
41  	 * @param maxHttpHeaderSize
42  	 * @param maxChunkSize
43  	 */
44  	public IcapClientCodec(int maxInitialLineLength, int maxIcapHeaderSize, int maxHttpHeaderSize, int maxChunkSize) {
45  		decoder = new IcapResponseDecoder(maxInitialLineLength,maxIcapHeaderSize,maxHttpHeaderSize,maxChunkSize);
46  	}
47  	
48  	public IcapClientCodec() {
49  		this(4096,8192,8192,8192);
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  }