1
votes

I have an Apache camel application which talks with a web service. This is purely a integration(mediation) application. We take REST request and transform it to a SOAP message (using VM templates) and call the web service. Receive response from web service, transform it to JSON and send back to our client.

REST ---->transform to SOAP req (Velocity template) ---->call WS ---->receive response---->transform into JSON---->return response to caller.

We are using servlet endpoint to receive request from our client. We can obtain HttpSession object from exchange before calling web service as follows :

HttpServletRequest req = exchange.getIn().getBody(HttpServletRequest.class);
HttpSession session = req.getSession();

However, the problem is that I cannot obtain HTTPSession from exchange after receiving response from web service. If I check the Exchange object in debug mode, the Exchange.getIn() is of type DefaultMessage rather than HttpMessage. That is the reason I think I loose Request and response objects.

I tried setting the exchange pattern to InOut but that doesn’t help. The only solution I could find is to store the original body of the in message in a header or a property and retrieve it at the end. But I think there must be a better solution that this.

Could anybody help please?

Note: We need HttpSession so that we can store corresponding session information like session id created on WS for the session created by our request. We cannot pass session information created on WS to our callers, and need a place on our application to hold this mapping info. HttpSession serves this requirement. Is there any better way?

1
Have you tried Content Enricher (camel.apache.org/content-enricher.html) pattern?Sergey
@Sergey Thank you replying my question. I tried using Enrich EIP. In theory this is the best approach, but I faced issues due to use of VM templates. As I said, we use VM templates to prepare SOAP request. Soon after I call <to uri="velocity:... the In message type gets changed to DefaultMessage from HttpMessage. I tried to find solution for that but failed. Instead I am using solution suggested by Willem Jiang.Amit

1 Answers

0
votes

You can store the http session as an exchange property, camel copy these properties across the exchanges, so you can access it in the route when you need.