Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
439 views
in Technique[技术] by (71.8m points)

mule - call subflow with in mule3 webservice

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


<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>

sample webservice method


public class WebserviceTestImpl implements WebserviceTest,Serializable {
        @Override
    public String test(String requestMessage) throws Exception{
               // sends XML message to a sub-flow
               return "success";
        }

The issue is I do not find an mule api to call a sub-flow with in webservice method.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Invoking a sub-flow from code is no small feat but possible.

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;
    }
}

The component is configured this way:

<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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...