Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Not A Bug
-
3.16.0
-
None
-
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