1 /* 2 * Copyright 2009 Red Hat, Inc. 3 * 4 * Red Hat 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 6 * License. You may obtain a copy of the License at: 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations 14 * under the License. 15 */ 16 package org.jboss.netty.example.http.upload; 17 18 import static org.jboss.netty.channel.Channels.*; 19 20 import javax.net.ssl.SSLEngine; 21 import javax.net.ssl.SSLException; 22 23 import org.jboss.netty.channel.ChannelPipeline; 24 import org.jboss.netty.channel.ChannelPipelineFactory; 25 import org.jboss.netty.handler.codec.http2.HttpClientCodec; 26 import org.jboss.netty.handler.codec.http2.HttpContentDecompressor; 27 import org.jboss.netty.handler.ssl.SslHandler; 28 import org.jboss.netty.handler.stream.ChunkedWriteHandler; 29 //import org.jboss.netty.example.securechat.SecureChatSslContextFactory; 30 31 /** 32 * @author <a href="http://www.jboss.org/netty/">The Netty Project</a> 33 * @author Andy Taylor (andy.taylor@jboss.org) 34 * @author <a href="http://gleamynode.net/">Trustin Lee</a> 35 * @author <a href="http://openr66.free.fr/">Frederic Bregier</a> 36 * 37 * @version $Rev: 612 $, $Date: 2010-11-11 19:35:43 +0100 (jeu., 11 nov. 2010) $ 38 */ 39 public class HttpClientPipelineFactory implements ChannelPipelineFactory { 40 private final boolean ssl; 41 42 public HttpClientPipelineFactory(boolean ssl) { 43 this.ssl = ssl; 44 } 45 46 public ChannelPipeline getPipeline() throws Exception { 47 // Create a default pipeline implementation. 48 ChannelPipeline pipeline = pipeline(); 49 50 // Enable HTTPS if necessary. 51 if (ssl) { 52 System.err.println("No SSL in this example..."); 53 throw new SSLException("No SSL in this example"); 54 /* 55 SSLEngine engine = 56 SecureChatSslContextFactory.getClientContext().createSSLEngine(); 57 engine.setUseClientMode(true); 58 59 pipeline.addLast("ssl", new SslHandler(engine));*/ 60 } 61 62 pipeline.addLast("codec", new HttpClientCodec()); 63 64 // Remove the following line if you don't want automatic content decompression. 65 pipeline.addLast("inflater", new HttpContentDecompressor()); 66 67 // to be used since huge file transfer 68 pipeline.addLast("chunkedWriter", new ChunkedWriteHandler()); 69 70 pipeline.addLast("handler", new HttpResponseHandler()); 71 return pipeline; 72 } 73 }