Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Not A Bug
-
2.21.0
-
None
-
None
-
Unknown
Description
If i just build a simple Route like this to proxy a incoming Get request to external host:
@Override public void configure() throws Exception { from(format("servlet://%s?httpMethodRestrict=GET&servletName=%s", RETRIEVE_PATH, servletName)) .process((exchange) -> { exchange.getOut().setHeader(Exchange.HTTP_URI, "https://some.external.system/"); }).to("https4:something"); }
The following exception is thrown:
org.apache.camel.RuntimeCamelException: java.io.IOException: Stream closed at org.apache.camel.http.common.HttpMessage.createBody(HttpMessage.java:80) at org.apache.camel.impl.MessageSupport.getBody(MessageSupport.java:54) at org.apache.camel.processor.DefaultExchangeFormatter.getBodyTypeAsString(DefaultExchangeFormatter.java:468) at org.apache.camel.processor.DefaultExchangeFormatter.format(DefaultExchangeFormatter.java:126) at org.apache.camel.processor.CamelLogProcessor.process(CamelLogProcessor.java:88) at org.apache.camel.component.log.LogProducer.process(LogProducer.java:40) at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:148) at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) at org.apache.camel.processor.Pipeline.process(Pipeline.java:138) at org.apache.camel.processor.Pipeline.process(Pipeline.java:101) at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97) at org.apache.camel.http.common.CamelServlet.doService(CamelServlet.java:208) at org.apache.camel.http.common.CamelServlet.service(CamelServlet.java:78) at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:110) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:108) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:106) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) Caused by: java.io.IOException: Stream closed at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:346) at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:152) 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) ... 60 more
Workaround / Additional notice:
- If I rewrite my example route to work without a processor, .setHeader(Exchange.HTTP_URI, constant("https://some.external.system/")) everything works, so it seems to be an issue with the processor handling. Nevertheless, processor logic should also work.
- even if i use a simple to("log:com.mycompany.order?showAll=true&multiline=true") the issue occurs as well. So it has nothing to with the camel-http4 producer.
- Adding "mapHttpMessageBody=false" to the servlet definition seems to be a proper workaround for my example, since I only proxy GET requests which never have a body in the request.
- I already debug into the camel code, but i am not 100% sure if this is the correct place to fix: org.apache.camel.http.common.DefaultHttpBinding.parseBody(HttpMessage) - here it might make sense to skip body parsing for certain HTTP methods (e.g. GET)
- I found two quiet similar issues on the mailing list: