wso2 esb: Construct one message from multiple web service calls - web-services

I have a number of web services each returning a list of user ids as follows:
<application name="abc">
<users>
<id>123</id>
<id>456</id>
<id>789</id>
</users>
</application>
I need to be able to
Call a proxy service with a specific id (for example 123);
Call each webservice and search for the ID;
Create a response for each webservice and finally
Aggregate all responses in one message which is sent to the client as follows:
<response>
<id>123</id>
<application name="abc">
found
</application>
<application name="lmn">
not found
</application>
<application name="xyz">
found
</application>
</response>
Its probably a mix of service chaining and aggregate, but I cannot figure out how to do it. I tried cloning a request and using send at the end with a receiving sequence which transforms the body using the payload factory. In the Out sequence I then used aggregate to combine the new messages. However it times out and I don't think it's a matter of timing. My main issue is how to create a new message from each webservice response the aggregate mediator can combine them.
Any help is appreciated.
Thanks

You need to follow this pattern, https://docs.wso2.com/display/IntegrationPatterns/Scatter-Gather and you are almost there. When you define receive sequence the response will be forwareded to that sequence and you wouldn't get the response message in outSequence. Use aggregator mediator inside the outSequence and Combine the responses rather than defining a receive sequence.
Once you aggregate the responses, you can use xslt mediator to transform the message.

I managed to solve my issue by creating a proxy service for each web servive. Each proxy service calls the actual web services and uses a filter in the out sequence to create a response likes this:
<application name="abc">
found
</application>
Then I created a REST API which takes the idno as a URI template. I then prepare a payload with this idno and clone the request to the proxy services I mentioned above. Then I aggregate the responses and add the idno in the payload.
If anybody has any questions let me know.

Related

Filter payload that passes to the transformer in Webservice Proxy pattern in Mule ESB

When using a web service proxy pattern in Mule, you have the ability to pass the message through 1 or more transformers. Is there anyway to avoid passing ?Wsdl gets or other messages filtered on Content-Type for example? My transformer is manipulating the XML payload prior to passing it off to the web service, but I've found my wsdl calls are also being processed by the transformer and failing.
I've put a check in my transformer code, but this doesn't seem like the right way to go about solving this.
if(message.getOriginalPayload().toString().endsWith("wsdl")||!(xmlString.startsWith("<") && xmlString.endsWith(">"))){return message; }
The Proxy config:
<pattern:web-service-proxy name="SR-Proxy"
doc:name="SR-Proxy"
transformer-refs="enrichPayloadWithSFSession"
wsdlFile="service/SR_Webservice.wsdl">
<http:inbound-endpoint exchange-pattern="request-response" host="${hostname}" port="${http.port}" path="service/SRProxy" doc:name="HTTP" />
<https:outbound-endpoint exchange-pattern="request-response" address="${sfdc.wsUrl}SR_Webservice" />
</pattern:web-service-proxy>
Use the http.query.string inbound message property to detect the ?wsdl request.
See http://www.mulesoft.org/documentation/display/current/HTTP+Transport+Reference#HTTPTransportReference-HTTPProperties for more information about the available inbound properties you can find in inbound HTTP messages.

Can A Header Be Added & Body Modified In A Salesforce SOAP Response?

