title: In XPages how do you get the POST body from a REST call?
body: <p>I have an XPages that has a restService control on it.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;xe:restService
      id="restService1"
      pathInfo="service"
      state="false"&gt;
      &lt;xe:this.service&gt;
          &lt;xe:customRestService
              contentType="application/json"
              serviceBean="com.domain.rest.Employee"&gt;
          &lt;/xe:customRestService&gt;
      &lt;/xe:this.service&gt;
  &lt;/xe:restService&gt;
  </code></pre>
  
  <p>I want to pass in JSON data from an outside application.  For this test I'm just using the postman plugin for Chrome.</p>
  
  <p>I have some shell code that gets the REST verb and sends it to a matching method.  The stub for the methods looks like this : </p>
  
  <pre class="lang-java prettyprint-override"><code>public void doPost( HttpServletRequest req, HttpServletResponse res, PrintWriter out ) {
          // Do something here
          this.doUnHandled(req, res, out);
      }
  </code></pre>
  
  <p>What I'm struggling with is how do I get read in the body of the Post so I can turn that incoming JSON into a Map or something else that I can work with in my Java code to then interact with Domino Documents.  I've found a bunch of examples on the web, but they all seem different and I've not been able to put it together. </p>
  
  <p>Ideally I'd like to use something built in I guess with com.ibm.commons.util.io.json for now.  I know GSON and other things are popular but I just want to get something working first.</p>
  
  <p>My latest attempt was with this example : </p>
  
  <pre class="lang-java prettyprint-override"><code>public void doPost( HttpServletRequest req, HttpServletResponse res, PrintWriter out ) throws IOException, JsonException {
  
          System.out.println("POSTING DATA");
  
          Map&lt;String, Object&gt; result = (Map&lt;String, Object&gt;) 
  JsonParser.fromJson(JsonJavaFactory.instance, req.getReader());
  
          Map&lt;String, Object&gt; foo = new HashMap&lt;String, Object&gt;();
          foo.put("firstName", result.get("firstName"));
          System.out.println(foo.get("firstName"));
  
          this.doUnHandled(req, res, out);
      }
  </code></pre>
  
  <p>I had high hopes for that but I get an error that I can't use the buffered reader - req.getReader() - while ServletInputStream is in use.</p>
  
  <p>My understanding is that the data I was is inside the req.getInputStream() and that might need to be read line by line and I've tried that with problems as well.</p>
  
  <p>Any help or advice would be appreciated.  Thanks!!</p>