在Mule3 Web服务中调用子流 [英] call subflow with in mule3 webservice
本文介绍了在Mule3 Web服务中调用子流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个Mule3简单前端Web服务,该服务应该将XML消息传递给子流,并将成功返回给其调用方.
I created a Mule3 Simple Front-end Web Service which is supposed to pass the XML message to a sub-flow and returns success to its caller.
mule-config.xml
mule-config.xml
<flow name="webserviceTestFlow">
<http:inbound-endpoint address="${webservicetest.env.endpoint}" exchange-pattern="request-response" doc:name="HTTP"/>
<cxf:simple-service serviceClass="com.test.WebserviceTest" doc:name="SOAP"/>
<component class="com.test.WebserviceTestImpl" />
</flow>
示例网络服务方法
public class WebserviceTestImpl implements WebserviceTest,Serializable {
@Override
public String test(String requestMessage) throws Exception{
// sends XML message to a sub-flow
return "success";
}
问题是我找不到在webservice方法中调用子流的call子api.
The issue is I do not find an mule api to call a sub-flow with in webservice method.
推荐答案
从代码中调用sub-flow
并非易事,但有可能.
Invoking a sub-flow
from code is no small feat but possible.
这是一个测试组件,它确实会调用注入其中的sub-flow
:
Here is a test component that does invoke a sub-flow
injected in it:
public class TestComponent implements MuleContextAware, FlowConstructAware
{
private MuleContext muleContext;
private FlowConstruct flowConstruct;
private MessageProcessor subFlow;
public void initialize() throws MuleException
{
muleContext.getRegistry().applyProcessorsAndLifecycle(subFlow);
}
public String test(final String requestMessage) throws Exception
{
final MuleEvent muleEvent = new DefaultMuleEvent(new DefaultMuleMessage(requestMessage, muleContext),
MessageExchangePattern.REQUEST_RESPONSE, flowConstruct);
final MuleEvent resultEvent = subFlow.process(muleEvent);
return resultEvent.getMessageAsString();
}
public void setMuleContext(final MuleContext muleContext)
{
this.muleContext = muleContext;
}
public void setFlowConstruct(final FlowConstruct flowConstruct)
{
this.flowConstruct = flowConstruct;
}
public void setSubFlow(final MessageProcessor subFlow)
{
this.subFlow = subFlow;
}
}
以这种方式配置组件:
<spring:beans>
<spring:bean name="testComponent" class="com.example.TestComponent"
p:subFlow-ref="testSubFlow" init-method="initialize" />
</spring:beans>
...
<component>
<spring-object bean="testComponent" />
</component>
这篇关于在Mule3 Web服务中调用子流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文