Received non-all-whitespace CHARACTERS or CDATA event in nextTag - soap

I am using web service consumer(1.6.9) in Mule4 and triggering the external soap service, the external service is returning SOAP FAULT and below is the SOAP fault which I am getting as below
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<soapenv:Body>
<soapenv:Fault>
<faultcode>Internal Server Error</faultcode>
<faultstring>Unexpected close tag
</urn:UniqueName>; expected
</urn:UniqueNam>
at [row,col {unknown-source}]: [40,54]
</faultstring>
<Detail>Invalid incoming request /Buyer/soap/C133/X-T/testPull?null</Detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
but Web service consumer in mule is returning the below error:
Caused by: com.ctc.wstx.exc.WstxParsingException: Received non-all-whitespace CHARACTERS or CDATA event in nextTag()
Please let me know what is the issue, it seems web service consumer is throwing the above error while parsing the above soap fault.

It seems to be complaining that the SOAP fault response is not valid XML because of this line:
</urn:UniqueNam>
at [row,col {unknown-source}]: [40,54]...
</faultstring>
Note how the text is between </urn:UniqueNam> and </faultstring>. That's not valid in XML. There should be an XML tag or nothing there instead of plain text.

Related

SudsLibrary in Robot Framework: Getting & Setting object attributes

I am working with the SudsLibrary for Robot Framework. Below is the Rq/Rs for the webservice I'm testing. You will also find the Robot Framework info and my comment on what's going on.
REQUEST
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sec="http://localhost/ABC/Services/Security/">
<soapenv:Header/>
<soapenv:Body>
<sec:AuthUser>
<sec:userName>MyAdmin</sec:userName>
<sec:password>Password123</sec:password>
</sec:AuthUser>
</soapenv:Body>
</soapenv:Envelope>
RESPONSE
<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" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.ompum-open.org/wss/2004/01/ompum-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.ompum-open.org/wss/2004/01/ompum-200401-wss-wssecurity-utility-1.0.xsd">
<soap:Header>
...
</soap:Header>
<soap:Body>
<AuthUserResponse xmlns="http://localhost/ABC/Services/Security/">
<AuthTicket>k3l5d9k6-3z53-8765-b512-df09as87</AuthTicket>
</AuthUserResponse>
</soap:Body>
</soap:Envelope>
*** Settings ***
Library SudsLibrary
*** Test Case ***
Check App Auth Ticket
Create Soap Client http://localhost/Services/Authentication.asmx?wsdl
${WSDLobj} Create Wsdl Object AuthUser
Set Wsdl Object Attribute ${WSDLobj} userName MyAdmin
Set Wsdl Object Attribute ${WSDLobj} password Password123
${result} Call Soap Method AuthUser ${WSDLobj}
log Result: ${result}
# Now get the specific element from the response
${AuthVal} Get Wsdl Object Attribute ${result} AuthTicket
log Auth Ticket: ${AuthVal}
Everything is successful in my test case Check App Auth Ticket until I call the SudsLibrary Get Wsdl Object Attribute keyword. The following error occurs: ValueError: Object must be a WSDL object (suds.sudsobject.Object). Why would I get an error when the object is created and is called successfully?
When I print out the ${result} variable, it is the value for AuthVal. However, I am wanting to explicitly extract a specific value / element from the web service response. I have other web service responses that will require me to parse this data for my end to end testing.

Groovy SoapClient Post 500 Error

I want to make a soap request with SoapClient in groovy.
My Code:
SoapClient client = SoapClient.builder()
.endpointUri("http://www.webservicex.com/globalweather.asmx")
.build();
String output = client.post(requestxml)
Request XML:
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<web:GetWeather xmlns:web="http://www.webserviceX.NET">
<web:CityName>Berlin</web:CityName>
<web:CountryName>Germany</web:CountryName>
</web:GetWeather>
</soapenv:Body>
</soapenv:Envelope>
I always get an exception:
ERROR errors.GrailsExceptionResolver - TransmissionException occurred when processing request:
HTTP response=[Internal Server Error] code=[500]. Stacktrace follows:
Message: HTTP response=[Internal Server Error] code=[500]
Line | Method
->> 171 | executePost in org.reficio.ws.client.core.SoapClient
What am I doing wrong?
Consider using WSLite: http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22groovy-wslite%22 This is almost standard SOAP client for Groovy, IMHO.

Apache CXF (Mule) Invalid QName in mapping: SOAP-ENV:Client

