title: How to get POST form data using VERTX handlers?
body: <p>I am able to get the form data using the buffer handler, but it is a void function and I cannot return the form data values. Have about 4-7 forms total, I don't want to end up writing the same handler over and over because the default function is void.</p>
  
  <p>html:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;    
  &lt;head&gt;&lt;title&gt;Login Page&lt;/title&gt;&lt;/head&gt;
  &lt;body&gt;
      &lt;a href="/activateUserPage"&gt;activate user&lt;/a&gt;
      &lt;br/&gt;
      &lt;a href="/login"&gt;log in&lt;/a&gt;
      &lt;br/&gt;
  
      &lt;form id='login' action='/login' method='post'&gt;
          &lt;fieldset &gt;
              &lt;legend&gt;Login&lt;/legend&gt;
              &lt;input type='hidden' name='submitted' id='submitted' value='1'/&gt;
  
              &lt;label for='username' &gt;UserName: &lt;/label&gt;
              &lt;input type='text' name='username' id='username'  maxlength="50"/&gt;
  
              &lt;label for='password' &gt;Password: &lt;/label&gt;
              &lt;input type='password' name='password' id='password' maxlength="50"/&gt;
  
              &lt;input type='submit' name='Submit' value='Submit' /&gt;
          &lt;/fieldset&gt;
      &lt;/form&gt;         
  &lt;/body&gt;    
  &lt;/html&gt;
  </code></pre>
  
  <p>java:</p>
  
  <pre><code>import org.jboss.netty.handler.codec.http.QueryStringDecoder;
  import org.vertx.java.core.Handler;
  import org.vertx.java.core.Vertx;
  import org.vertx.java.core.buffer.Buffer;
  import org.vertx.java.core.http.HttpServer;
  import org.vertx.java.core.http.HttpServerRequest;
  import org.vertx.java.core.http.RouteMatcher;
  import org.vertx.java.deploy.Verticle;
  
  import java.util.Collection;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  
  /**
   * Created by IntelliJ IDEA.
   * User: yao
   * Date: 1/17/13
   * Time: 2:22 PM
   */
  
  public class Main extends Verticle
  {
      @Override
      public void start() throws Exception
      {
          System.out.println("starting the vertx stuff");
          final String host = "localhost";
          final String port = "8181";
  
          Vertx vertx = Vertx.newVertx();
          HttpServer httpServer = vertx.createHttpServer();
  
          ...
  
          httpServer.requestHandler(new Handler&lt;HttpServerRequest&gt;()
          {
              public void handle(HttpServerRequest req)
              {
                  String path = req.path;
  
                  /* start mapping of page urls*/
                  // redirect user to the login page
                  if (path.equals("/"))
                  {
                      req.response.sendFile(dir + "html/loginPage.html");
                  }
                  ...
  
                  /* end mapping of page urls*/
  
                  /* start mapping of form urls */
                  // login
                  else if (path.equals(login))
                  {
                      mainLogin();
                      getFormData(req);
                  }
                  ...
  
                  /* end mapping of form urls */
  
                  /* all other pages */
                  else
                  {
                      req.response.end("404 - page no exist");
                  }
              }
          });
  
          System.out.println("vertx listening to: " + host + " " + port);
          httpServer.listen(Integer.valueOf(port), host);
      }
  
      ...
  
      private void getFormData(final HttpServerRequest req)
      {
          req.bodyHandler(new Handler&lt;Buffer&gt;()
          {
              @Override
              public void handle(Buffer buff)
              {
                  String contentType = req.headers().get("Content-Type");
                  if ("application/x-www-form-urlencoded".equals(contentType))
                  {
                      QueryStringDecoder qsd = new QueryStringDecoder(buff.toString(), false);
                      Map&lt;String, List&lt;String&gt;&gt; params = qsd.getParameters();
                      System.out.println(params);
                  }
              }
          });
      }
  }
  </code></pre>