Error parsing SOAP response - web-services

I'm trying to parse a SOAP response from a web service. I'm using httpbuilder to do the request. Here is my code:
def String WSDL_URL = 'http://ws.webgains.com/aws.php'
def http = new HTTPBuilder( WSDL_URL , ContentType.XML )
String soapEnvelope =
"""<?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>
<getFullUpdatedEarnings xmlns="http://ws.webgains.com/aws.php">
<startDate>2013</startDate>
<endDate>2013</endDate>
<username>username</username>
<password>pass</password>
</getFullUpdatedEarnings>
</soap12:Body>
</soap12:Envelope>"""
http.request( Method.POST, ContentType.XML ) {
body = soapEnvelope
response.success = { resp, xml ->
println "XML was ${xml.Body.getFullUpdatedEarningsResponse.return.text()}"
def territories = new XmlSlurper().parseText(
xml.Body.getFullUpdatedEarningsResponse.return.text()
)
}
response.failure = { resp, xml ->
xml
}
}
When I try to parse the response I get a org.xml.sax.SAXParseException Content is not allowed in prolog.
Here is the output I'm getting from the web services:
3936713759987www.tikcode.com1367552013-05-13T15:04:482013-05-13T15:04:48Miniinthebox - US46119566172850.060.8confirmednotcleared2013-05-13T14:58:33http%3A%2F%2Fwww.lightinthebox.com%2Fes%2F%3Flitb_from%3Daffiliate_webgainsEShttp%3A%2F%2Flocalhost%3A8080%2Fcom.publidirecta.widget%2Fpromocion%2FverPromocion%3Fpromocion%3D
If I use ContenTyp.TEXT the xml I'm getting is
[<?xml version="1.0" encoding="UTF-8"?>, <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="urn:http://ws.webgains.com/aws.php" xmlns:enc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><env:Body xmlns:rpc="http://www.w3.org/2003/05/soap-rpc"><ns1:getFullUpdatedEarningsResponse env:encodingStyle="http://www.w3.org/2003/05/soap-encoding"><rpc:result>return</rpc:result><return enc:itemType="ns1:fullLinesArray" enc:arraySize="1" xsi:type="ns1:fullReportArray"><item xsi:type="ns1:fullLinesArray"><transactionID xsi:type="xsd:int">39367137</transactionID><affiliateID xsi:type="xsd:int">59987</affiliateID><campaignName xsi:type="xsd:string">www.tikcode.com</campaignName><campaignID xsi:type="xsd:int">136755</campaignID><date xsi:type="xsd:dateTime">2013-05-13T15:04:48</date><validationDate xsi:type="xsd:dateTime">2013-05-13T15:04:48</validationDate><delayedUntilDate xsi:type="xsd:string"></delayedUntilDate><programName xsi:type="xsd:string">Miniinthebox - US</programName><programID xsi:type="xsd:int">4611</programID><linkID xsi:type="xsd:string">95661</linkID><eventID xsi:type="xsd:int">7285</eventID><commission xsi:type="xsd:float">0.06</commission><saleValue xsi:type="xsd:float">0.8</saleValue><status xsi:type="xsd:string">confirmed</status><paymentStatus xsi:type="xsd:string">notcleared</paymentStatus><changeReason xsi:nil="true"/><clickRef xsi:nil="true"/><clickthroughTime xsi:type="xsd:dateTime">2013-05-13T14:58:33</clickthroughTime><landingPage xsi:type="xsd:string">http%3A%2F%2Fwww.lightinthebox.com%2Fes%2F%3Flitb_from%3Daffiliate_webgains</landingPage><country xsi:type="xsd:string">ES</country><referrer xsi:type="xsd:string">http%3A%2F%2Flocalhost%3A8080%2Fcom.publidirecta.widget%2Fpromocion%2FverPromocion%3Fpromocion%3D</referrer></item></return></ns1:getFullUpdatedEarningsResponse></env:Body></env:Envelope>]
I'm fairly new to web services so If anyone have any ideas I really would appreciate any help
EDIT: Also tried with ws lite with the same results

It looks like you're parsing the response a second time. Why are you using an XmlSlurper to parse the text of the return tag? The elements under return are already parsed and can be accessed directly.

Related

Change JAX-WS output namespace prefix

