Mule REST Component Return Type

I am trying to implement a REST component in Mule Flow and I was able to expose REST services as well and the response is returned to the client as well. But when I put the Mule Java Component in order to access the response properties of the REST component, I cannot do that. Below is the code of my Mule message processor,

public class RestResponseProcessor implements Callable{

@Override
public Object onCall(MuleEventContext eventContext) throws Exception {
    Object messagePayload = eventContext.getMessage().getPayload();
    System.out.println("Message payload class is  " + messagePayload.getClass());
    org.mule.module.jersey.JerseyResourcesComponent jerseyResponse = (org.mule.module.jersey.JerseyResourcesComponent) messagePayload;
    System.out.println("jerseyResponse.getClass() is  " + jerseyResponse.getClass());
    return eventContext;
}

}

      

The output is for the first sysout Message payload class is class org.mule.module.jersey.JerseyResourcesComponent$2

, but when I try to create an object org.mule.module.jersey.JerseyResourcesComponent

it gives a classCastException, java.lang.ClassCastException: org.mule.module.jersey.JerseyResourcesComponent$2 cannot be cast to org.mule.module.jersey.JerseyResourcesComponent

What does this $ 2 after the class name mean and what might be a possible solution to this.

Basically I'm trying to redirect my message based on the response of the REST component before sending the response to the client.

Hope I understood my question.

+3


source to share


1 answer


I got a response from the Mule forum.

$ 2 is an anonymous class of type org.mule.api.transport.OutputHandler created by the Jersey component.



I tried using "Byte Array To String" and it worked. This solved my goal.

+1


source







All Articles