WSO2ESB Parallel SOAP calls - wso2

I have the following problem:
Develop a WSDL Based Proxy that calls several different SOAP Web services in parallel and returns the responses:
<inSequence>
<log level="full"/>
<iterate xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:agg="http://www.test.ro/aggregate"
preservePayload="true"
attachPath="//soapenv:Body"
expression="//agg:AggregateRequest/agg:messageRequest">
<target>
<sequence>
<property name="messageId"
expression="//soapenv:Body/agg:messageRequest/agg:messageId[node()]"/>
<property name="endpoint"
expression="//soapenv:Body/agg:messageRequest/agg:endpoint[node()]"/>
<xslt key="CleanPayload" source="/"/>
<send>
<endpoint key="MirrorEndpoint"/>
</send>
</sequence>
</target>
</iterate>
</inSequence>
<outSequence>
<property name="resp" scope="default">
<agg:AggregateResponse xmlns:agg="http://www.test.ro/aggregate"/>
</property>
<aggregate>
<completeCondition timeout="10">
<messageCount min="-1" max="-1"/>
</completeCondition>
<onComplete xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
expression="$body/*"
enclosingElementProperty="resp">
<log level="full"/>
<send/>
</onComplete>
</aggregate>
</outSequence>
My challenges are:
how do I pass the messageId from inSequence to outSequence so I can match the response to the request (similar to local environment from Message Broker)
how do I set the endpoint key with the text from agg:endpoint
I know this may be a newbie question but I'm having a hard time finding good tutorials on this topic.
Thank you

When you set a property (scope default) inside the In Sequence, you can find back it's value inside the Out Sequence.
Set this property inside your In Sequence :
<property name="IN_MESSAGE_ID" expression="get-property('MessageID')"/>
you can use get-property('IN_MESSAGE_ID') in your Out Sequence
If you want to send a message to a dynamic address, you can set "To" header and use send mediator :
<header name="To" expression="get-property('MY_DESTINATION')"/>
<send/>

Try setting the messageId as a HTTP header property,
<header name="MessageId" value="0001" scope="transport"/>
And retrieve this header in the outSequence
<property name="MessageId" expression="get-property('MessageId')"/>
I havnt tested this out, so give a feedback on whether it works

Related

why call is not working in wso2 esb

I have a problem with wso2 esb.
I wrote a proxy and in that I call an endpoint to do some changes on original input. but the log before call and after call is the same(it should be different). It seems the call is not working at all.when I send respone to outsequence it is null. Can any one say why this happen? (I have tested my endpoint in soupUI)
this is my proxy:
<inSequence>
<property name="transport.vfs.ReplyFileName" value="GET" scope="transport"/>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<smooks config-key="smooks-csv1">
<input type="text"/>
<output type="xml"/>
</smooks>
<iterate continueParent="true"
preservePayload="true"
attachPath="//csv-set"
expression="//csv-set/search"
sequential="true">
<target>
<sequence>
<xslt key="gov:/first.xsl"/>
<xslt key="gov:/second.xsl"/>
**<log level="full"/>
<call blocking="true">
<endpoint>
<address uri="MyEndPiont"/>
</endpoint>
</call>
<log level="full"/>**
</sequence>
</target>
</iterate>
<respond/>
</inSequence>
<outSequence>
<aggregate>
<completeCondition>
<messageCount min="0" max="100"/>
</completeCondition>
<onComplete expression="//Guest">
</onComplete>
</aggregate>
</outSequence>
Try this. List of changes:
Removed respond mediator.
Replaced call by send.
Added send in out sequence.
<inSequence>
<property name="transport.vfs.ReplyFileName" value="GET" scope="transport"/>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<smooks config-key="smooks-csv1">
<input type="text"/>
<output type="xml"/>
</smooks>
<iterate continueParent="true"
preservePayload="true"
attachPath="//csv-set"
expression="//csv-set/search"
sequential="true">
<target>
<sequence>
<xslt key="gov:/first.xsl"/>
<xslt key="gov:/second.xsl"/>
<log level="full"/>
<send>
<endpoint>
<address uri="MyEndPiont"/>
</endpoint>
</send>
</sequence>
</target>
</iterate>
</inSequence>
<outSequence>
<aggregate>
<completeCondition>
<messageCount min="0" max="100"/>
</completeCondition>
<onComplete expression="//Guest">
</onComplete>
</aggregate>
<send />
</outSequence>
Try blocking="false". Please note that making this change does not make the call mediator is asynchonus. It's synchronous regardless of whether blocking is true or false. Blocking is just an implementation detail.
The Call mediator is used to send messages out of the ESB to an
endpoint. You can invoke services either in blocking or non-blocking
manner.
When you invoke a service in non-blocking mode, the underlying worker
thread returns without waiting for the response. In blocking mode, the
underlying worker thread gets blocked and waits for the response after
sending the request to the endpoint. Call mediator in blocking mode is
very much similar to the Callout mediator.
In both blocking and non-blocking modes, Call mediator behaves in a
synchronous manner. Hence, mediation pauses after the service
invocation and resumes from the next mediator in the sequence when the
response is received. Call mediator allows you to create your
configuration independent from the underlying architecture.
Quoted from https://docs.wso2.com/display/ESB500/Call+Mediator