I'm using Apache CXF 2.5.9 within Mule ESB 3.5.0 CE for a Web Service client. If the soap message validation fails on server I get a soap fault (naturally) that looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Fault xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>https://10.1.104.105:8444/DohvatiIzOIBaF2FAServiceTest: cvc-simple-type 1: element {http://www.apis-it.hr/fin/2008/elements/DohvatIzOIBa}OIB value '716500116650' is not a valid instance of type {http://www.apis-it.hr/fin/2008/types/f63}String11BrojType</faultstring>
<faultactor>OIB CIS pristupni čvor</faultactor>
</soapenv:Fault>
..but when client side tries to unmarshall the fault I get this exception:
2014-12-13 13:52:34,199 [WARN] org.apache.cxf.phase.PhaseInterceptorChain - Interceptor for {http://www.apis-it.hr/fin/2010/services/DohvatiIzOIBaF2FAService}DohvatiIzOIBaF2ServicePortTypeService#{http://www.apis-it.hr/fin/2010/services/DohvatiIzOIBaF2FAService}DohvatiFOPoOIBu has thrown exception, unwinding now
java.lang.RuntimeException: Invalid QName in mapping: SOAP-ENV:Client
at org.apache.cxf.staxutils.StaxUtils.readQName(StaxUtils.java:1399)
at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalFault(Soap11FaultInInterceptor.java:59)
at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:46)
at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:35)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:114)
at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:69)
at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:801)
I want the CXF client to unmarshall the soap fault to exception. How to get around this error?
Try making SOAP-ENV:Client something like this 12345, making the fault code a number solved it for me.
Mule won't catch the exception itself.
You should probably use a cxf fault interceptor. From there you can compose the message you are expecting.
Alternativly you could use the CXF transform feature
You need:
<entry key="faultcode" value="faultcode=soapenv:Client"/>
This will map the original invalid fault from the server into the following valid fault so that it can be accepted by the cxf client
<soapenv:Fault>
<faultcode>soapenv:Client</faultcode>
<faultstring>An error occurred</faultstring>
</soapenv:Fault>

WSO2 API Manager: Fault message schema (xsd)

WHat is the schema defintion of the fault message when a service on the WSO2 API Managers fails. For example the services has the status blocked, invoking this service, WSO2 replies with an proper SOAP-Fault message. What is the schema (xsd) defintition of the am:fault element?
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://foobar.nl/foobar">
<soapenv:Header/>
<soapenv:Body>
<am:fault xmlns:am="http://wso2.org/apimanager">
<am:code>700700</am:code>
<am:message>API blocked</am:message>
<am:description>This API has been blocked temporarily. Please try again later or contact the system administrators.</am:description>
</am:fault>
</soapenv:Body>
</soapenv:Envelope>
A documentation request is created to WSO2 to update the documentation; https://wso2.org/jira/browse/DOCUMENTATION-866
The default schema is,
<am:fault xmlns:am="http://wso2.org/apimanager">
<am:code>ERROR_CODE</am:code>
<am:message>ERROR_MESSAGE</am:message>
<am:description>ERROR_DESCRIPTION</am:description>
</am:fault>
You can customize the fault format through sequences.

BancBox SOAP API getClient - call fails using WCF client infrastructure

