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();
//remove this property 
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               : 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 ( (null)
2. com.sun.jersey.spi.container.ContainerResponse (org.apache.commons.lang.SerializationException)
  org.apache.commons.lang.SerializationUtils:111 (null)
3. 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 (
Root Exception stack trace: com.sun.jersey.spi.container.ContainerResponse
        at Source)
        at Source)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

Post Comments and Suggestions !!