Skip to content

Commit

Permalink
Problems with up.loaded files with Netty : http://github.com/pepite/P…
Browse files Browse the repository at this point in the history
  • Loading branch information
pepite committed Jun 27, 2010
1 parent 8a68830 commit a61415e
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions samples-and-tests/test/app/controllers/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public static void index() {

public static void upload(File file) throws Exception {
Logger.info("File is " + file.getAbsolutePath() + "]");
FileUtils.copyFile(file, new File(Play.getFile("data/"), file.getName()));
FileUtils.copyFile(file, new File(Play.getFile("/data/"), file.getName()));
Logger.info("File size [" + file.length() + "]");
}

}
}
2 changes: 1 addition & 1 deletion samples-and-tests/test/app/views/Application/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

<input type="submit">

</form>
</form>
2 changes: 1 addition & 1 deletion samples-and-tests/test/conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ date.format=dd-MM-yyyy
# ~~~~~
# Specify log level for your application.
# If you want a very customized log, create a log4j.properties file in the conf directory
# application.log=INFO
application.log=TRACE
#
# More logging configuration
# application.log.path=/log4j.properties
Expand Down
6 changes: 1 addition & 5 deletions src/play/modules/netty/HttpServerPipelineFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.handler.codec.http.HttpChunkAggregator;
import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
import org.jboss.netty.handler.stream.ChunkedWriteHandler;
Expand All @@ -38,13 +37,11 @@ public class HttpServerPipelineFactory implements ChannelPipelineFactory {
public ChannelPipeline getPipeline() throws Exception {

Integer max = Integer.valueOf(Play.configuration.getProperty("play.netty.maxContentLength", "-1"));
Integer threshold = Integer.valueOf(Play.configuration.getProperty("play.netty.threshold", "8192"));


ChannelPipeline pipeline = pipeline();

pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("aggregator", new StreamChunkAggregator(max));
//pipeline.addLast("aggregator", new HttpChunkAggregator(max));
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());

Expand All @@ -54,4 +51,3 @@ public ChannelPipeline getPipeline() throws Exception {
return pipeline;
}
}

2 changes: 1 addition & 1 deletion src/play/modules/netty/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Server() {

// Setup the http server for netty
ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));

bootstrap.setPipelineFactory(new HttpServerPipelineFactory());
bootstrap.bind(new InetSocketAddress(address, httpPort));
Expand Down
5 changes: 3 additions & 2 deletions src/play/modules/netty/StreamChunkAggregator.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
return;
}


HttpMessage currentMessage = this.currentMessage;
File localFile = this.file;
if (currentMessage == null) {

HttpMessage m = (HttpMessage) msg;
if (m.isChunked()) {
final String localName = UUID.randomUUID().toString();
Expand All @@ -79,6 +79,7 @@ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
if (encodings.isEmpty()) {
m.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING);
}

this.currentMessage = m;
this.file = new File(Play.tmpDir, localName);
this.out = new FileOutputStream(file, true);
Expand All @@ -104,7 +105,7 @@ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
HttpHeaders.Names.CONTENT_LENGTH,
String.valueOf(localFile.length()));

currentMessage.setContent(new play.server.FileChannelBuffer(localFile));
currentMessage.setContent(new FileChannelBuffer(localFile));
this.out = null;
this.currentMessage = null;
this.file = null;
Expand Down

0 comments on commit a61415e

Please sign in to comment.