Skip to content

Commit

Permalink
Merge branch 'master' of github.com:vert-x/mod-formupload
Browse files Browse the repository at this point in the history
  • Loading branch information
purplefox committed Mar 14, 2013
2 parents e046d02 + 1bc1874 commit c9f69b0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main/java/org/vertx/mods/formupload/MultipartRequest.java
@@ -1,7 +1,9 @@
package org.vertx.mods.formupload;

import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.http.DefaultHttpContent;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.handler.codec.http.multipart.*;
import org.vertx.java.core.Handler;
import org.vertx.java.core.Vertx;
Expand All @@ -19,6 +21,7 @@

/**
* @author <a href="http://tfox.org">Tim Fox</a>
* @author <a href="mailto:nmaurer@redhat.com">Norman Maurer</a>
*/
public class MultipartRequest {

Expand All @@ -38,6 +41,26 @@ public MultipartRequest(Vertx vertx, HttpServerRequest req) {
nettyReq = ((DefaultHttpServerRequest)req).getNettyRequest();
try {
decoder = new HttpPostRequestDecoder(new DataFactory(), nettyReq);
req.dataHandler(new Handler<Buffer>() {
@Override
public void handle(Buffer event) {
try {
decoder.offer(new DefaultHttpContent(event.getByteBuf()));
} catch (HttpPostRequestDecoder.ErrorDataDecoderException e) {
throw convertException(e);
}
}
});
req.endHandler(new Handler<Void>() {
@Override
public void handle(Void event) {
try {
decoder.offer(LastHttpContent.EMPTY_LAST_CONTENT);
} catch (HttpPostRequestDecoder.ErrorDataDecoderException e) {
throw convertException(e);
}
}
});
} catch (Exception e) {
throw convertException(e);
}
Expand Down

0 comments on commit c9f69b0

Please sign in to comment.