这是我在流程中所做的事情:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<spring:beans>
<spring:bean id="JavaMule" class="com.intuit.platform.fdp.transaction.orchestration.JavaMule"/>
</spring:beans>
<flow name="javaflowFlow1" doc:name="javaflowFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="9090" path="java" doc:name="HTTP"/>
<component class="com.intuit.platform.fdp.transaction.orchestration.JavaMule" doc:name="Java">
</component>
<set-payload value="#['This is my clientcontext'+ '13424234']" doc:name="Set Payload"/>
<invoke object-ref="JavaMule"
method="myMethod"
methodArguments="#[payload]" doc:name="Invoke"/>
<object-to-string-transformer doc:name="Object to String" returnClass="com.intuit.platform.fdp.transaction.orchestration.DummyPojo"/>
<echo-component doc:name="Echo"/>
</flow>
</mule>
这是myMethod
的代码。
public DummyPojo myMethod(String payload) throws IOException {
// do things with payload.
DummyPojo pojo = new DummyPojo();
pojo.setCode(0);
pojo.setDesc(payload);
return pojo;
}
以及 DummyPojo
的代码。
public class DummyPojo {
private int code;
private String desc;
public int getCode() {
return code;
}
public String getDesc() {
return desc;
}
public void setCode(int code) {
this.code = code;
}
public void setDesc(String desc) {
this.desc = desc;
}
}
但是,当我运行流程时,出现以下错误。
The object transformed is of type: "SimpleDataType{type=java.lang.String, mimeType='*/*'}", but the expected return type is "SimpleDataType{type=com.test.DummyPojo, mimeType='text/plain'}" (org.mule.api.transformer.TransformerException). Message payload is of type: DummyPojo
对我在流程中做错了什么有什么想法吗?我正在尝试返回自定义对象而不是字符串。
编辑:
我正在尝试使我创建的对象(DummyPojo)可供另一个骡子流使用。 IE。例如,子流 B 会生成一个 DummyPojo
作为其操作的结果。我如何/从 B 返回什么,以便 A 可以使用返回的对象
最佳答案
这里有很多事情不完全正确:
同一个类被实例化两次:com.intuit.platform.fdp.transaction.orchestration.JavaMule。
这会连续调用两次,一次使用组件,一次使用调用。如果 JavaMule 只有一个带有单个参数字符串签名的方法,那么我将保留组件并删除调用。
正如 Ryan 所说,字符串转换器的对象是不正确的。此外,这可能不是您想要做的。在您的问题中,您提到您想要返回一个对象,如果这实际上是您的意图,只需完全删除对象到字符串转换器即可。如果您想以某种方式序列化对象,只需使用 xstream 的对象到 xml 转换器或对象到 bytearray 转换器。
如果您使用 echo 组件的目的是记录有效负载,则应使用 logger
元素:<logger messsage="#[message.payload]" />
echo-component
是 mule 2 已弃用的组件,它会产生一些不良影响,例如将入站属性复制到出站。
编辑:
要拥有一个可从其他流程调用的可重用流程,您不需要明确执行任何操作,只需使用 flow-ref 调用该流程即可。 :
<flow-ref name="javaflowFlow1" />
这将忽略 inbound-endpoint
(无论如何,您在问题的流程中可能不需要)。
有关此主题的更多信息,您可以访问 documentation ,开始使用 Mule Cloud connect ,和Mule in action .
关于java - 在将自定义对象返回到 mule 流时我做错了什么以及如何返回可由另一个 mule 流使用的对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27160863/