uthomas
uthomas

Reputation: 754

How echo back various parts of request into response in mule

Context: I have an XML based API. I get requests using this API. Then I have transformers that transform this requests into a 3rd party specific API. Then I do a web-service call using the transformed object, get back some response that I transform back to my API object.

In one line it's like:

MY_API_REQ -> 3RD_PARTY_API_REQ -> WS-CAL -> 3RD_PARTY_API_RES -> MY_API_RES

Dead simple.

Problem: Now, I want to echo back some parts of my request in my response.

So let's say my request API has an Echo component that must be present in the response also. The simplest solution appears to me that I store somewhere (for e.g.: in session scoped header property) this Echo component before transforming my request to API of 3rd party. Then on the response branch I retrieve this Echo component and set it on my response object.

In one line it's like:

MY_API_REQ -> Store parts -> 3RD_PARTY_API_REQ -> WS-CAL -> 3RD_PARTY_API_RES -> MY_API_RES -> Retrieve and set stored parts

Concern: This solution doesn't make my feel like I'm using the best possible solution. Partially cause I'm afraid that there are copy mechanisms during execution of the flow that I'm not aware of and that makes me worried about performance...

I'm doing all of this synchronously so I should be on the same thread all the way down so maybe my concerns has no bases what so ever. However before doing some performance testing or profiling I wanted to ask you guys about this...

Laziness is half healthiness. ;) Thanks in advance: T

Upvotes: 0

Views: 187

Answers (1)

David Dossot
David Dossot

Reputation: 33413

There are two different approaches (you're using the first one):

  • Store the information you want to keep in a property and let the outbound interactions replace the payload with their responses, subsequently retrieving the saved information from the property. Using a flow variable instead of a session property would be more advisable if you do not need to share this stored information across flows.
  • Transform the original payload into the intended response, propagating this "echo" value and interact with outbound services with message enrichers. This can be semantically clearer if the outbound interactions are really about enriching the response.

Upvotes: 1

Related Questions