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.
Related
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.
i have a web service client which uses axis2 1.6.1, xmlbeans. It works fine.
Now, i want to create a string of soap request message (not only a xml string but also a soap string) from request object.
Please help.
(using jaxb or cxf are not options for this project)
Ok, i worked it out. After you have xmlbean object, just do string concatenate between soap envelope and xmlObject.toXML().
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="http://www.qwest.com/XMLSchema" >
<soapenv:Header/>
<soapenv:Body>
+ xmlObject.toXML()
+ </soapenv:Body>
</soapenv:Envelope>
I'm trying to add a SOAP API to APIM 1.10.0.
First, I'll try to test the SOAP service itself, using the following CURL. The service should return weather conditions of a given city/country:
curl -X POST -T soap.xml -H "Content-Type: text/xml" \
"http://www.webservicex.net/globalweather.asmx"
Providing the following soap.xml:
<?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>
<GetWeather xmlns="http://www.webserviceX.NET">
<CityName>Eilat</CityName>
<CountryName>Israel</CountryName>
</GetWeather>
</soap:Body>
</soap:Envelope>
I receive a sensible response!
Now I introduce this service to APIM, as follows:
- Add new API
- I have a SOAP endpoint
- WSDL URL: http://www.webservicex.net/globalweather.asmx?wsdl
- Start Creating
- Name: eilat
- Context: /eilat
- Version: 1.0.0
- WSDL: http://www.webservicex.net/globalweather.asmx?wsdl [tested ok]
- Production Endpoint: http://www.webservicex.net/globalweather.asmx [valid]
- Tier Availability: Unlimited
I subscribe to this API, and try the following CURL
curl -H "Authorization: Bearer <my-key>" -X POST -T soap.xml \
-H "Content-Type: text/xml" http://localhost:8280/eilat/1.0.0
I get the following reply:
<faultstring>unknown</faultstring>
Trying the same in SOAP UI, I get:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server</faultcode>
<faultstring>unknown</faultstring>
<detail/>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
With #status#: HTTP 1.1/500 Internal Server Error
Looking at the logs:
1) http_access_2016-01-17.log
127.0.0.1 - - [17/Jan/2016:16:53:34 +0200]
"POST /eilat/1.0.0 HTTP/1.1" - 482 "-"
"curl/7.19.7 (x86_64-redhat-linux-gnu)
libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
2) wso2-apigw-errors.log
2016-01-17 16:53:34,364 [-] [PassThroughMessageProcessor-374]
ERROR ServerWorker Error processing
POST reguest for :
/eilat/1.0.0. Error detail: null. java.lang.NullPointerException
3) wso2carbon.log
INFO {org.apache.synapse.rest.API} -
Initializing API: admin--eilat:v1.0.0 {org.apache.synapse.rest.API}
INFO {org.wso2.carbon.core.services.util.CarbonAuthenticationUtil} -
'admin#carbon.super [-1234]' logged in at [2016-01-17 16:52:51,282+0200]
{org.wso2.carbon.core.services.util.CarbonAuthenticationUtil}
ERROR {org.apache.synapse.transport.passthru.ServerWorker} -
Error processing POST reguest for : /eilat/1.0.0.
Error detail: null.
{org.apache.synapse.transport.passthru.ServerWorker}
java.lang.NullPointerException
Looking at the API again, I see that WSDL URL is changed from the URL I provided, to the following:
/registry/resource/_system/governance/apimgt/applicationdata/wsdls/admin--eilat1.0.0.wsdl
I guess this is normal behavior.
Question is - why the Null Pointer Exception?
Error was caused due to a custom authentication plugin handler.
Removing this handler from the chain of handlers solved the problem.
I am very new to Mule ESB. I want to expose a Mule flow as an WebService to an external applicaton. How to set the request(payload) structure in the wsdl exposed by mule?
Am using CFX for it.
Currently my request while loading WSDL in SoapUI looks like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sup="http://support.cxf.module.mule.org/">
<soapenv:Header/>
<soapenv:Body>
<sup:invoke>
<sup:arg0>?</sup:arg0>
</sup:invoke>
</soapenv:Body>
</soapenv:Envelope>
Actual request expected to be is as follows:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://pcom.orga.com/pc/webservices/messages/v1">
<soapenv:Header/>
<soapenv:Body>
<v1:searchOfferRequest>
<searchInput>
<status>RELEASED</status>
</searchInput>
</v1:searchOfferRequest>
</soapenv:Body>
</soapenv:Envelope>
Have a look at Mule documentation for exposing a SOAP service in Mule, specifically look for the section "Creating a WSDL First JAX-WS Service" which has an example of what you are looking for.
HTH
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.