【发布时间】:2015-06-11 14:04:26
【问题描述】:
浏览了一下,发现如下图:
import org.mule.api.MuleMessage;
import org.mule.api.transformer.TransformerException;
import org.mule.transformer.AbstractMessageTransformer;
import java.util.Scanner;
public class javaTest extends AbstractMessageTransformer{
public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException{
message.getInvocationProperty("test");
return message;
}
}
我正在使用此代码,其中消息是我刚刚声明为“测试”的 Mule 流变量。问题是,当我发送有效负载时,我得到“{NullPayload}”,这不太正确。我只想让它返回字符串“test”。
我在这里做错了什么?我的 Mule 代码如下所示:
<?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">
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration"/>
<http:request-config name="HTTP_Request_Configuration" protocol="HTTPS" host="hooks.slack.com" doc:name="HTTP Request Configuration"/>
<flow name="testFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<set-variable variableName="test" value="Test" doc:name="Variable"/>
<custom-transformer class="javaTest" doc:name="HelloWorld"/>
<set-payload value="{"channel": "#testing", "username": "Testing", "text": "#[payload]"}" doc:name="Set Payload"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<http:request config-ref="HTTP_Request_Configuration" path="/services/slackURL" method="POST" doc:name="HTTP"/>
</flow>
</mule>
【问题讨论】:
-
这个转换器是一个空操作:它返回它收到的消息。它对“测试”调用属性也没有任何作用。你在这里的意图是什么?