Vicky
Vicky

Reputation: 889

Mule REST Component Return type

I am trying to implement the REST component in Mule Flow and I was able to expose REST services also and the response is coming back to client also. But When I put Mule Java Component to access the properties of the REST component response, I am not able to 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 for the first sysout is Message payload class is class org.mule.module.jersey.JerseyResourcesComponent$2 but when I trying to cast it org.mule.module.jersey.JerseyResourcesComponent object, it is giving classCastException, java.lang.ClassCastException: org.mule.module.jersey.JerseyResourcesComponent$2 cannot be cast to org.mule.module.jersey.JerseyResourcesComponent What does this $2 means after the class name and what can be the possible solution to this.

Basically I am trying to route my message based on the REST component response before sending the response to client.

Hope I am clear with my question.

Upvotes: 3

Views: 634

Answers (1)

Vicky
Vicky

Reputation: 889

I got the answer from 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. It solved my purpose.

Upvotes: 1

Related Questions