Reputation: 6186
I have a mule flow which uses Jersey REST component
<flow name="rest-api" doc:name="rest-api">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" path="rest" port="8081" doc:name="HTTP" />
<logger message="Message !!!!!!!! #[payload]" level="INFO"
doc:name="Logger" />
<jersey:resources doc:name="REST">
<component class="com.test.api.TestAPI" />
</jersey:resources>
<logger message="Message $$$$$$$ #[payload]" level="INFO" doc:name="Logger" />
</flow>
The object past jersey component is of type "org.mule.module.jersey.MuleResponseWriter"
How to process this payload? I need to use the message and do some work on the message before returning to the invoker.
Ref: http://www.mulesoft.org/documentation/display/current/Jersey+Module+Reference
Sending Jersey response to other flows
If you want to transform or send the request from your jersey component to next resource/flow then you need to use
ContainerResponse cr = (ContainerResponse) message.getInvocationProperty("jersey_response");
String messageString = (String) cr.getResponse().getEntity();
message.setPayload(messageString);
This will convert org.mule.module.jersey.MuleResponseWriter$1 type to String, which you can forward to your next resource.
Upvotes: 2
Views: 1997
Reputation: 33413
Note: The question has been drastically reviewed by the OP (see history), so this answer now looks disconnected. This answer explain how a Jersey resource can interact with other flows.
To invoke other flows from your resources, you can either:
MuleContextAware
then use the MuleClient to perform calls.This is one of the problems APIkit is solving: http://www.mulesoft.org/documentation/display/current/APIkit
Upvotes: 5
Reputation: 6186
Created the following transformer.It converts the Jersey's Response to String
public class JerseyResponseTransformer extends AbstractMessageTransformer {
public static Logger logger = Logger.getLogger(JerseyResponseTransformer.class);
@Override
public Object transformMessage(MuleMessage message, String outputEncoding)
throws TransformerException {
logger.debug("Transfroming Jersey Response to String");
ContainerResponse cr = (ContainerResponse) message.getInvocationProperty("jersey_response");
String messageString = (String) cr.getResponse().getEntity();
message.setPayload(messageString);
return message;
}
}
Upvotes: 1