Skip to content

Commit

Permalink
reenabled error message
Browse files Browse the repository at this point in the history
  • Loading branch information
pepite committed Mar 6, 2010
1 parent ee3784d commit 82a8c8c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 37 deletions.
Binary file modified lib/netty-3.1.5.GA.jar
Binary file not shown.
5 changes: 0 additions & 5 deletions src/play/modules/netty/HttpServerPipelineFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,8 @@ public class HttpServerPipelineFactory implements ChannelPipelineFactory {
public ChannelPipeline getPipeline() throws Exception {

Integer max = Integer.valueOf(Play.configuration.getProperty("play.module.netty.maxContentLength", "-1"));
// if (max == -1) {
// max = Integer.MAX_VALUE;
// }

Integer threshold = Integer.valueOf(Play.configuration.getProperty("play.module.netty.threshold", "8192"));


ChannelPipeline pipeline = pipeline();

pipeline.addLast("decoder", new HttpRequestDecoder());
Expand Down
48 changes: 16 additions & 32 deletions src/play/modules/netty/PlayHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import java.io.*;
import java.net.URI;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.ParseException;
import java.util.*;
Expand Down Expand Up @@ -153,7 +154,7 @@ public void run() {
public void execute() throws Exception {
Logger.trace("execute: begin");
ActionInvoker.invoke(request, response);
//saveExceededSizeError(nettyRequest, response);
saveExceededSizeError(nettyRequest, response);
copyResponse(ctx, request, response, nettyRequest);
Logger.trace("execute: end");
}
Expand All @@ -180,7 +181,7 @@ void saveExceededSizeError(HttpRequest nettyRequest, Response response) {
throw new UnexpectedException("Flash serialization problem", e);
}
}
} // Thread
}

protected static void addToResponse(Response response, HttpResponse nettyResponse) {
Map<String, Http.Header> headers = response.headers;
Expand Down Expand Up @@ -298,21 +299,21 @@ public static void copyResponse(ChannelHandlerContext ctx, Request request, Resp
Logger.trace("copyResponse: end");
}

private static String escapeIllegalCharacters(String uri) throws Exception {
// Encode uri according to RFC 2396
return URLEncoder.encode(uri, "US-ASCII").replaceAll("%2F", "/").replaceAll("%3F", "?").replaceAll("%3D", "=").replaceAll("%26", "&");
}

public static Request parseRequest(ChannelHandlerContext ctx, HttpRequest nettyRequest) throws Exception {
Logger.trace("parseRequest: begin");
final URI uri = new URI(escapeIllegalCharacters(nettyRequest.getUri()));
int index = nettyRequest.getUri().indexOf("?");
String querystring = "";
String path = URLDecoder.decode(nettyRequest.getUri(), "UTF-8");
if (index != -1) {
path = URLDecoder.decode(nettyRequest.getUri().substring(0, index), "UTF-8");
querystring = nettyRequest.getUri().substring(index + 1);
}

final Request request = new Request();
request.remoteAddress = ctx.getChannel().getRemoteAddress().toString();
request.method = nettyRequest.getMethod().getName();
request.path = uri.getPath();
request.querystring = uri.getQuery() == null ? "" : uri.getQuery();

request.path = path;
request.querystring = querystring;
final String contentType = nettyRequest.getHeader(CONTENT_TYPE);
if (contentType != null) {
request.contentType = contentType.split(";")[0].trim().toLowerCase();
Expand All @@ -335,7 +336,7 @@ public static Request parseRequest(ChannelHandlerContext ctx, HttpRequest nettyR
request.body = new ChannelBufferInputStream(b);
}

request.url = uri.toASCIIString();
request.url = nettyRequest.getUri();
request.host = nettyRequest.getHeader(HOST);

if (request.host.contains(":")) {
Expand Down Expand Up @@ -406,7 +407,7 @@ protected static void addToRequest(HttpRequest nettyRequest, Request request) {
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
throws Exception {
e.getCause().printStackTrace();
//e.getCause().printStackTrace();
e.getChannel().close();
}

Expand Down Expand Up @@ -591,25 +592,8 @@ public static void serveStatic(RenderStatic renderStatic, ChannelHandlerContext
ch.write(nettyResponse);

// Write the content.
ChannelFuture writeFuture;

writeFuture = ch.write(new ChunkedFile(raf, 0, fileLength, 8192));
//
// // No encryption - use zero-copy.
// final FileRegion region =
// new DefaultFileRegion(raf.getChannel(), 0, fileLength);
// writeFuture = ch.write(region);
// writeFuture.addListener(new ChannelFutureProgressListener() {
// public void operationComplete(ChannelFuture future) {
// region.releaseExternalResources();
// }
//
// public void operationProgressed(
// ChannelFuture future, long amount, long current, long total) {
// System.out.printf("%s: %d / %d (+%d)%n", localFile.getPath(), current, total, amount);
//
// }
// });
ChannelFuture writeFuture = ch.write(new ChunkedFile(raf, 0, fileLength, 8192));

if (!isKeepAlive(nettyRequest)) {
// Close the connection when the whole content is written out.
writeFuture.addListener(ChannelFutureListener.CLOSE);
Expand Down

0 comments on commit 82a8c8c

Please sign in to comment.