users@jersey.java.net

Re: [Jersey] read time-out when processing form post

From: mmogley <mmogley_at_wirefreethought.com>
Date: Tue, 3 Mar 2009 13:00:31 -0800 (PST)

I'm posting this through a proxy servlet I wrote (in order to get around
cross-domain security issues). I think you're right that it must be
something on the server side, or in other words in my code. The actual
method that sends the request is below.

  private void executeHttpMethod(HttpMethodBase httpMethod,
HttpServletRequest request, HttpServletResponse response) throws IOException
  {
    try
    {
      httpMethod.setDoAuthentication(false);

      try
      {
        for (Enumeration<String> e = request.getHeaderNames();
e.hasMoreElements();)
        {
          String headerName = e.nextElement();
          String headerValue = request.getHeader(headerName);

          httpMethod.setRequestHeader(headerName, headerValue);
        }

        int returnCode = m_httpClient.executeMethod(httpMethod);

        for (Header header : httpMethod.getResponseHeaders())
        {
          String headerName = header.getName();
          String headerValue = header.getValue();
          response.setHeader(headerName, headerValue);
        }

        InputStream inputStream = httpMethod.getResponseBodyAsStream();
        OutputStream outputStream = response.getOutputStream();

        if (inputStream != null)
        {
          int read = IOUtils.copy(inputStream, outputStream);

          outputStream.flush();

          response.setContentLength(read);
        }
      }
      finally
      {
        httpMethod.releaseConnection();
      }
    }
    catch (IOException e)
    {
      String msg = e.getMessage();

      if (msg == null)
      {
        msg = "";
      }

      if (e.getCause() != null)
      {
        msg += " Caused by: " + e.getCause().getMessage();
      }

      LOG.warn(msg);
    }
    catch (Exception e)
    {
      LOG.error(e.getMessage(), e);
      response.sendError(500, "Could not proxy content: " + e.getMessage());
    }
  }

I am flushing the response. Is there anything else I'm missing?

Michael


Craig McClanahan wrote:
>
> Michael Mogley wrote:
>> I am trying to process a simple post request. Whenever I invoke the
>> post, I get a 'read timed out' error from Jersey.
> What kind of client are you sending the request with? Since the timeout
> occurs on the server side, that implies something like maybe the client
> is not flushing its output stream to actually complete sending of the
> request ... but there's no way to know for sure without more information.
>
> Craig
>> I've browsed the mailing list for similar issues. One appeared
>> related, but in my case, Tomcat has no valves enabled. My rest method
>> is:
>>
>> @Consumes("application/x-www-form-urlencoded")
>> @POST @Path("/storeHoursProfile/add")
>> @Produces("text/html")
>> public String addProfile(@FormParam("groupId") Long groupId,
>> @FormParam("fromDate") String fromDateString, @FormParam("toDate")
>> String toDateString, @FormParam("fromTime") String fromTimeString,
>> @FormParam("toTime") String toTimeString)
>> {
>> String response = PlainTextResponseCode.OK;
>>
>> ....
>>
>> return response;
>> }
>>
>> The Jersey stack-trace:
>>
>> java.net.SocketTimeoutException: Read timed out
>> at java.net.SocketInputStream.socketRead0(Native Method)
>> at java.net.SocketInputStream.read(SocketInputStream.java:129)
>> at
>> org.apache.coyote.http11.InternalInputBuffer.fill(InternalInputBuffer.java:746)
>> at
>> org.apache.coyote.http11.InternalInputBuffer$InputStreamInputBuffer.doRead(InternalInputBuffer.java:776)
>> at
>> org.apache.coyote.http11.filters.IdentityInputFilter.doRead(IdentityInputFilter.java:116)
>> at
>> org.apache.coyote.http11.InternalInputBuffer.doRead(InternalInputBuffer.java:705)
>> at org.apache.coyote.Request.doRead(Request.java:428)
>> at
>> org.apache.catalina.connector.InputBuffer.realReadBytes(InputBuffer.java:304)
>> at org.apache.tomcat.util.buf.ByteChunk.substract(ByteChunk.java:405)
>> at
>> org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:327)
>> at
>> org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:193)
>> at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
>> at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
>> at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
>> at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
>> at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
>> at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
>> at java.io.InputStreamReader.read(InputStreamReader.java:167)
>> at java.io.Reader.read(Reader.java:123)
>> at
>> com.sun.jersey.core.provider.AbstractMessageReaderWriterProvider.readFromAsString(AbstractMessageReaderWriterProvider.java:89)
>> at
>> com.sun.jersey.core.impl.provider.entity.FormProvider.readFrom(FormProvider.java:76)
>> at
>> com.sun.jersey.core.impl.provider.entity.FormProvider.readFrom(FormProvider.java:63)
>> at
>> com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:391)
>> at
>> com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:400)
>> at
>> com.sun.jersey.server.impl.model.method.dispatch.FormDispatchProvider.processForm(FormDispatchProvider.java:76)
>> at
>> com.sun.jersey.server.impl.model.method.dispatch.FormDispatchProvider$FormParamInInvoker.getParams(FormDispatchProvider.java:91)
>> at
>> com.sun.jersey.server.impl.model.method.dispatch.FormDispatchProvider$TypeOutInvoker._dispatch(FormDispatchProvider.java:132)
>> at
>> com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:67)
>>
>> Is there something I'm not understanding here? I should not that GET
>> requests are mapped to corresponding REST methods without a hitch.
>>
>> I'm on Jersey 1.0.2 / Tomcat 6.0.18.
>>
>> Thanks for any help.
>>
>> Michael
>
>
>

-- 
View this message in context: http://n2.nabble.com/read-time-out-when-processing-form-post-tp2414051p2417882.html
Sent from the Jersey mailing list archive at Nabble.com.