Callout mediator doe'snot giving any response in WSO2 ESB 4.7.0

While I am using call out mediator in wso2 esb , with DSS Endpoint I am
getting the request only, I am not getting response, even I put log in
the out sequence. Here I am sending my proxy service.
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="Binaryformat"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<property name="messageType" value="application/json" scope="axis2"/>
<property name="ContentType" value="application/json" scope="axis2"/>
<log level="full">
<property name="M1" value="*************Callout PROXY*************"/>
</log>
<callout serviceURL="http://192.168.1.201:9769/services/emp_DataService/">
<source type="envelope"/>
<target key="response"/>
</callout>
<log level="full">
<property name="Status" expression="get-property('response')"/>
</log>
<header name="To" action="remove"/>
<property name="RESPONSE" value="true"/>
<!--<property name="OUT_ONLY" value="true"/>-->
<send/>
</inSequence>
<outSequence>
<log level="full">
<property name="Status" expression="get-property('response')"/>
</log>
<payloadFactory media-type="xml">
<format>
<response>outonly</response>
</format>
<args/>
</payloadFactory>
<property name="OUT_ONLY" value="true"/>
<send/>
</outSequence>
</target>
</proxy>
I think you have configured callout mediator wrongfully. Check for the callout mediator sample here
http://docs.wso2.org/display/ESB470/Sample+430%3A+Simple+Callout+Mediator+for+Synchronized+Web+Service+Invocation
As well as OUT-ONLY set to "true" mean on a message to indicate that no response message is expected for it once it is forwarded from the ESB. you can read more about OUT_ONLY and other properties from here http://docs.wso2.org/display/ESB470/Generic+Properties
callout mediator is synchronous, it will return the response in the same sequence (your inSequence, by doing a blocking call) : your outSequence is unnecessary.
however, you should add a faultSequence to log any error
you should use tcpmon (launch tcpmon in ESB_HOME/bin) between ESB and your endpoint to verify request content going to your service and verify if you obtain a response from your service.

Return property value as response in proxy service