The web service that calls us expects us to return the following XML:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:loc="http://www.csapi.org/schema/parlayx/sms/notification/v2_2/local">
<soapenv:Header />
<soapenv:Body>
<loc:notifySmsDeliveryReceiptResponse />
</soapenv:Body>
</soapenv:Envelope>
We use JAX-WS to provide our web service. The following is how we define our web service interface:
#BindingType(value = javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING)
#WebService (targetNamespace = "http://www.csapi.org/schema/parlayx/sms/notification/v2_2/local")
#HandlerChain(file = "deliverysoaphandler.xml")
#SOAPBinding(style = Style.DOCUMENT)
public interface DeliveryService {
#WebMethod ()
public void notifySmsReception(
#WebParam(name = "correlator", targetNamespace = "http://www.csapi.org/schema/parlayx/sms/notification/v2_2/local") #XmlElement(required = true) String correlator,
#WebParam(name = "message", targetNamespace = "http://www.csapi.org/schema/parlayx/sms/notification/v2_2/local") #XmlElement(required = true) Message message
) throws DeliveryException;
}
This produces the following return document:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<S:Body>
<ns2:notifySmsReceptionResponse xmlns:ns2="http://www.csapi.org/schema/parlayx/sms/notification/v2_2/local"/>
</S:Body>
</S:Envelope>
We think the document is essential the same as what the calling system expects but gets rejected because 1) the namespaces are capitalized, 2) the same namespace reference is repeated and 3) there is a namespace declaration in the middle of the document.
Is there anyway in which I can persuade the JAX-WS provider to produce what the other system wants?
Based on this description, I am not sure the namespaces are the problem.
The service consumer is expecting:
<soapenv:Body>
<loc:notifySmsDeliveryReceiptResponse />
</soapenv:Body>
but is receiving
<S:Body>
<ns2:notifySmsReceptionResponse xmlns:ns2="..."/>
</S:Body>
which indicates a response to a different operation name.
Try changing your service endpoint interface WebMethod method name to:
#WebMethod ()
public void notifySmsDeliveryReceipt(
Doing so will require you to also change the method name on the implementation class (or it will no longer compile).
Alternatively, you can also just change your #WebMethod to the desired/indicated operation name:
#WebMethod (operationName="notifySmsDeliveryReceipt")
public void notifySmsReception(
The service should now produce:
<S:Body>
<ns2:notifySmsDeliveryReceiptResponse xmlns:ns2="http://www.csapi.org/schema/parlayx/sms/notification/v2_2/local"/>
</S:Body>

consuming an external web service using marklogic

Having a difficult time. Finding examples on, How to access an external web service using marklogic? (maybe my search terms are wrong? i also tried xdmp:http-get, xdmp:http-post, post http request, mash-up, orchestrate).
I first need to understand, How difficult (hopefully easy) it will be for me to write a script in MarkLogic to access one external (non-ML) web service and display the response before I proceed with combining results from 3 different web services (is the correct term for this mash-up?) in one page using ML.
An example using ML will be most appreciated. I have seen celsius to fahrenheit conversion examples, also stock quotes request and response but not in ML. I do not know how or where to start. Can you point me to right direction please. Eager to learn using ML for web services.
many thanks.
I'd say there are examples here: http://docs.marklogic.com/xdmp:http-post
But for the sake of completeness, let me add these as well:
Based on:
http://www.w3schools.com/xml/tempconvert.asmx?op=FahrenheitToCelsius
SOAP 1.1:
let $envelop :=
<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>
<FahrenheitToCelsius xmlns="http://www.w3schools.com/xml/">
<Fahrenheit>100</Fahrenheit>
</FahrenheitToCelsius>
</soap:Body>
</soap:Envelope>
return
xdmp:http-post(
"http://www.w3schools.com/xml/tempconvert.asmx",
<options xmlns="xdmp:http">
<headers>
<Content-Type>text/xml; charset=utf-8</Content-Type>
<SOAPAction>"http://www.w3schools.com/xml/FahrenheitToCelsius"</SOAPAction>
</headers>
</options>,
$envelop
)
SOAP 1.2:
let $envelop :=
<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>
<FahrenheitToCelsius xmlns="http://www.w3schools.com/xml/">
<Fahrenheit>100</Fahrenheit>
</FahrenheitToCelsius>
</soap12:Body>
</soap12:Envelope>
return
xdmp:http-post(
"http://www.w3schools.com/xml/tempconvert.asmx",
<options xmlns="xdmp:http">
<format xmlns="xdmp:document-get">xml</format>
<headers>
<Content-Type>application/soap+xml; charset=utf-8</Content-Type>
</headers>
</options>,
$envelop
)
HTTP POST:
let $body := text {
string-join(
("Fahrenheit=" || encode-for-uri(string(100))),
"&"
)
}
return
xdmp:http-post(
"http://www.w3schools.com/xml/tempconvert.asmx/FahrenheitToCelsius",
<options xmlns="xdmp:http">
<headers>
<Content-Type>application/x-www-form-urlencoded</Content-Type>
</headers>
</options>,
$body
)
HTH!

ASMX webserive not recieving parameters from classic ASP soap request.

I am attempting to wrap a newer .net ASMX webservice so that it can be used by an older classic asp application. To do this I found some code to send the soap requests. However in my testing it seems that none of my parameters are reaching the server.
The Server Test Code
<WebMethod()> _
Public Function Ping1(str As String)
If str <> "" Then
Return str
Else
Return "False"
End If
End Function
The xml being sent:
<?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>
<Ping1 xmlns="http://tempuri.org">
<str>asdf</str>
</Ping1>
</soap12:Body>
</soap12:Envelope>
The page keeps returning "False" but as far as I can tell, this should be the right format to send parameters. Any help would be appreciated.
As demonstrated in this other question you should set proper headers when consuming the service:
oXmlHTTP.setRequestHeader "Content-Type", "application/soap+xml; charset=utf-8"
oXmlHTTP.setRequestHeader "SOAPAction", "http://ourNameSpace/Ping1"
Note that you can't use tempuri.org namespace, you have to also set your own namespace.

Making a call to a web service through a java client

I have a web service running on my local apache tomcat. I can successfully talk to it via SoapUI. However, when I write a client in Java, it does not give me a response !
Here is the client code:
SOAPConnectionFactory myFct = SOAPConnectionFactory.newInstance();
SOAPConnection myCon = myFct.createConnection();
MessageFactory myMsgFct = MessageFactory.newInstance();
SOAPMessage message = myMsgFct.createMessage();
SOAPPart mySPart = message.getSOAPPart();
SOAPEnvelope myEnvp = mySPart.getEnvelope();
SOAPBody body = myEnvp.getBody();
Name bodyName = myEnvp.createName("Ping", "ws","http://ws.myeclipseide.com/");
SOAPBodyElement gltp = body.addBodyElement(bodyName);
Name myContent1 = myEnvp.createName("arg0");
SOAPElement mySymbol1 = gltp.addChildElement(myContent1);
mySymbol1.addTextNode("test");
message.saveChanges();
URLEndpoint endPt = new URLEndpoint("http://localhost:8080/PingWebService/StringPingPort?WSDL");
SOAPMessage reply = myCon.call(message, endPt);
myCon.close();
System.out.println("Response: "+reply.getContentDescription());
The call through soapUI looks like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.myeclipseide.com/">
<soapenv:Header/>
<soapenv:Body>
<ws:Ping>
<!--Optional:-->
<arg0>testing this</arg0>
</ws:Ping>
</soapenv:Body>
</soapenv:Envelope>
Any idea why it would not work through java???
Does not work
Exception, error message, no call,... ?
At first glance, I cannot see anything obvious but since you are using Eclipse, activate the TCP Monitor under Eclipse, issue your call by running you program from Eclipse and check what is sent on the wire.
getContentDescription() "Returns: a String describing the content of this message or null if no description has been set" and NOT the content of your message.
Try this:
ByteArrayOutputStream out = new ByteArrayOutputStream();
reply.writeTo(out);
System.out.println("Response: "+out.toString());

How to retrieve result from WebService response?

I am new to WebService. I am getting the following response from the WebService
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header/>
<S:Body><ns2:getGreetingResponse xmlns:ns2="http://wsserver.myfirst.com/">
<return>Hello Cheepu</return>
</ns2:getGreetingResponse></S:Body></S:Envelope>
Result in the XML is "Hello Cheepu". How can i retrieve that from the response.
You may load the XML DOM with code such as:
if (window.DOMParser)
{
parser=new DOMParser();
xmlDoc=parser.parseFromString(text,"text/xml");
}
else // Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.loadXML(text);
}
Then traverse the DOM to the element.
This code is for javaScrip at the browser. Similar code in Java as given in http://www.mkyong.com/java/how-to-read-xml-file-in-java-dom-parser/