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

java.io.IOException: Stream closed with mongodb3 when no data in findOneByQuery

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.23.0
    • 4.x
    • camel-mongodb3
    • None
    • Novice

    Description

      When doing something like:

      from("direct:my-endpoint")
        .to("mongodb3:cosmosdb?database=dbname&collection=collname&operation=findOneByQuery")

      The code works fine if something is found in the db. If no result is returned from the query, I obtain a stacktrace like that:

      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.RestBindingAdvice.marshal(RestBindingAdvice.java:402)
          at org.apache.camel.processor.RestBindingAdvice.after(RestBindingAdvice.java:151)
          at org.apache.camel.processor.RestBindingAdvice.after(RestBindingAdvice.java:51)
          at org.apache.camel.processor.CamelInternalProcessor$InternalCallback.done(CamelInternalProcessor.java:251)
          at org.apache.camel.processor.Pipeline.process(Pipeline.java:127)
          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:213)
          at org.apache.camel.http.common.CamelServlet.service(CamelServlet.java:79)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:750)
          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:53)
          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.FormContentFilter.doFilterInternal(FormContentFilter.java:92)
          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:93)
          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:200)
          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:490)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
          at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
          at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
          at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:770)
          at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
          at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
          at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
          at java.lang.Thread.run(Thread.java:745)
      Caused by: java.io.IOException: Stream closed
          at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:338)
          at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:132)
          at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:110)
          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:243)
          at org.apache.camel.http.common.HttpHelper.readRequestBodyFromServletRequest(HttpHelper.java:194)
          at org.apache.camel.http.common.DefaultHttpBinding.parseBody(DefaultHttpBinding.java:595)
          at org.apache.camel.http.common.HttpMessage.createBody(HttpMessage.java:78)
          ... 48 more
      

      Note that I call the route from a rest endpoint and that the stacktrace appear in the http response (not in the logs)

      I found a work around:

      from("direct:my-endpoint")
        .to("mongodb3:cosmosdb?database=dbname&collection=collname&operation=findOneByQuery")
        .choice()
          .when(header(RESULT_TOTAL_SIZE).isLessThan(1))
              .setBody(simple("{}"))
        .end()

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            carlphilipp Carl-Philipp Harmant
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: