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

Null value for HttpServletRequest after http call

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Not A Bug
    • 3.16.0
    • None
    • camel-http
    • None
    • Unknown

    Description

      I am trying to generate an audit message after a HTTP call, the audit message needs to contain the body of the original request. 

       

      I have the following route snippet:

       
      from("direct:myqueue").setHeader(Exchange.HTTP_METHOD, constant(org.apache.camel.component.http.HttpMethods.POST)).setHeader(Exchange.CONTENT_TYPE, simple("application/json")).to("http://127.0.0.1:4000/").process("AuditProcessor").to("file://target/audit");
       
      The AuditProcessor class contains the fragment:
      public void process(Exchange exchange) throws Exception {
      HttpServletRequest request = exchange.getIn().getBody(HttpServletRequest.class);
      String httpRequestBody = request.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
       
      however, request is always being evaluated as null. 
       
      The documentation https://camel.apache.org/components/3.15.x/http-component.html#:~:text=camel%2Dcxf%20endpoint.-,HttpServletRequest,-request%20%3D%20exchange.getIn suggests I should be able to access the request object after the http request in the pipeline.
       
      Thanks

      Attachments

        Activity

          People

            Unassigned Unassigned
            tropas Andy Mitchell
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: