title: Generic all purpose implementation for HttpPost, HttpGet, HttpPut, etc
body: <p>I created a method that loops around and gets a hold of an incoming request's headers and then transfers them to a HttpPost, HttpGet, etc object depending on what the request method was:</p>
  
  <pre><code>protected HttpPost savePostData(HttpPost httpPost, HttpServletRequest servletRequest) throws UnsupportedEncodingException {
      Enumeration&lt;String&gt; headerNames = servletRequest.getHeaderNames();
      while (headerNames.hasMoreElements()) {
  
      String headerName = headerNames.nextElement();
      Enumeration&lt;String&gt; headers = servletRequest.getHeaders(headerName);
      while (headers.hasMoreElements()) {
          String headerValue = headers.nextElement();
          httpPost.addHeader(headerName, headerValue);
      }
  }
  StringEntity requestBody = new StringEntity(servletRequest.getParameter(parameterBody));
  httpPost.setEntity(requestBody);
  return httpPost;
  </code></pre>
  
  <p>}</p>
  
  <p>AND</p>
  
  <pre><code>protected HttpPut savePutData(HttpPut httpPut, HttpServletRequest servletRequest) throws UnsupportedEncodingException {
      Enumeration&lt;String&gt; headerNames = servletRequest.getHeaderNames();
      while (headerNames.hasMoreElements()) {
  
      String headerName = headerNames.nextElement();
      Enumeration&lt;String&gt; headers = servletRequest.getHeaders(headerName);
      while (headers.hasMoreElements()) {
          String headerValue = headers.nextElement();
          httpPut.addHeader(headerName, headerValue);
      }
  }
  StringEntity requestBody = new StringEntity(servletRequest.getParameter(parameterBody));
  httpPut.setEntity(requestBody);
  return httpPut;
  </code></pre>
  
  <p>}</p>
  
  <p>But I do not want to repeat code, and I do not know how to make a token that could serve as a universal argument.</p>