1

我创建了一个 Mule3 简单前端 Web 服务,它应该将 XML 消息传递给子流并将成功返回给它的调用者。

骡子配置.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";
        }

问题是我没有找到一个 mule api 来调用 webservice 方法中的子流。

4

2 回答 2

1

从代码调用一个sub-flow不小的壮举,但可能。

这是一个调用sub-flow注入的测试组件:

公共类TestComponent实现MuleContextAware,FlowConstructAware
{
    私人骡上下文骡上下文;
    私有 FlowConstruct 流构造;
    私有 MessageProcessor 子流;

    public void initialize() 抛出 MuleException
    {
        muleContext.getRegistry().applyProcessorsAndLifecycle(subFlow);
    }

    公共字符串测试(最终字符串请求消息)抛出异常
    {

        final MuleEvent muleEvent = new DefaultMuleEvent(new DefaultMuleMessage(requestMessage, muleContext),
            MessageExchangePattern.REQUEST_RESPONSE, flowConstruct);
        最终 MuleEvent resultEvent = subFlow.process(muleEvent);

        返回结果事件.getMessageAsString();
    }

    公共无效 setMuleContext(最终 MuleContext muleContext)
    {
        this.muleContext = muleContext;
    }

    公共无效setFlowConstruct(最终FlowConstruct flowConstruct)
    {
        this.flowConstruct = flowConstruct;
    }

    公共无效 setSubFlow(最终 MessageProcessor 子流)
    {
        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>
于 2013-05-13T23:52:56.230 回答
0

我通过使用单例实例在 WebserviceTestImpl 类的 test() 方法中存储 requestMessage 并在 TestSubflow 组件中检索它来解决这个问题。我不确定它是否完美。但它有效:)

这是我的做法。。

骡子配置:


<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-ref name="testSubflow"/>
</flow>

<sub-flow name="testSubflow">
    <pooled-component class="com.test.TestSubflow">
        <pooling-profile exhaustedAction="WHEN_EXHAUSTED_FAIL" initialisationPolicy="INITIALISE_ALL" maxActive="1" maxIdle="2" maxWait="3" />
    </pooled-component>
</sub-flow>

WebserviceTestImpl 和 TestSubflow 代码片段


public class WebserviceTestImpl implements WebserviceTest,Serializable {
    private static final long serialVersionUID = 1L;
    private TestMessageProxy testMessageProxy;

    public TriggerTestImpl() {
        this.testMessageProxy = TestMessageProxy.getInstance();
    }
    @Override
    public String test(String requestMessage) throws Exception{
        this.testMessageProxy.setTestMessage(requestMessage);
        return "success";
    }
}

public class TestSubflow  implements Callable{
    private TestMessageProxy testMessageProxy;
    public TestSubflow() {
        this.testMessageProxy = TestMessageProxy.getInstance();
    }

    @Override
    public Object onCall(MuleEventContext context) throws Exception {
        String  testMessage = this.testMessageProxy.getTestMessage();
    }
}
于 2013-05-14T19:20:56.673 回答