javax.xml.soap.SOAPException: InputStream does not represent a valid SOAP 1.1 Message - soap

I am consuming a SOAP API. The XML response I receive is surrounded with a 'soap envelope' - so I need to remove or parse past that wrapper before I can process the XML. I've taken the below approach with other endpoints (so the code is sane, at least) but with this particular endpoint, I get errors.
The error I'm encountering is:
SEVERE: SAAJ0304: InputStream does not represent a valid SOAP 1.1
Message
This is the code I am using to remove the Soap Wrapper:
String soapResponse = getSoapResponseFromApi();
ByteArrayInputStream inputStream = new ByteArrayInputStream(soapResponse.getBytes());
SOAPMessage message = MessageFactory.newInstance().createMessage(null, inputStream);
Document doc = message.getSOAPBody().extractContentAsDocument(); // <-- error thrown here
//unmarhsall the XML in 'doc' into an object
//do useful stuff with that object
here is the XML I am receiving back (the contents of soapResponse in the code above)
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<XMLContentIActuallyWant xmlns="http://my-url.com/webservices/">
<!-- Useful stuff here -->
</XMLContentIActuallyWant >
</soap:Body>
</soap:Envelope>

I discovered the solution as I was preparing this question.
Soap versions have different formatting. The SoapMessage library was defaulting to soap 1.1 - but the contents of the response I was receiving was soap 1.2.
I could see this when I inspected the full request that was being sent, in order to receive the response noted above - it looked like this:
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<!-- xml content here -->
</soap12:Body>
</soap12:Envelope>
the soap12 part highlights that it is requesting soap 1.2.
so although the response doesn't contain the '12' - the response is also in 1.2.
So we need to tell SoapMessage to use 1.2 instead of the default (1.1 in my case).
I did this by modifying my code above like so:
Before:
SOAPMessage message = MessageFactory.newInstance().createMessage(null, inputStream);
After:
SOAPMessage message = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage(null, inputStream);
It's worth noting that other endpoints of the same API served SOAP 1.1 - which is why this error was so confusing for me. I was doing the same thing and getting different results.

Related

Return SOAP response using WSO2 when invoking an API

I have created an API using the WSO2 Dataservice which return a JSON Object, My client Application waiting for a SOAP response not a JSON response, so I tried to use datamapper to change the response format from JSON to SOAP but it return only and XML format without the SOAP Body and the SOAP envelope. How to hundle this problem?
This is the SOAP response format I would like to get:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetFacturesClientResponse xmlns="http://tempuri.org/">
<GetFacturesClientResult>
<code>0</code>
<codeClient>P-2008-043681</codeClient>
<nom>na</nom>
<prenom>ouss</prenom>
</GetFacturesClientResult>
</GetFacturesClientResponse>
</soap:Body>
</soap:Envelope>
But I got this response:
<GetFacturesClientResponse xmlns="http://tempuri.org/">
<GetFacturesClientResult>
<code>0</code>
<codeClient>P-2008-043681</codeClient>
<nom>na</nom>
<prenom>ouss</prenom>
</GetFacturesClientResult>
</GetFacturesClientResponse>
And this is my code:
<datamapper config="gov:datamapper/oussama.dmc" inputSchema="gov:datamapper/oussama_inputSchema.json" inputType="JSON" outputSchema="gov:datamapper/oussama_outputSchema.json" outputType="JSON" xsltStyleSheet="gov:datamapper/oussama_xsltStyleSheet.xml"/>
Before the Respond Mediator set the following property.
<property name="messageType" value="application/soap+xml" scope="axis2"/>
Also in your Datamapper section the outputType="XML" not JSON.
Update
As ophychius mentioned. The above content type will create a SOAP 1.2 message and if you need a SOAP 1.1 message set the content type to text/xml. Typically, clients supports both versions.

Get data from xml response in Jmeter

Hi Everyone!
I would like to get status from this response from Jmeter.How can i create regexp for that?
I just want to get 'vacant' from response
<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns5:GetRandomMSISDNListResponse xmlns:ns2="http://www.trump.com/products/common/core" xmlns:ns3="http://www.trump.com/products/common/rr" xmlns:ns4="http://www.yota224.com/vux/domains/common/core" xmlns:ns5="http://www.yota224.com/vux/services/inventory">
<ns2:extension>
<ns2:item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:RequestContextType">
<ns2:correlationId>8f7ce7e1-31ae-40fe-82ba-4d59f634e599</ns2:correlationId>
</ns2:item>
</ns2:extension>
<msisdnList>
<homeRegion>1078</homeRegion>
<msisdn>9992146221</msisdn>
<status>vacant</status>
</msisdnList>
</ns5:GetRandomMSISDNListResponse>
</soap:Body>
</soap:Envelope>
If you targeting to do it via Regular Expressions - the relevant one would be something like:
<status>(\w+)</status>
Here is how it looks in the "RegExp Tester" mode of the View Results Tree listener
Also it might be easier to use XPath Extractor which is designed for working with XML data. In that case the relevant XPath query to get the status will be as simple as:
//status

