I would like to find out the best way to parse responses using oasis xsd. I have the following response xml string but am not sure how to parse it, i tried copying the xsd from oasis but it fails to create jaxb objects. This is the xml response data:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-521833581">
<wsu:Created>2017-09-07T00:00:02.002Z</wsu:Created>
</wsu:Timestamp>
</wsse:Security>
</soap:Header>
<soap:Body>
<soap:Fault xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:c="urn:schemas-visa-com:transaction-data-1.0">
<faultcode>wsse:FailedCheck</faultcode>
<faultstring>
Security Data : UsernameToken authentication failed.
</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
Found a simple solution, not implemented this way ofcource, just an illustration:
SOAPBody body = soapResponse.getSOAPBody();
if(body.hasFault()){
LOG.debug("HAS LOG FAULT, LETS SEE WHAT ELSE...");
LOG.debug("getFaultCode" + body.getFault().getFaultCode());
LOG.debug("getFaultString" + body.getFault().getFaultString());
}
Related
Can i send xml payload as a string to soap web service ? Is it allowed to use any http client library (Apache HttpClient, RxNetty) for the same or should i only use SAAJ framework (http://stackoverflow.com/questions/15948927/working-soap-client-example) ?
E.g.,
curl --header "Content-Type: text/xml;charset=UTF-8"
--header "SOAPAction:http://www.webserviceX.NET/ConversionRate"
--data #request3.xml http://www.webservicex.net/CurrencyConvertor.asmx
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ConversionRate xmlns="http://www.webserviceX.NET/">
<FromCurrency>USD</FromCurrency>
<ToCurrency>GBP</ToCurrency>
</ConversionRate>
</soap:Body>
</soap:Envelope>
Yes, it is perfectly possible, in fact, under the hood, that's what happens when you call a SOAP based web service _action located at _url URI:
XmlDocument soapEnvelop = new XmlDocument();
soapEnvelop.LoadXml(#"<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ConversionRate xmlns="http://www.webserviceX.NET/">
<FromCurrency>USD</FromCurrency>
<ToCurrency>GBP</ToCurrency>
</ConversionRate>
</soap:Body>
</soap:Envelope>");
HttpWebRequest webRequest = CreateWebRequest(_url, _action);
using (Stream stream = webRequest.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
Now your request, loaded with your SOAP envelop is ready to be expedited!
<soap:Envelope xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsrl="http://docs.oasis-open.org/wsrf/rl-2" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:ns1="http://workflow.comarch.com/SDService_ws" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsrp="http://docs.oasis-open.org/wsrf/rp-2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://www.w3.org/2005/08/addressing">
<soap:Body wsu:Id="myBody-1491835424">
<ns1:listProcessesResponse>
<listProcessesReturn xsi:nil="true" xsi:type="tns:listProcessesReturn"/>
</ns1:listProcessesResponse>
</soap:Body>
</soap:Envelope>
What is wrong with that SOAP response? I'm using SoapUI to verify SOAP Answers. It checks if received response is compatible with WSDL standards. So when I run validation in SoapUI it produces the following error.
java.lang.String cannot be cast to org.apache.xmlbeans.XmlError
The message itself looks like a bug in SoapUI's error handling
What is wrong with that SOAP response?
Your schemaLocation is wrong
xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/ http://schemas.xmlsoap.org/soap/envelope/"
you have the same URI in there twice
Also, you are using the namespace tns without having defined it in
xsi:type="tns:listProcessesReturn"
I have the following issue with CXF version 2.7.7-redhat-1, that seems like a bug in the library.
With the following request:
<?xml version="1.0" encoding="utf-8"?>
<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>
<authorizePayment xmlns="http://ejb.example.org">
<request xmlns="">
<role xmlns:q1="http://to.homepay.example.org" xsi:type="q1:CustomerTO">
<user>7C742</user>
</role>
<error>
<errorCode>1</errorCode>
<errorMessage>1</errorMessage>
</error>
<status>
<code>1</code>
</status>
<ordAccount>1</ordAccount>
<logId>374216011815223570893830967949</logId>
<signMethod>1</signMethod>
<lang>1</lang>
<terminalId>1</terminalId>
<terminalLocation>Earth</terminalLocation>
</request>
</authorizePayment>
</soap:Body>
</soap:Envelope>
I get the following error:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Unmarshalling Error: unexpected element (uri:"http://ejb.example.org", local:"request"). Expected elements are <{}request></faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
From the request you can clearly see that the namespace of the request is "" overridden from its parent.
If I change the request to:
<?xml version="1.0" encoding="utf-8"?>
<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>
<aa:authorizePayment xmlns:aa="http://ejb.example.org">
<request xmlns="">
<role xmlns:q1="http://to.homepay.example.org" xsi:type="q1:CustomerTO">
<user>7C742</user>
</role>
<error>
<errorCode>1</errorCode>
<errorMessage>1</errorMessage>
</error>
<status>
<code>1</code>
</status>
<ordAccount>1</ordAccount>
<logId>374216011815223570893830967949</logId>
<signMethod>1</signMethod>
<lang>1</lang>
<terminalId>1</terminalId>
<terminalLocation>Earth</terminalLocation>
</request>
</aa:authorizePayment>
</soap:Body>
</soap:Envelope>
The call works. I need a way to fix this issue server side, the client can't be modified to change the request.
Versions:
JBoss AS release: 7.3.4.Final-redhat-1 "Janus"
JBoss AS product: EAP 6.2.4.GA
java.version: 1.7.0_91
Set the elementFormDefault=qualified in the wsdl, generate the artifacts and redeploy the application.
Qualified means that local element declarations (xs:element within xs:complexType) refers to elements in the target namespace of the schema. Without it, they refer to elements in no namespace.
I'm using JAXB to generate a soap xml request. The current xml output that i want is this
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:rgw="http:/blablablablabla.org"
xmlns:typ="http://blablablablabla.org/bla/bla">
<soapenv:Header>
<wsse:Security
soapenv:mustUnderstand="1"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="testToken-13">
<wsse:Username>blbalbalL</wsse:Username>
<wsse:Password
Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">1234r</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
</soapenv:Body>
</soapenv:Envelope>
Until now i have generate the Envelope and Header tag but i have trouble with the Security tag.
My problem is if i try to set the xmlns to package-info.class the prefix is correct but the xmlns:wsse="blbalbla" and the xmlns:wsu="http://balbla.com" going to the root element(envelope) and not into the security tag. Here is the output that i get:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:rgw="http://gr/gsis/rgwsalldata/RgWsAllData.wsdl"
xmlns:typ="http://gr/gsis/rgwsalldata/RgWsAllData.wsdl/types/"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<soapenv:Header>
<wsse:Security/>
</soapenv:Header>
<soapenv:Body/>
As you can see in the desire xml output the xmlns:wsse and xmlns:wsu namespaces are at the security tag. how can i these xmlns to security tag? and how can the UsernameToken tag should build?
package-info.class
#XmlSchema(
namespace = "http://schemas.xmlsoap.org/soap/envelope/",
xmlns = { #XmlNs(prefix="soapenv", namespaceURI="http://schemas.xmlsoap.org/soap/envelope/"),
#XmlNs(prefix="rgw", namespaceURI="http://blabalbalbal.org"),
#XmlNs(prefix="typ", namespaceURI="blablaba/types/"),
#XmlNs(prefix="wsse", namespaceURI="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"),
#XmlNs(prefix="wsu", namespaceURI="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd")},
elementFormDefault = XmlNsForm.QUALIFIED)
package broker.jaxb.xmlrequest;
import javax.xml.bind.annotation.*;
You can use #XmlType(namespace="http://docs.oasis-open.org/wss") (or XMLRoot) on top of Security class instead of declaring the namespace in package-info it should bring the namespace down to the Security tag.
As mentioned in the comment both documents are equivalent xml, so first test if the soap message works as it is. No point in reproducing the exact format if the other side can read this one as well (any decent modern WS framework will do).
Is there any way to get a particular field value in a SoapMessage which is built from an XML file.
Here is my incoming soap message,
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
<wsa:Action xmlns:wsa="http://www.w3.org/2005/08/addressing">http://www.example.com</wsa:Action>
<wsa:MessageID xmlns:wsa="http://www.w3.org/2005/08/addressing">8d6f49b9-22c6-41d9-a1fb-bc07c82pbhar</wsa:MessageID>
<wsa:From xmlns:wsa="http://www.w3.org/2005/08/addressing">
<Address xmlns="http://www.w3.org/2005/08/addressing">http://bcd.com</Address>
</wsa:From>
<wsa:ReplyTo xmlns:wsa="http://www.w3.org/2005/08/addressing">
<Address xmlns="http://www.w3.org/2005/08/addressing">http://blah.com</Address>
</wsa:ReplyTo>
<wsa:To xmlns:wsa="http://www.w3.org/2005/08/addressing">https://blah2.com</wsa:To>
</soap:Header>
<soap:Body wsu:Id="id-8" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<ns2:abc xmlns:ns2="abc" xmlns:ns3="abc" xmlns:ns4="abc">
<ns2:FunctionCallIdentifier>https://bcd.com</ns2:FunctionCallIdentifier>
<ns2:ValidityPeriod>120000</ns2:ValidityPeriod>
<ns2:fieldOne>
<ns2:Subfield xsi:type="ns2:MSId_AliasType" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns2:property1>IWantToGetThis</ns2:property1>
</ns2:Subfield>
</ns2:abc>
</soap:Body>
</soap:Envelope>
Now, I want to get the "property1" file, how do I do that, all I can see is getHeaders(), getContextualProperty(),etc, etc
Thanks!
Maybe this link can help you:
How to parse SOAP message into Jaxb classes
Jaxb is framework for processing XML documents, as sopa body is a XML, you can process it with Jaxb