Merge pull request #468 from fredericBregier/3

Fix issue when SSL is used on top of the Multipart. See #468
This commit is contained in:
Norman Maurer 2012-07-23 01:18:22 -07:00
commit a76e8a8e36
5 changed files with 26 additions and 7 deletions

View File

@ -124,6 +124,7 @@ public class HttpUploadClient {
DiskAttribute.baseDirectory = null; // system temp directory DiskAttribute.baseDirectory = null; // system temp directory
// Simple Get form: no factory used (not usable) // Simple Get form: no factory used (not usable)
System.err.println("==========================================\nStarting Get\n==========================================");
List<Entry<String, String>> headers = List<Entry<String, String>> headers =
formget(bootstrap, host, port, get, uriSimple); formget(bootstrap, host, port, get, uriSimple);
if (headers == null) { if (headers == null) {
@ -131,6 +132,7 @@ public class HttpUploadClient {
return; return;
} }
// Simple Post form: factory used for big attributes // Simple Post form: factory used for big attributes
System.err.println("==========================================\nStarting Simple Post\n==========================================");
List<InterfaceHttpData> bodylist = List<InterfaceHttpData> bodylist =
formpost(bootstrap, host, port, uriSimple, file, factory, headers); formpost(bootstrap, host, port, uriSimple, file, factory, headers);
if (bodylist == null) { if (bodylist == null) {
@ -138,6 +140,7 @@ public class HttpUploadClient {
return; return;
} }
// Multipart Post form: factory used // Multipart Post form: factory used
System.err.println("==========================================\nStarting PostUpload Multipart\n==========================================");
formpostmultipart(bootstrap, host, port, uriFile, factory, headers, bodylist); formpostmultipart(bootstrap, host, port, uriFile, factory, headers, bodylist);
// Shut down executor threads to exit. // Shut down executor threads to exit.
@ -365,6 +368,7 @@ public class HttpUploadClient {
} }
// send request // send request
System.err.println("Request is chunked? " + request.isChunked() + ":" + bodyRequestEncoder.isChunked());
channel.write(request); channel.write(request);
// test if request was chunked and if so, finish the write // test if request was chunked and if so, finish the write
@ -393,8 +397,10 @@ public class HttpUploadClient {
new HttpUploadClient(baseUri, filePath).run(); new HttpUploadClient(baseUri, filePath).run();
} }
// use to simulate a small TEXTAREA field in a form
private static final String textArea = "short text";
// use to simulate a big TEXTAREA field in a form // use to simulate a big TEXTAREA field in a form
private static final String textArea = private static final String textAreaLong =
"lkjlkjlKJLKJLKJLKJLJlkj lklkj\r\n\r\nLKJJJJJJJJKKKKKKKKKKKKKKK <20><><EFBFBD><EFBFBD>&\r\n\r\n" + "lkjlkjlKJLKJLKJLKJLJlkj lklkj\r\n\r\nLKJJJJJJJJKKKKKKKKKKKKKKK <20><><EFBFBD><EFBFBD>&\r\n\r\n" +
"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\r\n" + "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\r\n" +
"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\r\n" + "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\r\n" +

View File

@ -44,7 +44,9 @@ public class HttpUploadClientPipelineFactory implements ChannelPipelineFactory {
SecureChatSslContextFactory.getClientContext().createSSLEngine(); SecureChatSslContextFactory.getClientContext().createSSLEngine();
engine.setUseClientMode(true); engine.setUseClientMode(true);
pipeline.addLast("ssl", new SslHandler(engine)); SslHandler handler = new SslHandler(engine);
handler.setIssueHandshake(true);
pipeline.addLast("ssl", handler);
} }
pipeline.addLast("codec", new HttpClientCodec()); pipeline.addLast("codec", new HttpClientCodec());

View File

@ -24,6 +24,7 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
public class HttpUploadServer { public class HttpUploadServer {
private final int port; private final int port;
public static boolean isSSL;
public HttpUploadServer(int port) { public HttpUploadServer(int port) {
this.port = port; this.port = port;
@ -50,6 +51,9 @@ public class HttpUploadServer {
} else { } else {
port = 8080; port = 8080;
} }
if (args.length > 1) {
isSSL = true;
}
new HttpUploadServer(port).run(); new HttpUploadServer(port).run();
} }
} }

View File

@ -17,21 +17,28 @@ package org.jboss.netty.example.http.upload;
import static org.jboss.netty.channel.Channels.*; import static org.jboss.netty.channel.Channels.*;
import javax.net.ssl.SSLEngine;
import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory; import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.example.securechat.SecureChatSslContextFactory;
import org.jboss.netty.handler.codec.http.HttpContentCompressor; import org.jboss.netty.handler.codec.http.HttpContentCompressor;
import org.jboss.netty.handler.codec.http.HttpRequestDecoder; import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
import org.jboss.netty.handler.codec.http.HttpResponseEncoder; import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
import org.jboss.netty.handler.ssl.SslHandler;
public class HttpUploadServerPipelineFactory implements ChannelPipelineFactory { public class HttpUploadServerPipelineFactory implements ChannelPipelineFactory {
public ChannelPipeline getPipeline() throws Exception { public ChannelPipeline getPipeline() throws Exception {
// Create a default pipeline implementation. // Create a default pipeline implementation.
ChannelPipeline pipeline = pipeline(); ChannelPipeline pipeline = pipeline();
// Uncomment the following line if you want HTTPS if (HttpUploadServer.isSSL) {
//SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine(); SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
//engine.setUseClientMode(false); engine.setUseClientMode(false);
//pipeline.addLast("ssl", new SslHandler(engine)); SslHandler handler = new SslHandler(engine);
handler.setIssueHandshake(true);
pipeline.addLast("ssl", handler);
}
pipeline.addLast("decoder", new HttpRequestDecoder()); pipeline.addLast("decoder", new HttpRequestDecoder());

View File

@ -628,7 +628,7 @@ public class HttpPostRequestEncoder implements ChunkedInput {
} }
request.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String request.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String
.valueOf(realSize)); .valueOf(realSize));
if (realSize > HttpPostBodyUtil.chunkSize) { if (realSize > HttpPostBodyUtil.chunkSize || isMultipart) {
isChunked = true; isChunked = true;
if (transferEncoding != null) { if (transferEncoding != null) {
request.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING); request.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING);