Question

Dear all, In the first happy new year.

My Objective is as follow:

I have two axis2 webservices (ws1, ws2) deployed in wso2as. The Client, through wso2esb has to give arguments to ws1, and the returned value must be given to ws2 as an argument that will return the final value to the Client. So what the Client Make, is just give the Arguments to ws1 and receive the final response from ws2.

Question:

How to make that Step By Step and make the ws1 and ws2 communicate (I think it's through Proxy)? Cause I tried many tuto and no one is for my detailed cause I'm really begginer with ESBs.

Thanks a lot.

Was it helpful?

Solution

Yes. You can do this in one step. I had done this in a project before: Here is the steps you can follow:

1. ws1 and ws2 are both have "endpoints" defined in the ESB.
2. In the ws1 proxy, define a target inSequence to point to a "sequence"
   for example "ws1InSequence"
3. In the "ws1InSequence", you can use <filter> to make sure the value is exists.
   Then you can <send> to the ws1 <endpoint> with "receive" attribute point to
   a sequence for example "ws1ResultSequence"
4. In the ws1ResultSequence, you can again use the <filter> to make sure 
   it has the parameter/value you need. Then you can use param/value to format a request message.
<payloadFactory>
    <format>
        <ns1: ws2Operation
            xmlns:ns1="ws2Namespace">
            <element1 xmlns="">$1</element1> 
            <!-- Note $1 will have the //paramName value from the ws1 Result message -->
            <element2 xmlns="">$2</element2>
            <!-- Note $2 will have the //paramName2 value from the ws1 Result message -->
    </format>
    <args>
        <arg expression="//paramName" />
        <arg expression="//paramName2" />
    </args>
</payloadFactory>
5. Still in ws1ResultSequence, after you create the request message, 
   you <send> it to the ws2 proxy. Then in the ws2 proxy, in the <outSequence>
   you can juse use <send/> to send the response to the client.

Note, you may need to include exception(faultSequence) handling.

WSO2ESB use Apache Synapse for the configuration. You can find most of the syntax and example usages in their doc: http://synapse.apache.org/userguide/config.html

UPDATE: You can use this as an example. NOTE, this may not be the completed code as you need, and you may need to add exception handling.

   <sequence xmlns="http://ws.apache.org/ns/synapse" name="ws1ResultSequence"
trace="enable" onError="ws1ResultSequenceErrorHandler">
<log level="custom">
    <property name="sequence" value="INVOCATION START: ws1ResultSequence" />
</log>
<!-- record the original message for future reference -->
<enrich>
    <source clone="true" type="envelope" />
    <target action="replace" type="property" property="ORIGINAL" />
</enrich>

<!-- Check if the ws1 result message has the value -->
<property
    xmlns:ns1="ws1Namespace"
    name="valueExists" expression="//ns1:element1" />
    <!--Note here, element1 is the element name which has the value: output1 -->

<filter xpath="fn:boolean( get-property('valueExists') )">
    <then>
        <!-- create the request message to invoke ws2 -->
        <payloadFactory>
            <format>
                <ns1:ws2OperationName
                    xmlns:ns1="ws2Namespace">
                    <element2 xmlns="">$1</element2>
                </ns1:ws2OperationName>
            </format>
            <args>
                <arg expression="//ns1:element1" />
            </args>
        </payloadFactory>
        <log level="custom">
            <property name="inInvokeWS2" value="INVOCATION START: value from ws1 result exists" />
        </log>

        <send>
            <endpoint key="ws2Sequence" />
        </send>
        <drop/>
    </then>
</filter>
<!-- No result value found from the ws1 result message -->
<send>
    <endpoint key="DoSomethingElseOrThrowError" />
</send>

OTHER TIPS

What you need to do is, invoke ws1, get the response, extract the value from the response, then create the payload to be sent to ws2 and invoke ws2. This webinar shows how to do a similar scenario.

I will try to explain all the followed steps :


WebServices

  1. wsOne deployed in wso2as: takes as parameters: wsOne (input1, size) and return a table of 3 strings (t1, t2, output1),
  2. ws2One deployed in wso2as: takes as parameters: wsTwo(output1) and return String : "Hello output1".

wsOne :

EndPoint (In wso2as): http://localhost:9765/services/wsOne

WSDL (In wso2as): http://localhost:9765/services/wsOne?wsdl

wsTwo :

EndPoint (In wso2as): http://localhost:9765/services/wsTwo

WSDL (In wso2as): http://localhost:9765/services/wsTwo?wsdl


  1. Now I am in wso2esb, and I have to create a sequences before the proxies because I'll call the sequences inside the proxies for each ws:

Sequences

ServiceBus -> Sequences -> Defined Sequences -> Add Sequence.

ws1ResultSequence

I don't knwo exactly what must contain cause When I tried to create the payload I had error..

ws1InSequence

<sequence xmlns="http://ws.apache.org/ns/synapse"><in>
  <filter>
     <then>
        <send receive="ws1ResultSequence">
           <endpoint>
              <address uri="http://localhost:9765/services/wsOne"/>
           </endpoint>
        </send>
       </then>
     <else/>
    </filter>
  </in>
</sequence>

ws2Sequence

<sequence xmlns="http://ws.apache.org/ns/synapse" name="conf:/ws2Sequence">
   <out>
      <send/>
   </out>
</sequence>

Proxies

ws1Proxy

Add->Proxy Service ->Custom Proxy-> Name: ws1proxy, publishing wsdl: No, Next -> Define InSequence-> Pick from Registry -> ws1InSequence.

ws2Proxy

Add->Proxy Service ->Custom Proxy-> Name: ws2proxy, publishing wsdl: No, Next -> Define InSequence-> Pick from Registry -> ws2Sequence.


Is My steps correct or not ? I know that I did Many mistakes following as it's my first interaction with SOA, ESB, ... What Must the Client execute to launch the chaining and obtain the required result (ws1Proxy) or an other?

Thanks a lot for your time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top