我正在尝试调用一个从Mule中的Java Invoke实现Callable的类。但我无法弄清楚从调用配置中传递的方法参数。请帮忙!
public class ModificationService implements Callable {
@Override
public Object onCall(MuleEventContext eventContext) throws Exception {
MuleMessage msg = eventContext.getMessage();
String path = msg.getProperty("destination", PropertyScope.OUTBOUND);
String[] splitpath = path.split("/");
path = splitpath[0];
msg.setProperty("destination", path, PropertyScope.OUTBOUND);
MuleMessage newMessage = new DefaultMuleMessage(path, msg, eventContext.getMuleContext());
return newMessage;
}
配置XML
<invoke name="ModificationBean" object-ref="modificationServiceBean" method="onCall" methodArguments="#[payload]" doc:name="Invoke"/>
我已经传递了消息有效负载,只是为了不将参数部分保持为空。
答案 0 :(得分:0)
我相信您创建的类将适用于mule的Java Component,因为您需要对MuleEventContext的引用,您可以在其中获取有效负载的值。
请看这个链接:
https://docs.mulesoft.com/mule-user-guide/v/3.7/java-component-reference
虽然您正在寻找的是:
https://docs.mulesoft.com/mule-user-guide/v/3.7/invoke-component-reference
您需要创建自定义类,请参阅下面的示例:
addTwoNumbers是类方法,其中#[1]和#[2]作为参数。那些可以是flowVars或SessionVars或有效载荷。
答案 1 :(得分:0)
这可以帮到你:
&#34;如何在同一个java组件中设置/获取变量,操作或修改有效负载,读取属性文件和弹簧&#34;
https://stackoverflow.com/a/32612487/3957754
https://github.com/jrichardsz/mule-esb-usefull-templates
具有可调用方法的简单组件:
package com.spring.component;
import java.util.Map;
import javax.annotation.Resource;
import org.mule.api.MuleEventContext;
import org.mule.api.lifecycle.Callable;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.mule.api.transport.PropertyScope;
@Component("myComponent")
@Scope("prototype")
/*
* Use Callable if you want :
* (spring functionalities, handle mule message and read a properties file)
* at the same time.
* */
public class MyComponent implements Callable{
// @Autowired
// private AnotherSpringComponetOrServiceOrWhatever spring;
@Override
public Object onCall(MuleEventContext eventContext) throws Exception {
//get payload
String payload = (String) eventContext.getMessage().getPayload();
//SESSION, INBOUND, OUTBOUND, APPLICATION
//http://blogs.mulesoft.com/dev/anypoint-platform-dev/mule-school-the-mulemessage-property-scopes-and-variables/
//get vars according to its scope
String inputProperty = eventContext.getMessage().getProperty("inputProperty", PropertyScope.INVOCATION);
//set vars in some scope
eventContext.getMessage().setProperty("key", "some_value", PropertyScope.SESSION);
//return eventContext.getMessage().getPayload(); //payload is intact
return "NEW_PAYLOAD";
}
}
春天的骡子流:
<component doc:name="myComponent">
<spring-object bean="myComponent" />
</component>
或没有弹簧(删除弹簧注释)
<component class="com.spring.component.MyComponent" doc:name="MyComponent"/>
我希望这会对你有所帮助。