获取org.mule.api.expression.ExpressionRuntimeException
在mule中运行以下代码段时获取org.mule.api.expression.ExpressionRuntimeException 我在var1和var2中分别将值存储为[message.inboundProperties.http.query.params.value1]和[message.inboundProperties.http.query.params.value2] 我试图返回传递的参数之和获取org.mule.api.expression.ExpressionRuntimeException,mule,Mule,在mule中运行以下代码段时获取org.mule.api.expression.ExpressionRuntimeException 我在var1和var2中分别将值存储为[message.inboundProperties.http.query.params.value1]和[message.inboundProperties.http.query.params.value2] 我试图返回传递的参数之和 import java.lang.Integer; int firstValue = I
import java.lang.Integer;
int firstValue = Integer.pareseint(flowVars.var1);
int secondValue =Integer.pareseint(flowVars.var2);
int result = firstValue + secondValue;
payload = result
更新:我已经解决了这个错误,但是现在它正在连接输入,而不是添加它们。其他操作符,如*、/、-,等工作正常。您可以尝试使用Mule表达式作为:#[2+4]您可以使用java transformer组件以以下方式进行尝试。这对我有用 下面是主mule xml配置文件
<?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"
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="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="tryoutFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/bill" allowedMethods="GET" doc:name="HTTP"/>
<set-variable variableName="var1" value="#[message.inboundProperties.'http.query.params'.value1]" doc:name="var1"/>
<set-variable variableName="var2" value="#[message.inboundProperties.'http.query.params'.value2]" doc:name="var2"/>
<custom-transformer class="org.mule.transformar.Addition" returnClass="java.lang.Integer doc:name="Java">
</custom-transformer>
</flow>
</mule>
您做的一切都是对的,但是很少有语法错误,比如
Integer.pareseint
而不是Integer.parseInt
请参考以下流程,使其以简单的方式工作:-
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="testFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
<set-variable doc:name="Variable" value="#[message.inboundProperties.'http.query.params'.value1]" variableName="var1"/>
<set-variable doc:name="Variable" value="#[message.inboundProperties.'http.query.params'.value2]" variableName="var2"/>
<expression-component doc:name="Expression"><![CDATA[
import java.lang.Integer;
int firstValue = Integer.parseInt(flowVars.var1);
int secondValue = Integer.parseInt(flowVars.var2);
int result = firstValue + secondValue;
payload = result]]></expression-component>
<object-to-string-transformer doc:name="Object to String"/>
<logger message="#['Total '+message.payload]" level="INFO" doc:name="Logger"/>
</flow>
要测试的url为:-
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="testFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
<set-variable doc:name="Variable" value="#[message.inboundProperties.'http.query.params'.value1]" variableName="var1"/>
<set-variable doc:name="Variable" value="#[message.inboundProperties.'http.query.params'.value2]" variableName="var2"/>
<expression-component doc:name="Expression"><![CDATA[
import java.lang.Integer;
int firstValue = Integer.parseInt(flowVars.var1);
int secondValue = Integer.parseInt(flowVars.var2);
int result = firstValue + secondValue;
payload = result]]></expression-component>
<object-to-string-transformer doc:name="Object to String"/>
<logger message="#['Total '+message.payload]" level="INFO" doc:name="Logger"/>
</flow>