I have a situation where in i have created a proxy service where in i have used an inline wsdl so that i can pass some data from try-it tool. After that i want to get the data passed from try-it to in seq that i am able to do.After that there is no use of inline-wsdl. In the "in-sequence" i have used a custom class mediator inside which i have set a property called "user" and i have saved that property value(user) in Property mediator. Now i want to send this property as response through out sequence.How to do this. Please help...
My Proxy code is:
<proxy xmlns="http://ws.apache.org/ns/synapse" name="ProviderPublication" transports="https,http" statistics="disable" trace="disable" startOnLoad="false">
<target>
<inSequence>
<property xmlns:xs="http://www.openandaway.org/xml/BBC/" name="URI" expression="//xs:SessionID" scope="default" type="STRING"/>
<payloadFactory>
<format>
<p:Session xmlns:p="http://www.openandaway.org/xml/BBC/">
<xs:ChannelURI xmlns:xs="http://www.openandaway.org/xml/BBC/">$1</xs:ChannelURI>
</p:Session>
</format>
<args>
<arg xmlns:ns="http://org.apache.synapse/xsd" expression="get-property('URI')"/>
</args>
</payloadFactory>
<log level="full">
<property name="Inside_In_Sequence" value="---------Hi i am inside in sequence--------------"/>
</log>
<log level="full">
<property name="PropValFromURI" expression="get-property('URI')"/>
</log>
</inSequence>
<outSequence>
<log level="full">
<property name="Inside_Out_Sequence" value="-------Hi inside Out Sequence--------------------"/>
</log>
<property name="GetDataFromINSeq" expression="get-property('URI')" scope="default" type="STRING"/>
<log level="full">
<property name="GetPropValueFromInSeq" expression="get-property('URI')"/>
</log>
<send/>
</outSequence>
</target>
<publishWSDL uri="http://10.224.188.87:2425/BBC1.0/services/BBCPublicationService?wsdl"/>
<description></description>
</proxy>
In the above code i am not able to get inside the out sequence. It is not hitting the out-sequence.Where am i doing wrong?
In your proxy's in-sequence, I dont see you sending the message to any backend. i.e. I dont see a send part in the in-sequence. Without the message going out, there is no way for a response to come to the out-sequence.
Regarding your original question on accessing properties set by your class mediator, if you set the property with the scope set to "synapse", you can access it within any place in your proxy.
You can access that property at the outsequence. Please refer following threads.
stWSO2ESB OutSequence Processing
Pass property from inSequence to outSequence

WSO2 ESB - transform a HTTP 202 accepted response

The Endpoint_BPS_CreateCaseService/UpdateCaseService endpoints below both point to one-way BPEL services running on WSO2 BPS. WSO2 BPS returns a HTTP 202 accepted message instantly when they are invoked.
The client application that I am using will throw a fault if it does not get a valid SOAP envelope as a response so I'm going to use a proxy service in ESB to wrap around the BPEL process.
How do I use a WSO2 ESB proxy service to forward a SOAP envelope to Endpoint_BPS_* below and then return a SOAP envelope response to my client app?
I also want to execute the faultSequence "ProcessFault" if either endpoint is unavailable or times out. I previously used the OUT_ONLY to get around the response issue above but it means I can't detect endpoint problems. Unless it is possible to do both somehow?
Another thing I've tried is cloning the message but this was a bit messy.
Any help greatly appreciated
<proxy xmlns="http://ws.apache.org/ns/synapse" name="BPSProxyService" transports="https,http" statistics="disable" trace="enable" startOnLoad="true">
<target faultSequence="ProcessFault">
<inSequence>
<log level="full">
<property name="MESSAGE" value="BEGIN BPSProxyService" />
</log>
<switch source="//*[local-name()='Operation']">
<case regex="create">
<send>
<endpoint key="Endpoint_BPS_CreateCaseService" />
</send>
</case>
<case regex="update">
<send>
<endpoint key="Endpoint_BPS_UpdateCaseService" />
</send>
</case>
</switch>
</inSequence>
<outSequence>
<property name="HTTP_SC" value="200" scope="axis2" />
<class name="esb.mediators.InjectSOAPEnvelope" />
<log level="full">
<property name="MESSAGE" value="END BPSProxyService" />
</log>
<send />
<drop />
</outSequence>
</target>
<publishWSDL key="common/bpsproxyservice/bpsproxyservice.wsdl">
<resource location="schema.xsd" key="common/schema_v2.xsd" />
</publishWSDL>
</proxy>
When you receive a 'HTTP/1.1 202 Accepted' response from your backend like BPS in the outSequence of your Proxy Service, then you need the <property name="SC_ACCEPTED" value="false" scope="axis2"/> statement to modify the '202'-response into something else.
Example:
<property name="SC_ACCEPTED" value="false" scope="axis2"/>
<property name="HTTP_SC" value="200" scope="axis2"/>
<payloadFactory media-type="xml">
<format>
<response>
<result>OK</result>
</response>
</format>
<args/>
</payloadFactory>
<send/>
The response is transformed into 'HTTP/1.1 200 OK' with a response message.
Add the "FORCE_SC_ACCEPTED" parameter with the "OUT_ONLY" in the inSequence of the proxy service as follows.
<property name="FORCE_SC_ACCEPTED" value="true" scope="axis2" type="STRING"/>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
For more information use the following article:
http://mohanadarshan.wordpress.com/2013/05/05/out_only-scenario-in-proxy-service-wso2-esb/

