WSO2 Proxy service XML Xpath - wso2

Im using wso2 EI 6.5.0
in my proxy service i need to get element between these 2 tags <aa></aa>
xpath //tem:Request is working but /tem:Request/xDoc/aa does not work
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:Request>
<xDoc>
<aa>
<bb>
....
</bb>
<cc>
<Parameter>
......
</Parameter>
</cc>
</aa>
</xDoc>
</tem:Request>
</soapenv:Body>
</soapenv:Envelope>

You have to use either /soapenv:Envelope/soapenv:Body/tem:Request/xDoc/aa or $body/tem:Request/xDoc/aa.
The purpose of using "//" in an xpath is to directly access a particular element. But if we use "/", we need to specify the entire path to traverse through the XML tags and reach a particular element.
On a different note, if you want to access the tag <aa/> then you can directly use the xpath //aa.

Related

WSO2ESB, XPath, split values based on a token in SOAP response

I have a SOAP response message which contains a node value
similar to string A_B_C_D. I need to split each
value based on the underscore (_) and set them in
separate properties.
I checked with Xpath tokenize function but could not find a
way to get the values like array[1], array[2].. separately.
I also did some reading on XSLT mediator but not sure whether
it will help me to achieve this.
Please guide me on how to achieve this objective
Thanks
You can get value like "array[1]" but can't apply tokenize directly on soap:Body with ESB 4.8.1 :
<property xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fn="http://www.w3.org/2005/xpath-functions" name="MY_VALUE" expression="//soapenv:Body/myNode"/>
<property xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fn="http://www.w3.org/2005/xpath-functions" name="Element1" expression="fn:tokenize(syn:get-property('MY_VALUE'),'_')[1]"/>
With this message :
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<myNode>A_B_C</myNode>
</soapenv:Body>
</soapenv:Envelope>
property 'Element1' contain : 'A'

XSLT to get the attribute value from a SOAP Request

I have the following SOAP Request and i need to extract the IP Address parameter value inside the XSLT template.
SOAP REQUEST:
<soapenv:Envelope
xmlns:ws="http://diamondip.com/ipcontrol/ws/"
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:Header />
<soapenv:Body>
<ws:deleteDevice soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<inpDev xsi:type="ser:WSDevice"
xmlns:ser="http://service.ipcontrol.diamondip.com"
>
<ipAddress xsi:type="soapenc:string"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
>xxx.xxx.xx.xx</ipAddress>
</inpDev>
</ws:deleteDevice>
</soapenv:Body>
</soapenv:Envelope>
I tried using the following to get the value,but it didn't work
<xsl:variable name="ipAddress" select="soapenv:Envelope/soapenv:Body/ws:deleteDevice/inpDev/ipAddress/text()"/>
Appreciate any advise!
The one thing we don't know from your question is what the current context node is when you do the xsl:variable. It should work if your current context node is the root node.
Try changing the XPath to an absolute path (put a forward slash at the beginning). If that doesn't work, make sure all the namespaces are defined correctly in your XSLT.
You can use below code to navigate and get the output.
<xsl:stylesheet version ="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match ='/'>
<xsl:variable name="ipAddress" select="/*[local-name() = 'Envelope']/*[local-name() = 'Body']/*[local-name() = 'deleteDevice']/*[local-name() = 'inpDev']/*[local-name() = 'ipAddress']/text()"/>
IP Adress: <xsl:value-of select = "$ipAddress"/>
</xsl:template>
</xsl:stylesheet>

How do I remove operation element from soap envelope body in WCF?

