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/
Related
I am trying to create a Data Mapper mediator that converts from XML to JSON. However, whenever I try to create a link, I get the following error message:
!ENTRY org.wso2.developerstudio.datamapper.diagram 2 0 2018-02-22 12:43:29.804
!MESSAGE Could not save file L/X/Y.dmc : java.lang.ArrayIndexOutOfBoundsException
Here's the XML:
<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns0:response xmlns:ns0="http://www.server.com/api/SoapEndpoint">
<return>
<messages>
<code>0</code>
<message>STRING</message>
</messages>
</return>
</ns0:response>
</S:Body>
</S:Envelope>
Here's the JSON schema:
{
"success": true,
"messages": [
{
"code": 0,
"message": "string"
}
]
}
Whenever I try to create a link from the XML code element to the corresponding field in the JSON schema, I get the error message.
Here's my Data Mapper config portion:
<datamapper config="gov:datamapper/Y.dmc" inputSchema="gov:datamapper/A.json" inputType="XML" outputSchema="gov:datamapper/Y.json" outputType="JSON"/>
Found out the issue: when I was importing it into the Data Mapper diagram, the messages element was being interpreted as an Object rather than array. Once I changed it to an array, the mapping started working and the issue went away.
I want to use BPMN Service Task and invoke a REST API.
I need to receive requests from the service ESB in format XML.
Example of request:
<?xml version="1.0" encoding="utf-8"?>
<reqSendEvent extrSystem="rout" typeEvent="newRout" xmlns="http://magnit.ru/tanderCoreMassageData.xsd">
<originTime>2017.08.25 15:12:00</originTime>
<content>
<rout>
<name>xxxxx</name>
</rout>
</content>
</reqSendEvent>
servicetask:
<serviceTask id="servicetask1" name="Service Task" activiti:class="org.wso2.developerstudio.bpmn.extensions.restTask.RESTTask">
<extensionElements>
<activiti:field name="serviceURL">
<activiti:expression><![CDATA[http://localhost:9773/tanderBPMN/services/servicetask1]]></activiti:expression>
</activiti:field>
<activiti:field name="method">
<activiti:string><![CDATA[POST]]></activiti:string>
</activiti:field>
<activiti:field name="headers">
<activiti:expression><![CDATA[Content-Type:text/xml]]></activiti:expression>
</activiti:field>
<activiti:field name="outputMappings">
<activiti:string><![CDATA[xxxxxx]]></activiti:string>
</activiti:field>
</extensionElements>
</serviceTask>
In all the examples, using JSON payloads. What do i write expression in to the outputMappings to get value from tag *//rout/name?
You should be able to use a simple String to hold the POST payload and map the parameter to the String.
Have you tried this?
Greg
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.
I am invoking an opportunity service, but ending with the following Error.
SOAP Response:
<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>Client</faultstring><detail><ErrorCode>SBL-ODU-01007</ErrorCode><ErrorMessage>The HTTP request did not contain a valid SOAPAction header
The value of the header was:
document/urn:crmondemand/ws/ecbs/opportunity/10/2004:OpportunityQueryPage</ErrorMessage></detail></soap:Fault></soap:Body></soap:Envelope>
I am using apache http client to invoke this service.
SOAP Request Msg:
<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"urn:crmondemand/ws/ecbs/opportunity/10/2004\" xmlns:quer=\"urn:/crmondemand/xml/Opportunity/Query\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:wsse=\"http://schemas.xmlsoap.org/ws/2002/07/secext\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"> <soapenv:Header><wsse:Security><wsse:UsernameToken><wsse:Username>XXXXXX</wsse:Username><wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\">XXXXXXX</wsse:Password></wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body><ns:OpportunityQueryPage_Input><quer:ListOfOpportunity pagesize=\"100\" startrownum=\"1\" recordcountneeded=\"5\"><quer:Opportunity searchspec=\"[Owner] LIKE '*'\"><quer:Description sortorder=\"ASCE\"></quer:Description><quer:AccountName sortorder=\"ASCE\"></quer:AccountName><quer:cActual_Booking_ValueTCV_Mn></quer:cActual_Booking_ValueTCV_Mn></quer:Opportunity></quer:ListOfOpportunity></ns:OpportunityQueryPage_Input></soapenv:Body></soapenv:Envelope>
My Invocation URL:
https://secure-ausomxapa.crmondemand.com/Services/Integration
I am not able to find exactly where is the error. Kindly Help to fix this issue.
Here is an example which works for activities:
soapAction: '"document/urn:crmondemand/ws/ecbs/activity/10/2004:ActivityQueryPage"',
data: '<?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><ActivityQueryPage_Input xmlns="urn:crmondemand/ws/ecbs/activity/10/2004"><ListOfActivity pagesize="20" xmlns="urn:/crmondemand/xml/Activity/Query"><Activity searchspec= "[Id] = \''+myTextBox.val()+'\'"><Id></Id><Subject></Subject><Type></Type><Priority></Priority><Description></Description><CommentsAction></CommentsAction><OwnerFullName></OwnerFullName><DelegatedBy></DelegatedBy></Activity></ListOfActivity></ActivityQueryPage_Input></soap:Body></soap:Envelope>',
callback: function (data) {}
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.