title: Apache HTTP Request ends in exception on RESTful webservice
body: <p>I need to test a RESTful webservice* (with spring) with JUnit. I tested the Webservice using IntelliJs build in Testing Tool and it works well. So now I'm using ApacheHttpClient to perform a POST request on that webservice. Im starting the RESTful webservice and then execute this code</p>
  
  <pre><code>CloseableHttpClient httpclient = HttpClients.createDefault();
  URI uri = new URIBuilder()
               .setScheme("http")
               .setHost("localhost")
               .setPort(8080)
               .setPath("/register")
               .build();
  HttpPost post = new HttpPost(uri);
  List&lt;NameValuePair&gt; nvps = new ArrayList&lt;&gt;();
  nvps.add(new BasicNameValuePair("name", "test"));
  nvps.add(new BasicNameValuePair("email", "test"));
  nvps.add(new BasicNameValuePair("password", "test"));
  post.setEntity(new UrlEncodedFormEntity(nvps));
  CloseableHttpResponse response = httpclient.execute(post);
  response.close();
  </code></pre>
  
  <p>But this ends in an exception on the webservice saying:</p>
  
  <blockquote>
    <p>A servlet request to the URI <a href="http://localhost:8080/register" rel="nofollow">http://localhost:8080/register</a> contains form parameters in the request body but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using @FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected. UT005023: Exception handling request to /error</p>
  </blockquote>
  
  <p>Full stacktrace: <a href="http://pastebin.com/96aJtaS5" rel="nofollow">http://pastebin.com/96aJtaS5</a></p>
  
  <p>*Full source code is available at: <a href="https://github.com/pkalauner-tgm/dezsys09-java-webservices" rel="nofollow">https://github.com/pkalauner-tgm/dezsys09-java-webservices</a>
  Thx for your help</p>