【发布时间】:2015-07-01 04:06:36
【问题描述】:
我正在尝试在 Mule Flow 中实现 REST 组件,并且我还能够公开 REST 服务,并且响应也会返回给客户端。但是当我让 Mule Java 组件访问 REST 组件响应的属性时,我无法做到这一点。下面是我的 Mule 消息处理器的代码,
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;
}
}
第一个 sysout 的输出是
Message payload class is class org.mule.module.jersey.JerseyResourcesComponent$2 但是当我尝试将它转换为 org.mule.module.jersey.JerseyResourcesComponent 对象时,它给出了 classCastException,java.lang.ClassCastException: org.mule.module.jersey.JerseyResourcesComponent$2 cannot be cast to org.mule.module.jersey.JerseyResourcesComponent
这个 $2 在类名之后意味着什么以及可能的解决方案是什么。
基本上,在将响应发送到客户端之前,我会尝试根据 REST 组件响应来路由我的消息。
希望我的问题很清楚。
【问题讨论】:
-
XML 配置?骡版?
-
我猜你已经在这里得到了答案:- forum.mulesoft.org/mulesoft/topics/rest-component-return-type
-
@AnirbanSenChowdhary 是的,我得到了答案,也在这里发布了答案。
标签: java rest jersey mule mule-component