【问题标题】:Mule REST Component Return typeMule REST 组件返回类型
【发布时间】: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 组件响应来路由我的消息。

希望我的问题很清楚。

【问题讨论】:

标签: java rest jersey mule mule-component


【解决方案1】:

我从 Mule 论坛得到了答案。

$2 是由 Jersey 组件创建的 org.mule.api.transport.OutputHandler 类型的匿名类。

我尝试使用“字节数组到字符串”并且它有效。它解决了我的目的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-23
    相关资源
    最近更新 更多