2017-02-16 2 views
0

Получение 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] соответственно.

Я пытаюсь вернуть сумму переданных параметров.

import java.lang.Integer; 

int firstValue = Integer.pareseint(flowVars.var1); 
int secondValue =Integer.pareseint(flowVars.var2); 
int result = firstValue + secondValue; 
payload = result 

UPDATE: Я разрешил ошибку, но теперь она конкатенации входы не добавлять их. Другие операторы, такие как *, /, - и т. Д. Работают нормально.

ответ

0

Вы можете попробовать использовать Mule Expression как: # [2 + 4]

0

Вы можете попробовать это следующим образом, используя компонент Java трансформатор. Это работает для меня.

Ниже основной мул 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> 

А ниже классу Java который ява трансформатор компонент использовать для преобразования сообщения. Помните, чтобы поставить класс java под src/main/java папка.

org.mule.transformar.Addition

package org.mule.transformar; 

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

public class Addition extends AbstractMessageTransformer{ 

    @Override 
    public Integer transformMessage(MuleMessage message, String outputEncoding) throws TransformerException { 
     // TODO Auto-generated method stub 

     Integer i1 = Integer.parseInt(message.getProperty("var1", PropertyScope.INVOCATION)); 

     Integer i2 = Integer.parseInt(message.getProperty("var2", PropertyScope.INVOCATION)); 

     Integer returnVal = i1 + i2; 

     return returnVal; 
    } 
} 
0

Вы сделали все правильно, но лишь немногие ошибки синтаксиса как 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://localhost:8081/test/?value1=12&value2=100

Смежные вопросы