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

View File

@ -44,7 +44,9 @@ public class HttpUploadClientPipelineFactory implements ChannelPipelineFactory {
SecureChatSslContextFactory.getClientContext().createSSLEngine();
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());

View File

@ -24,6 +24,7 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
public class HttpUploadServer {
private final int port;
public static boolean isSSL;
public HttpUploadServer(int port) {
this.port = port;
@ -50,6 +51,9 @@ public class HttpUploadServer {
} else {
port = 8080;
}
if (args.length > 1) {
isSSL = true;
}
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 javax.net.ssl.SSLEngine;
import org.jboss.netty.channel.ChannelPipeline;
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.HttpRequestDecoder;
import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
import org.jboss.netty.handler.ssl.SslHandler;
public class HttpUploadServerPipelineFactory implements ChannelPipelineFactory {
public ChannelPipeline getPipeline() throws Exception {
// Create a default pipeline implementation.
ChannelPipeline pipeline = pipeline();
// Uncomment the following line if you want HTTPS
//SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
//engine.setUseClientMode(false);
//pipeline.addLast("ssl", new SslHandler(engine));
if (HttpUploadServer.isSSL) {
SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
engine.setUseClientMode(false);
SslHandler handler = new SslHandler(engine);
handler.setIssueHandshake(true);
pipeline.addLast("ssl", handler);
}
pipeline.addLast("decoder", new HttpRequestDecoder());

View File

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