WSO2 ESB If Then Else, authenticate or Error

This may be a basic question, I am just getting used to the WSO2 lingo. I have two services that I can deploy independently with WSDLs and pass the proper SOAP request, and return information accordingly. Now I want to combine them into an 'If then, else' statement sort of deal. This would be set up in a sequence of some sort I believe, just not sure how with the filters.
Send in request with authentication request and info request
Do authentication request – continue if passes, 401 on failure
Do info request – get info
Return the info
If you have a sample I could follow or point me to one of the hundreds WSO2 has, I just haven't been able to pull much from them. XML source example for the config could work also. Thanks for the help, and for my ignorance of WSO2 lingo, and workflow.
You can have a look at filter mediator to filter messages based on conditions Entitlement Mediator. You can find samples here as a reference which will be helpful for your use case.
So I ended up with something very similar to this. If someone down the road comes across this and looking for the wso2 configurations.
<proxy name="name"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<property xmlns:ns1="ns1"
xmlns:ns="ns"
name="userID"
expression="//ns:AuthenticateRequest/ns:Credentials/ns1:userID"
scope="default"
type="STRING"/>
<property xmlns:ns1="ns1"
xmlns:ns="ns1"
name="password"
expression="//ns:AuthenticateRequest/ns:Credentials/ns1:password"
scope="default"
type="STRING"/>
<log>
<property name="userID" expression="get-property('userID')"/>
<property name="password" expression="get-property('password')"/>
</log>
<header name="Action"
value="http://services.com:port/AuthenticateSecureCredential"/>
<send receive="AuthRecvSequence">
<endpoint>
<address uri="http://server.com:port/DefaultAuthenticationService"/>
</endpoint>
</send>
</inSequence>
</target>
</proxy>
<sequence name="AuthRecvSequence">
<filter xmlns:ns="ns"
source="//ns:AuthenticateSecureCredentialResponse/ns:isAuthenticated"
regex="false">
<then>
<makefault version="soap11">
<code xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/"
value="soap11Env:VersionMismatch"/>
<reason value="Not Authenticated"/>
<role/>
</makefault>
<header name="To" action="remove"/>
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
<send/>
<drop/>
</then>
<else>
<payloadFactory>
<format>
<ns:INFO xmlns:ns="ns"
xmlns:ns1="ns1">
<ns:secureCredentials>
<ns1:userID>$1</ns1:userID>
<ns1:password>$2</ns1:password>
</ns:secureCredentials>
</ns:INFORequest>
</format>
<args>
<arg expression="get-property('userID')"/>
<arg expression="get-property('password')"/>
</args>
</payloadFactory>
<header name="Action"
value="http://services.com/GetINFO"/>
<send receive="INFOrRecvSeq">
<endpoint>
<address uri="http://server:port/INFOService"/>
</endpoint>
</send>
</else>
</filter>
</sequence>
<sequence name="INFORecvSeq">
<send/>
</sequence>
<sequence name="main">
<description>The main sequence for the message mediation</description>
</sequence>