2
votes

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.

UPDATE (below)

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.

2

2 Answers

5
votes

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:

This is one of the problems APIkit is solving: http://www.mulesoft.org/documentation/display/current/APIkit

1
votes

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; 
} 

}