Reading web service response using ColdFusion - web-services

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

Related

Getting Soap Fault on hitting a WebService using JMETER

I'm trying to contact a webservice via Jmeter (3.0), and I get the following error:
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Body>
<s:Fault>
<s:Code>
<s:Value>s:Sender</s:Value>
<s:Subcode>
<s:Value xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:ActionNotSupported</s:Value>
</s:Subcode>
</s:Code>
<s:Reason>
<s:Text xml:lang="es-AR">The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).</s:Text>
</s:Reason>
</s:Fault>
</s:Body>
</s:Envelope>
I haven't encountered any issues contacting the web service from SoapUI, so I'm wondering what could cause this problem.
You can see the screen shots here:
The HTTP Request within the tree, first part of the HTTP Request data, the HTTP Header Manager settings: https://i.stack.imgur.com/6HxIK.jpg
Here are the results on SoapUI (works just fine):
Results and log
Is it possible that the way that SoapUI sends the requests differs from the way Jmeter does and that's why it works?
Please help. Thanks!
You need to put this action bit to be a part of the Content-Type header like:
I would also recommend adding HTTP Cookie Manager to your Test Plan
Out of interest, why don't you just record the request originated from SoapUI using JMeter HTTP(S) Test Script Recorder like:
Configure JMeter for recording. The easiest way of doing this is using JMeter Templates feature
From JMeter main menu: File - Templates - Recording - Create
Workbench - HTTP(S) Test Script Recorder - Start
Configure SoapUI for recording
From SoapUI main menu: Preferences - Proxy Settings
Proxy Settting: manual, host: IP address or hostname of machine where JMeter is running, port: 8888
Execute request in SoapUI
Inspect the recorded request in JMeter under Workbench -> Recording Controller.
I think you have some trivial error in the value of http header SOAPAction.
Happened to notice(in the image you attached) that there are double quotes in its value.
Just remove the double quotes " from the SOAPAction value.
UPDATE:
It is noticed, while editing the question, that soapui has sent an additional http header action with a value (you masked the value).
So, please add action header in the jmeter request as well the right value in the jmeter plan.

use soap services to get information

I'm new in learning Web services.
I was trying to use soap services to get a city weather from a website.
Here is the website
http://www.bom.gov.au/australia/majorcities.shtml?ref=hdr
I want to get the weather of Broome City on Friday.
While articulating my self doing this I came across two terms: EndPoint and SOAP Action
Can anyone please help me to understand these two terms ?
Is EndPoint is the URL from where I want to get information ?
SOAP Action ? What's this, why we use this and how we can use this ?
The only thing I know about SOAP services is It sends the request in xml format to server and response also comes up in xml format.(Might be am wrong)
Thanks in Advance !! :)
If you are starting fresh on web-services, I would recommend building REST service instead of soap service. That would be easier to start with.
If you go for REST service, your url would be:
http://serverxyz.com/{city}/{day}
Coming back to your questions:
EndPoint is the URL from where I want to get information ? - Correct
One web service usually has many operations which are called soap
action/soap method. Here is sample SOAP request from w3school which is also called
SOAP envelope:
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Body>
<m:GetPrice xmlns:m="http://www.w3schools.com/prices">
<m:Item>Apples</m:Item>
</m:GetPrice>
</soap:Body>
</soap:Envelope>

wso2 esb: Construct one message from multiple web service calls

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.

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.

SOAP web-service - fake a server side error?

my iphone app is using soap web-services. I want to know how it would behave if the web-service returns a soap error?
I am using charles (HTTP Proxy) to catch the responses and modify the response before sending it to my iPhone app. What I'm trying to do is to modify a successful soap response, and turn it into a soap fault to see how my application behave.
QUESTION: How does a SOAP error response look like? (With restful all i had to do was to change the responseCode to 504, how can I achieve this with SOAP)?
How does a SOAP error response look like?
Here's an example of how a failed SOAP response might look like:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header />
<s:Body>
<s:Fault>
<faultcode>s:Client</faultcode>
<faultstring xml:lang="en-US">The creator of this fault did not specify a Reason.</faultstring>
<detail>
<MyFault xmlns="http://schemas.datacontract.org/2004/07/ToDD" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<MyProperty>some value</MyProperty>
</MyFault>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
As you can see there's a special <Fault> node in the body of the SOAP response which could contain any XML describing the SOAP fault. The custom XML should be in the <detail> child node.