I have a WCF service setup mostly to a customer's spec, yet there is one extra element required of an envelope body that I'm trying to exclude based on the customer's sample request.
These are my service and operation contracts:
[ServiceContract(Namespace="http://www.somenamespace.com")]
public interface IProcessPayment
{
[OperationContract]
ResponseSubmitPayment execute(RequestSubmitPayment RequestSubmitPayment);
}
This is what they are sending to test my service with:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pay="http://www.somenamespace.com">
<soapenv:Header/>
<soapenv:Body>
<pay:RequestSubmitPayment>
<!-- irrelevant stuff -->
</pay:RequestSubmitPayment>
</soapenv:Body>
</soapenv:Envelope>
and this is what my service expects (based on SOAPUI):
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pay="http://www.somenamespace.com">
<soapenv:Header/>
<soapenv:Body>
<pay:execute> <!-- I want to remove this! -->
<pay:RequestSubmitPayment>
<!-- irrelevant stuff -->
</pay:RequestSubmitPayment>
</pay:execute> <!-- I want to remove this! -->
</soapenv:Body>
</soapenv:Envelope>
How can I configure my WCF service to not require or exclude that element? The client has told me they have many other customers with it successfully tested and implemented. SOAP 1.1 is my understanding of what they're sending.
Thanks in advance!
Not sure it is doable in operationcontract. Try using a message contract, it will give you the flexibility you need. If that fails use an xmlserializer contract with method flag ParameterStyle = SoapParameterStyle.Bare.

Reporting Services, how to query a webservice with complex type parameter as input

I need to query a webservice passing complex parameters in Reporting Services as input.
How can I do this?
In Query Designer at Visual Studio, I'm doing the query like this :
<Query>
<SoapAction>http://mywebservice.com/Customers/GetCustomers</SoapAction>
<Method Name="GetCustomers" Namespace="http://mywebservice.com/Customers/">
<Parameters>
<Parameter Name="myParams" type="xml">
<DefaultValue>
<myParams>
<IdCustomer>0</IdCustomer>
</myParams>
</DefaultValue>
</Parameter>
</Parameters>
</Method>
<ElementPath IgnoreNamespaces="true">*</ElementPath>
</Query>
WebService expect it as parameter:
<?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>
<GetCustomer xmlns="http://mywebservice.com/Customers/">
<myParams>
<IdCustomer>int</IdCustomer>
<IdCustomer>int</IdCustomer>
</myParams>
</GetCustomer>
</soap:Body>
</soap:Envelope>
When I try it at Visual Studio 2008, I get this error message :
Failed to execute web request for the specified URL. Soap Fault:
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
You should look at the xml being sent in a test client in order to get an example of the syntax needed for your query. I recommend using the wcftestclient that comes with Visual Studio. Once you run a test, you can view the xml on the XML tab (at the bottom of the screen in wcftestclient), and replace what is in the <DefaultValue> section of your query with the corresponding parameter values.
The query for that webservice should look something like the following. Note the a namespace which will be depend on your own situation:
<Query>
<SoapAction>http://mywebservice.com/Customers/GetCustomers</SoapAction>
<Method Name="GetCustomer" Namespace="http://mywebservice.com/Customers/">
<Parameters>
<Parameter Name="myParams" type="xml">
<DefaultValue xmlns:a="http://schemas.datacontract.org/2004/07/MyWebServices">
<a:IdCustomer>0</a:IdCustomer>
<a:IdCustomer>1</a:IdCustomer>
</DefaultValue>
</Parameter>
</Parameters>
</Method>
</Query>
Also, I do see that you have <Parameter type="xml">. For Me, I spent hours working through a similar query and was missing the type="xml". That attribute does not seem to be well documented on MSDN.

How to change the way coldfusion send the soap response?

I have a coldfusion webservice which takes in XML data and send back the acknowledgement.
When there is an error the current code returns me the soap response as
<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>
<ns1:updatePendingTicketsResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://v02.intouchdataservice">
<updatePendingTicketsReturn xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"><![CDATA[<fault>
<faultcode>TO BE DEFINED IF NEEDED</faultcode>
<faultstring >Content is not allowed in prolog.</faultstring>
<faultactor>InTouch</faultactor>
</fault>]]></updatePendingTicketsReturn>
</ns1:updatePendingTicketsResponse>
</soapenv:Body>
</soapenv:Envelope>
But what I would like to have in response is
<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>TO BE DEFINED IF NEEDED</faultcode>
<faultstring >Content is not allowed in prolog.</faultstring>
<faultactor>InTouch</faultactor>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
Is there a way we can change the way coldfusion sends back the response when there is an exception?
In addition to that, Is there a way we can add an XML schema to the coldfusion WSDL to validate the XML document thats been send ?
Thank you
I think no but you can put whole code in try and catch define your own response code.
You can use the wsdlfile attribute of <cfcomponent /> to specify a custom WSDL.
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7e0e.html
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-78a6.html