Parsing XML (SOAP Response) through NetSuite Script

In Netsuite Script I am trying to parse the response from EchoSign Webservice. The response from EchoSign is like this
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<getFormDataResponse xmlns="http://api.echosign">
<getFormDataResult xmlns="http://api.echosign">
<errorCode xmlns="http://dto8.api.echosign">OK</errorCode>
<errorMessage xmlns="http://dto8.api.echosign" xsi:nil="true" />
<formDataCsv xmlns="http://dto8.api.echosign">SOME DATA </formDataCsv>
<success xmlns="http://dto8.api.echosign">true</success>
</getFormDataResult>
</getFormDataResponse>
</soap:Body>
</soap:Envelope>
And my NetSuite code is here
var response = nlapiRequestURL(echoSignUrl, postStr, header);
var xml = nlapiStringToXML(response.getBody());
var resData = nlapiSelectNode(xml, 'soap:Envelope/soap:Body'); // /getFormDataResult/success');
if (resData)
return nlapiSelectValue(resData, 'formDataCsv');
But somehow I always get nothing back from nlapiSelectValue method!!
Nodes without any prefix should be accessed using default prefix nlapi:
for e.g. /soap:Envelope/soap:Body/nlapi:getFormDataResponse
It appears to be an issue with the way the namespacing is handled. Using the XML Tools plugin for Notepad++ and the XML you've provided, the XPATH Current Node Selector can't even find the getFormDataResponse node correctly. It simply fails with "Unknown Exception".
I also tried to manually evaluate the following expressions:
/soap:Envelope/soap:Body (works)
/soap:Envelope/soap:Body/getFormDataResponse (fails)
/soap:Envelope/soap:Body//getFormDataResponse (fails)
/soap:Envelope/soap:Body/*[local-name() = 'getFormDataResponse'] (fails)
/soap:Envelope/soap:Body/descendants::*[local-name() = 'getFormDataResponse'] (fails)
/soap:Envelope/soap:Body/descendants::getFormDataResponse (fails)
If I modify the XML so the EchoSign namespaces are in the Envelope with a prefix, like so:
<soap:Envelope xmlns:echo="http://api.echosign" xmlns:dto8="http://dto8.api.echosign" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<echo:getFormDataResponse>
<echo:getFormDataResult>
<dto8:errorCode>OK</dto8:errorCode>
<dto8:errorMessage xsi:nil="true" />
<dto8:formDataCsv>SOME DATA</dto8:formDataCsv>
<dto8:success>true</dto8:success>
</echo:getFormDataResult>
</echo:getFormDataResponse>
</soap:Body>
</soap:Envelope>
then the path selector can get all the way down to the formDataCsv node correctly. It returns the path: /soap:Envelope/soap:Body/echo:getFormDataResponse/echo:getFormDataResult/dto8:formDataCsv.
Not sure how helpful that is because you're not in control of the XML that EchoSign sends to you, but I'm not sure how to correctly format the XPATH to deal with the namespaces.

Parsing soap response from asp

I have a soap request returning a response like below:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:authkeyResponse xmlns:ns1="urn:authkey">
<return xsi:type="xsd:string">ALREADY REGISTERED</return>
</ns1:authkeyResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I am invoking the soap using vb script by following the example from http://kapie.com/2007/consuming-soap-web-services-from-vbscript. I get this whole xml in the strSoapReq object but not sure how to parse it so that I can popup only the result which is "ALREADY REGISTERED".
From the example from the link you gave, make sure you call GetResult explicitly.
If you followed the example and based on your SOAP result, it should be:
GetResult(strResult, "result")

iphone xml parsing error

Hello all in my iphone application after sending login xml request am getting following faulted xml... but i cant understand what the error is...
<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body><SOAP-ENV:Fault><faultcode xsi:type="xsd:string">SOAP-ENV:Client</faultcode><faultactor xsi:type="xsd:string"></faultactor><faultstring xsi:type="xsd:string">error in msg parsing:
Charset from HTTP Content-Type &apos;UTF-8&apos; does not match encoding from XML declaration &apos;ISO-8859-1&apos;</faultstring><detail xsi:type="xsd:string"></detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
Well, the error message is saying that you tried to parse a document where the document header said it was encoded in ISO 8859/1, while the HTTP header said it was in UTF-8. Parsers are allowed to resolve that conflict by giving the HTTP header precedence, but it seems this parser chose not to. The inconsistency means there's some kind of configuration problem and it needs to be investigated.