From doing some testing on SOAP requests to a webservice I created in Salesforce I note the response returned is of the following format.
Note my request function I called is GetMsgRQ
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://soap.sforce.com/schemas/class/MyIntegrationServices">
<soapenv:Body>
<GetMsgRQResponse>
<result>
<acctId>001J000000leVpEIAU</acctId>
<acctName>MyTest</acctName>
</result>
</lGetMsgRQResponse>
</soapenv:Body>
</soapenv:Envelope>
Relating to this I wonder is it possible to add a SOAP:Header?
Also I note the response has created an element "GetMsgRQResponse" (adding "Response" to "GetMsgRQ". Is it possible to create/specify the SOAP:Body without this occuring? Can I just set what the whole SOAP body response will be or will Salesforce always add such additional elements as the "GetMsgRQResponse" here and "result"?
Thanks in advance for any help on this. I know I can use a HTTP Request to send a full SOAP envelope but for my requirement I need to just provide a response instead of doing so.
I don't believe you can directly add any kind SOAP headers in an Apex defined WebService methods.
If you have absolutely no other option you could construct your own custom SOAP response via a REST web service (via #RestResource annotation) but that is a pretty ugly solution.

Reading web service response using ColdFusion

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header>
<WSResponseHeader xmlns="http://cio.xxx.com/commonheader/v3" xmlns:ns2="http://newhorizon.xxx.com/ABCservice">
<WSCorrelationId>?</WSCorrelationId>
</WSResponseHeader>
</S:Header>
<S:Body>
<ns2:newOrderResponse xmlns="http://cio.XXX.com/commonheader/v3" xmlns:ns2="http://newhorizon.XXXX.com/ABCservice">
<ns2:ABCOrderResponse>
<ns2:headerStatus>ERROR</ns2:headerStatus>
<ns2:lineResponse>
<ns2:sourceSystemRefLineNum>1</ns2:sourceSystemRefLineNum>
<ns2:lineStatus>ERROR</ns2:lineStatus>
<ns2:lineError>
<ns2:errorCode>122</ns2:errorCode>
<ns2:errorMessage>Billing Category Code is required. </ns2:errorMessage>
</ns2:lineError>
</ns2:lineResponse>
</ns2:ABCOrderResponse>
</ns2:newOrderResponse>
</S:Body>
</S:Envelope>
I have a soap web service code in ColdFusion which invokes an external web service and my app will pass some rows to it. The above is the format of response that the application will send back. There can be multiple <ns2:lineResponse> type blocks. Some blocks will have error tags, some may have success tags.
How can I iterate through this response to extract details from error tag blocks only?
When I try to make loops, it is counting <ns2:headerStatus>ERROR</ns2:headerStatus> also as child node.

Adding a header to a XML message in Synapse

Using Synapse 2.1, I am trying to transform an XML message with no header into a SOAP message with a header containing credentials to consume a web service. Something like this:
Synapse incoming message:
<SOAP-ENV:Envelope>
<SOAP-ENV:Body>
...TAGS...
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Synapse outgoing message:
<SOAP-ENV:Envelope>
<SOAP-ENV:Header>
<yta:Authentication>
<yta:UserName>srnm</yta:UserName>
<yta:Password>psswrd</yta:Password>
</yta:Authentication>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
...TAGS...
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
How could I configure Synapse to do it? I am successfully using a transform file to update the body of the message, but not to add a header to the output.
I tried using the header and property mediators in the configuration file, but I am not sure what is the way to go. Reading about the header mediator it says "At the moment set header only supports simple valued headers". Could this be the case?
Thanks
For the record, I ended up using a script mediator with an inline javascript script in the configuration file using the addHeader method. See below:
<script language="js">
<![CDATA[
var user = mc.getPayloadXML()..*::UserName.toString();
var psswd = mc.getPayloadXML()..*::Password.toString();
mc.addHeader(false, <yta:Authentication xmlns:yta="yta:namespace url"><yta:UserName>{user}</yta:UserName><yta:Password>{psswd}</yta:Password></yta:Authentication>);
]]>
</script>
You can use XSLT mediator to manipulate it. So add an XSLT transformation with required headers and it would add required headers. Or use Script mediator / Class mediator where you can manipulate message.
Please refer followings which will be useful.
http://wso2.org/forum/thread/10794
http://wso2.org/forum/thread/10843
If this xml structure is not needed.
you can use Http Headers you can use properties as below.
http://blog.thilinamb.com/2011/04/how-to-access-web-service-using-http.html
Looks like you want to secure the service. The easiest then, is to use username-token security. Go to the services dashboard in WSO2 ESB for your proxy service and secure it, using UT. Also see http://docs.wso2.org/wiki/display/ESB460/Sample+200%3A+Using+WS-Security+with+policy+attachments+for+proxy+services for a security sample

WSO2 ESB - How to build soapenv:Body for remote service call

I have the WSDL file of the remote web service I need to call from a proxy service in the WSO2 ESB and would like to know if I need to construct the soap:Body's elements manually through XSLT/Enrich or there is a way to generate the soapenv:Body's contains from the WSDL and maybe replace '?' for the values.
For example, if you've used soapUI before you'll know that when you import a WSDL file in a project a soapenv:Envelope gets generated automatically with all the XML elements and question marks for their values. Same goes for the TryIt tool in the WSO2 ESB.
Here is an example of an auto-generated soapenv:Envelope in soapUI after importing WSDL:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:abc="http://abc.com/">
<soapenv:Header/>
<soapenv:Body>
<abc:RegisterCandidate>
<abc:NameFirst>?</abc:NameFirst>
<abc:NameMiddle>?</abc:NameMiddle>
<abc:NameLast>?</abc:NameLast>
<abc:PhoneHome>?</abc:PhoneHome>
<abc:EmailAddress>?</abc:EmailAddress>
<abc:Address1>?</abc:Address1>
<abc:Address2>?</abc:Address2>
<abc:City>?</abc:City>
<abc:State>?</abc:State>
<abc:ZipCode>?</abc:ZipCode>
<abc:Country>?</abc:Country>
</abc:RegisterCandidate>
</soapenv:Body>
</soapenv:Envelope>
Is this possible in the Proxy Service through any of the mediators available to read a WSDL and generate soapenv:Body with its XML tags (in the code above it would be abc:RegisterCandidate with its children)? I've done it with the use of the XSL templates, but it's manual and not very elegant.
I've found a few articles/blogs online about writing proxy services in the WSO2 ESB that call remote web services and what the developers were doing in there was to insert the XML elements needed in the soapenv:Body with the use of XSL templates to have the correct/full SOAP message that is then sent (send mediator) to the remote web service server.
Thank you.
There is no way to generate the soap body from the remote service's wsdl as in your requirement. But there is an easier way than using xslt. That is to use the payload factory mediator. You can define the payload and assign values using xpath as shown in the sample.