Sunday 20 October 2013

Textual description of firstImageUrl

Send Jersey Response to other flows in Mule 3.3

Creating Rest Web Services in mule is very easy and explained in previous post Now If you want to preserve the rest response in your flow , or apply some checks on it or send it to other flows , you will write following java code to do this :
//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) eventContext.getMessage().getInvocationProperty("jersey_response");
String messageString = (String) cr.getResponse().getEntity();
message.setPayload(messageString);
//remove this property 
eventContext.getMessage().removeProperty("jersey_response",PropertyScope.INVOCATION);
This code will convert org.mule.module.jersey.MuleResponseWriter$1 type to String, which you can forward to your next resource. If you don't do that , you might get exception like this :


Message               : java.io.NotSerializableException: com.sun.jersey.spi.container.ContainerResponse (org.apache.commons.lang.SerializationException). Message payload is of type: String
Code                  : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. com.sun.jersey.spi.container.ContainerResponse (java.io.NotSerializableException)
  java.io.ObjectOutputStream:-1 (null)
2. java.io.NotSerializableException: com.sun.jersey.spi.container.ContainerResponse (org.apache.commons.lang.SerializationException)
  org.apache.commons.lang.SerializationUtils:111 (null)
3. java.io.NotSerializableException: com.sun.jersey.spi.container.ContainerResponse (org.apache.commons.lang.SerializationException). Message payload is of type: String (org.mule.api.MessagingException)
  org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:35 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.io.NotSerializableException: com.sun.jersey.spi.container.ContainerResponse
        at java.io.ObjectOutputStream.writeObject0(Unknown Source)
        at java.io.ObjectOutputStream.writeObject(Unknown Source)
        at org.apache.commons.collections.map.AbstractHashedMap.doWriteObject(AbstractHashedMap.java:1182)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
******************************************************************************** 

Post Comments and Suggestions !!