title: How to implement a PayPal IPN Controller in Java using Play 2.0
body: <p>I am implementing a PayPal IPN Controller (currently in Java) using Play Framework 2.0, which receives a form-encoded POST request from the PayPal server.   I am adapting a Play 1.x controller from <a href="http://blog.guillaumeleone.fr/play-and-paypal-ipn/" rel="nofollow">blog post by Guillame Leone</a> to work with Play 2.0.  Since "params" are now gone, this tasks seems a little tricky.</p>
  
  <p>There are two steps to the PayPal IPN process: </p>
  
  <p>1) Parse the request body as text, so I can submit the exact response to PayPal that they want. It must be the same string in the same order as they submit to me. This currently works:</p>
  
  <pre><code> @BodyParser.Of(BodyParser.TolerantText.class)
   public static Result validation() throws Exception {
     Logger.info("Received IPN request");
      String str = "cmd=_notify-validate&amp;" + request().body().asText();
      Logger.info("Validation string: " + str);
  </code></pre>
  
  <p>2) Send validation request to PayPal, and when they respond with "VERIFIED" response I want to decode the form-encoded request body and access it as a map. But since I have already parsed the request body as text using the annotation, the following returns null instead of a map:</p>
  
  <pre><code>Map&lt;String,String[]&gt; data = request().body().asFormUrlEncoded() //returns null
  </code></pre>
  
  <p>What is the best way to parse this request twice, once as text (ignoring the form encoded MIME type) and a second time as form-encoded data?  </p>
  
  <p>(It seems like I might want to get rid of the annotation and directly call the TolerantText and FormEncoded parsers, but I have no idea how to do that!)</p>