gpt4 book ai didi

java - 如何在java代码中访问Mule流变量?

转载 作者:行者123 更新时间:2023-11-30 03:23:30 24 4
gpt4 key购买 nike

浏览了一下,我发现了如下所示的内容:

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="{&quot;channel&quot;: &quot;#testing&quot;, &quot;username&quot;: &quot;Testing&quot;, &quot;text&quot;: &quot;#[payload]&quot;}" 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>

最佳答案

我不确定这是否是正确的解决方案,但我为解决此问题所做的是将java代码中的变量设置为message.getInitationProperty的值,然后返回该java变量,如下所示:

import org.mule.api.MuleMessage;
import org.mule.api.transformer.TransformerException;
import org.mule.transformer.AbstractMessageTransformer;

public class javaTest extends AbstractMessageTransformer{
public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException{
String testS = message.getInvocationProperty("test");
return testS;
}
}

关于java - 如何在java代码中访问Mule流变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30783107/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com