I apologize in advance if this post feels too long. But 1) this is my first post ever and 2) I have really been over the river and through the woods trying to figure this out.
The Add Service Reference feature in Visual Studio 2012 produces a proxy that (apparently) generates invalid SOAP messages. I suspect it has to do with serialization or how the proxy types are decorated but I cannot seem to figure it out. Help is much appreciated.
Detail 1. My environment is Visual Studio 2012 and I have created a .NET 4.5 class library with a service reference to https://sandbox-api.bancbox.com/v1/BBXPort?wsdl. I'm attempting to call the getClient() function; which is defined here. (http://www.bancbox.com/api/view/45)
The code looks like this:
public void GetClient()
{
// create an instance of the service reference proxy class
var bbx=newBBXClient();
bbx.ChannelFactory.Endpoint.Behaviors.Remove<System.ServiceModel.Description.ClientCredentials>();
bbx.ChannelFactory.Endpoint.Behaviors.Add(new CustomCredentials());
bbx.ClientCredentials.UserName.UserName="MY_USERNAME";
bbx.ClientCredentials.UserName.Password="MY_PASSWORD";
var customerId=newid {
subscriberReferenceId="44XX33YY"
};
var request=newgetClientRequest {
subscriberId=MY_SUBSCRIBER_ID,
clientId=customerId
};
var response=bbx.getClient(request);
}
Detail 2. I have made many successful calls into the web service via SoapUI. The successful SoapUI-produced SOAP messages look like this
<soapenv:Envelope xmlns:sch="schema.bancbox.com" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<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="UsernameToken-11">
<wsse:Username>MY_USERNAME</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">MY_PASSWORD</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">tRLo6AlRKl+/rULiKq6A6g==</wsse:Nonce>
<wsu:Created>2013-02-22T18:32:02.204Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<sch:getClient>
<getClientRequest>
<subscriberId>MY_SUBSCRIBER_ID</subscriberId>
<clientId>
<!--Optional:-->
<subscriberReferenceId>44XX33YY</subscriberReferenceId>
</clientId>
</getClientRequest>
</sch:getClient>
</soapenv:Body>
</soapenv:Envelope>
Detail 3. Per Fiddler, my failed SOAP messages look like this
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPozcAgEH0QhJHloqMBWUf3mAAAAAA5wy3enJkDUGU8IaMUCFyEjzfL+1Uez1HhAvEeFpJ+30ACQAA</VsDebuggerCausalityData>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<o:UsernameToken u:Id="uuid-6e1c9f81-0651-41f7-b659-26b191bf7e13-1" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<o:Username>MY_USERNAME</o:Username>
<o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">MY_PASSWORD</o:Password>
<o:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">hGggJkxurSkHQ3MKoeBK6AmEHNs=</o:Nonce>
<u:Created>2013-02-23T11:24:47.663Z</u:Created>
</o:UsernameToken>
</o:Security>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<getClient xmlns="schema.bancbox.com">
<getClientRequest xmlns="">
<subscriberId>MY_SUBSCRIBER_ID</subscriberId>
<clientId>
<subscriberReferenceId>XX55YY22</subscriberReferenceId>
</clientId>
</getClientRequest>
</getClient>
</s:Body>
</s:Envelope>
The SOAP message above is produced when running the GetClient() method. GetClient throws the following Exception.
System.ServiceModel.FaultException
Unmarshalling Error: cvc-elt.4.2: Cannot resolve 'getClientRequest' to a type definition for element 'getClientRequest'.
When I replay the same failing message using SoapUI, I get the following response:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Unmarshalling Error: cvc-elt.4.2: Cannot resolve 'getClientRequest' to a type definition for element 'getClientRequest'. </faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
Detail 4. Based on my research, this indicates that the server on the other end is Apache CXS. It's choking on my SOAP request. So I started playing around with my SOAP message and submitting it via SoapUI.
The first glaring distance in the successful message and my fail message are these lines
SUCCESS
<sch:getClient>
<getClientRequest>
FAIL
<getClient xmlns="schema.bancbox.com">
<getClientRequest xmlns="">
So the first thing that I did was make my getClientRequest tag identical to the successful one.
<getClient xmlns="schema.bancbox.com">
<getClientRequest>
This produced the following response.
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Found element {schema.bancbox.com}getClientRequest but could not find matching RPC/Literal part</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
The next thing that I did is change the way the getClient tag is assigned a schema.
BEFORE
<getClient xmlns="schema.bancbox.com">
AFTER
<s:Envelope xmlns:bb="schema.bancbox.com" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
. . .
<bb:getClient>
<getClientRequest>
. . .
</bb:getClient>
The resultant SOAP message looks like this and it is successful.
<s:Envelope xmlns:bb="schema.bancbox.com" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPozcAgEH0QhJHloqMBWUf3mAAAAAA5wy3enJkDUGU8IaMUCFyEjzfL+1Uez1HhAvEeFpJ+30ACQAA</VsDebuggerCausalityData>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<o:UsernameToken u:Id="uuid-6e1c9f81-0651-41f7-b659-26b191bf7e13-1" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<o:Username>MY_USERNAME</o:Username>
<o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">MY_PASSWORD</o:Password>
<o:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">hGggJkxurSkHQ3MKoeBK6AmEHNs=</o:Nonce>
<u:Created>2013-02-23T11:24:47.663Z</u:Created>
</o:UsernameToken>
</o:Security>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<bb:getClient>
<getClientRequest>
<subscriberId>MY_SUBSCRIBER_ID</subscriberId>
<clientId>
<subscriberReferenceId>XX55YY22</subscriberReferenceId>
</clientId>
</getClientRequest>
</bb:getClient>
</s:Body>
</s:Envelope>
So the million dollar questions are WHY and HOW.
*WHY does the .NET proxy class serialize the SOAP message the way it does?
*HOW do I fix it? How can I may my proxy serialize into the SOAP message above? How can I force the serializer to define shorthand for the message namespace in the Envelop and then use the shorthand in the message tag?
FYI, to even get to this point I had to get past a number of WCF WSE issues and ended up implementing the solution so generously provided on Rich Stahls blog. I would post the link but apparently I don't have enough rep.
From I understand, the SOAP message that WCF produces is syntactically correct. However, Java CXF web services are very rigid with regards to the SOAP messages that they will accept.
The solution to specific problem setting aliases for xml namespace definitions in the Operation node of the SOAP messages produced by WCF proxies involves implementing a Custom Message Inspector is detailed here: Force WCF to create an xml namespace alias in client proxy.
This has completely resolved my issue.