title: Java vertx 3.2 file upload using bodyhandler
body: <p>java.lang.IllegalStateException: Request has already been read exception in vertx3.0.  I tried in many ways. The simple formupload is working fine. But when i use body handler, it is throwing below exception. Can anybody help ?</p>
  
  <pre><code>import io.vertx.core.AbstractVerticle;
  import io.vertx.core.http.HttpHeaders;
  
  import io.vertx.ext.web.Router;
  import io.vertx.ext.web.handler.BodyHandler;
  
  /*
   * @author Gogs
   */
  
  public class TestServer extends AbstractVerticle {
  
    // Convenience method so you can run it in your IDE
    public static void main(String[] args) {
      Runner.runExample(TestServer.class);
    }
  
    @Override
    public void start() throws Exception {
  
      Router router = Router.router(vertx);
  
      // Enable multipart form data parsing
      router.route().handler(BodyHandler.create());
  
      router.route("/").handler(routingContext -&gt; {
        routingContext.response().putHeader("content-type", "text/html").end(
            "&lt;form action=\"/form\" ENCTYPE=\"multipart/form-data\" method=\"POST\" name=\"wibble\"&gt;\n" +
             "choose a file to upload:&lt;input type=\"file\" name=\"myfile\"/&gt;&lt;br&gt;"+
            " &lt;input type=\"submit\"/&gt;"+
            "&lt;/form&gt;"
        );
      });
  
      // handle the form
      router.post("/form").handler(ctx -&gt; {
  
        ctx.request().setExpectMultipart(true);
        ctx.request().uploadHandler(upload -&gt; {
            upload.exceptionHandler(cause -&gt; {
              ctx.response().setChunked(true).end("Upload failed");
            });
  
            upload.endHandler(v -&gt; {
              ctx.response().setChunked(true).end("Successfully uploaded to " + upload.filename());
            });
            // FIXME - Potential security exploit! In a real system you must check this filename
            // to make sure you're not saving to a place where you don't want!
            // Or better still, just use Vert.x-Web which controls the upload area.
            upload.streamToFileSystem(upload.filename());
          });
  
  
      });
  
      vertx.createHttpServer().requestHandler(router::accept).listen(8090);
    }
  }
  
  Am seeing the below exception.
  
  
  Feb 02, 2016 6:48:54 PM io.vertx.ext.web.impl.RoutingContextImplBase
  
  SEVERE: Unexpected exception in route
  
  java.lang.IllegalStateException: Request has already been read
  
      at io.vertx.core.http.impl.HttpServerRequestImpl.checkEnded(HttpServerRequestImpl.java:426)
      at io.vertx.core.http.impl.HttpServerRequestImpl.setExpectMultipart(HttpServerRequestImpl.java:322)
      at io.vertx.ext.web.impl.HttpServerRequestWrapper.setExpectMultipart(HttpServerRequestWrapper.java:166)
      at com.vertx.http.upload.TestServer.lambda$1(TestServer.java:43)
      at io.vertx.ext.web.impl.RouteImpl.handleContext(RouteImpl.java:221)
      at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:78)
      at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:93)
      at io.vertx.ext.web.handler.impl.BodyHandlerImpl$BHandler.doEnd(BodyHandlerImpl.java:155)
      at io.vertx.ext.web.handler.impl.BodyHandlerImpl$BHandler.uploadEnded(BodyHandlerImpl.java:135)
      at io.vertx.ext.web.handler.impl.BodyHandlerImpl$BHandler.lambda$null$35(BodyHandlerImpl.java:109)
      at io.vertx.core.http.impl.HttpServerFileUploadImpl.notifyEndHandler(HttpServerFileUploadImpl.java:213)
      at io.vertx.core.http.impl.HttpServerFileUploadImpl.lambda$handleComplete$165(HttpServerFileUploadImpl.java:206)
      at io.vertx.core.file.impl.AsyncFileImpl.lambda$doClose$226(AsyncFileImpl.java:470)
      at io.vertx.core.impl.ContextImpl.lambda$wrapTask$16(ContextImpl.java:335)
      at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:358)
      at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)
      at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>