Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-13886

camel-servlet + camel-http4 with null body causes "Stream closed" IOException

    XMLWordPrintableJSON

Details

    • Unknown

    Description

      A Rest DSL route like the following causes java.io.IOException: Stream closed when invoked at http://localhost:8000/test/proxy:

              rest("/test")
                      .get("/proxy")
                      .to("direct:callInternalRestService");
      
              from("direct:callInternalRestService")
                      .setHeader(Exchange.HTTP_METHOD, constant("DELETE"))
                      //.setBody(constant("")) // workaround for null body and http4 component
                      .to("http4://localhost:9000/test?bridgeEndpoint=true")
                      .log("${body}");
      

      The error stacktrace:

      Caused by: java.io.IOException: Stream closed
      	at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:372)
      	at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:156)
      	at org.apache.camel.util.IOHelper.copy(IOHelper.java:202)
      	at org.apache.camel.util.IOHelper.copy(IOHelper.java:174)
      	at org.apache.camel.util.IOHelper.copyAndCloseInput(IOHelper.java:234)
      	at org.apache.camel.util.IOHelper.copyAndCloseInput(IOHelper.java:230)
      	at org.apache.camel.http.common.HttpHelper.readResponseBodyFromInputStream(HttpHelper.java:245)
      	at org.apache.camel.http.common.HttpHelper.readRequestBodyFromServletRequest(HttpHelper.java:196)
      	at org.apache.camel.http.common.DefaultHttpBinding.parseBody(DefaultHttpBinding.java:577)
      	at org.apache.camel.http.common.HttpMessage.createBody(HttpMessage.java:78)
      	... 54 common frames omitted
      

      This seems to happen only when Tomcat is used as the container with Spring Boot. Undertow doesn't cause such an issue.

      The real root cause is that when an exchange has an HttpMessage with null body as its out message, then the next time Exchange.getMessage() is invoked the HttpMessage is tricked by the null body and tries to create body again with the already closed request input stream.

      Attachments

        Issue Links

          Activity

            People

              tadayosi Tadayoshi Sato
              tadayosi Tadayoshi Sato
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m