title: java.lang.IllegalArgumentException: java.text.ParseException: End of header
body: <p>I encounter <code>IllegalArgumentException</code> while sending a post request to the restful web-service.
  If i comment the method for post request(<code>getEmplByPostReqParam()</code>) then, code works fine for get request but with <code>getEmplByPostReqParam()</code>, all request throws <code>IllegalArgumentException</code>.</p>
  
  <p>Can you please help in identifying the problem.</p>
  
  <p>Web service code:</p>
  
  <pre><code>@Path("/employee")
  public class EmployeeInfoService {
  
      // This method is called if TEXT_PLAIN is request
      @GET
      @Path("/get/{id}")
      @Produces(MediaType.APPLICATION_ATOM_XML)
      public Employee getEmplById(@PathParam("id") String id) {
          System.out.println("sayPlainTextHello");
          EmployeeDAO dbHandler = new EmployeeDAOImpl();
          Employee fetchedEmployee = dbHandler.findEmployee(Integer.parseInt(id));
          return fetchedEmployee;
      }
  
      @GET
      @Path("/get")
      @Produces(MediaType.APPLICATION_ATOM_XML)
      public Employee getEmplByGetReqParam(@QueryParam("param1") String id) {
          System.out.println("getEmplByGetReqParam");
          EmployeeDAO dbHandler = new EmployeeDAOImpl();
          Employee fetchedEmployee = dbHandler.findEmployee(Integer.parseInt(id));
          return fetchedEmployee;
      }
  
      @POST
      @Path("/get")
      @Produces("MediaType.TEXT_PLAIN")
      public String getEmplByPostReqParam(@FormParam("param1") String id) {
          System.out.println("getEmplByPostReqParam");
          EmployeeDAO dbHandler = new EmployeeDAOImpl();
          Employee fetchedEmployee = dbHandler.findEmployee(Integer.parseInt(id));
          return fetchedEmployee.toString();
      }
  
  }
  </code></pre>
  
  <p>I used two client to test the service:
  1. Google chrome's Advance Rest client</p>
  
  <pre><code>url - http://myhost:14443/de.vogella.jersey.first/rest/employee/get
  payload - [param1: 1]
  method type - [post]
  </code></pre>
  
  <ol>
  <li><p>core java code</p>
  
  <pre><code>   String url = "http://myhost:14443/de.vogella.jersey.first/rest/employee/get";
     String charset = "UTF-8";
     String param1 = "1";
  
      String query = String.format("param1=%s",
              URLEncoder.encode(param1, charset));
  
      URL service = new URL(url);
      URLConnection connection = service.openConnection();
      connection.setDoOutput(true); // Triggers POST.
      connection.setRequestProperty("Accept-Charset", charset);
      connection.setRequestProperty("Content-Type",
              "application/x-www-form-urlencoded;charset=" + charset);
      OutputStream output = connection.getOutputStream();
      try {
          output.write(query.getBytes(charset));
      } catch (Exception e) {
          // TODO: handle exception
      }
  </code></pre></li>
  </ol>
  
  <p>Stacktrace:</p>
  
  <pre><code>&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;root cause&lt;/b&gt; &lt;pre&gt;java.lang.IllegalArgumentException: java.text.ParseException: End of header
      com.sun.jersey.core.header.MediaTypes.createQualitySourceMediaTypes(MediaTypes.java:289)
      com.sun.jersey.core.header.MediaTypes.createQualitySourceMediaTypes(MediaTypes.java:274)
      com.sun.jersey.server.impl.modelapi.annotation.IntrospectionModeller.addProduces(IntrospectionModeller.java:171)
      com.sun.jersey.server.impl.modelapi.annotation.IntrospectionModeller.workOutSubResourceMethodsList(IntrospectionModeller.java:342)
      com.sun.jersey.server.impl.modelapi.annotation.IntrospectionModeller.createResource(IntrospectionModeller.java:126)
      com.sun.jersey.server.impl.application.WebApplicationImpl.getAbstractResource(WebApplicationImpl.java:744)
      com.sun.jersey.server.impl.application.WebApplicationImpl.createAbstractResourceModelStructures(WebApplicationImpl.java:1564)
      com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1328)
      com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:168)
      com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:774)
      com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:770)
      com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
      com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:770)
      com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:765)
      com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:489)
      com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:319)
      com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
      com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
      com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374)
      com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557)
      javax.servlet.GenericServlet.init(GenericServlet.java:160)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
      java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      java.lang.Thread.run(Unknown Source)
  &lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;root cause&lt;/b&gt; &lt;pre&gt;java.text.ParseException: End of header
      com.sun.jersey.core.header.reader.HttpHeaderReaderImpl.getNextCharacter(HttpHeaderReaderImpl.java:168)
      com.sun.jersey.core.header.reader.HttpHeaderReaderImpl.next(HttpHeaderReaderImpl.java:129)
      com.sun.jersey.core.header.reader.HttpHeaderListAdapter.next(HttpHeaderListAdapter.java:111)
      com.sun.jersey.core.header.reader.HttpHeaderListAdapter.next(HttpHeaderListAdapter.java:98)
      com.sun.jersey.core.header.reader.HttpHeaderReader.nextSeparator(HttpHeaderReader.java:116)
      com.sun.jersey.core.header.QualitySourceMediaType.valueOf(QualitySourceMediaType.java:85)
      com.sun.jersey.core.header.reader.HttpHeaderReader$5.create(HttpHeaderReader.java:360)
      com.sun.jersey.core.header.reader.HttpHeaderReader$5.create(HttpHeaderReader.java:358)
      com.sun.jersey.core.header.reader.HttpHeaderReader.readList(HttpHeaderReader.java:481)
      com.sun.jersey.core.header.reader.HttpHeaderReader.readList(HttpHeaderReader.java:473)
      com.sun.jersey.core.header.reader.HttpHeaderReader.readAcceptableList(HttpHeaderReader.java:461)
      com.sun.jersey.core.header.reader.HttpHeaderReader.readQualitySourceMediaType(HttpHeaderReader.java:365)
      com.sun.jersey.core.header.reader.HttpHeaderReader.readQualitySourceMediaType(HttpHeaderReader.java:373)
      com.sun.jersey.core.header.MediaTypes.createQualitySourceMediaTypes(MediaTypes.java:287)
      com.sun.jersey.core.header.MediaTypes.createQualitySourceMediaTypes(MediaTypes.java:274)
      com.sun.jersey.server.impl.modelapi.annotation.IntrospectionModeller.addProduces(IntrospectionModeller.java:171)
      com.sun.jersey.server.impl.modelapi.annotation.IntrospectionModeller.workOutSubResourceMethodsList(IntrospectionModeller.java:342)
      com.sun.jersey.server.impl.modelapi.annotation.IntrospectionModeller.createResource(IntrospectionModeller.java:126)
      com.sun.jersey.server.impl.application.WebApplicationImpl.getAbstractResource(WebApplicationImpl.java:744)
      com.sun.jersey.server.impl.application.WebApplicationImpl.createAbstractResourceModelStructures(WebApplicationImpl.java:1564)
      com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1328)
      com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:168)
      com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:774)
      com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:770)
      com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
      com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:770)
      com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:765)
      com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:489)
      com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:319)
      com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
      com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
      com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374)
      com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557)
      javax.servlet.GenericServlet.init(GenericServlet.java:160)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
      java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      java.lang.Thread.run(Unknown Source)
  </code></pre>