Xquery: getting unique blocks with based on multiple values - xpath

I'm trying to get unique set of data from the XML below
<output>
<category>DB</category>
<title>Database systems</title>
<name>Smith</name>
<name>John</name>
<name>Adam</name>
</output>
<output>
<category>DB</category>
<title>Database systems</title>
<name>John</name>
<name>Smith</name>
<name>Adam</name>
</output>
<output>
<category>DB</category>
<title>Database systems</title>
<name>Adam</name>
<name>Smith</name>
<name>John</name>
</output>
<output>
<category>Others</category>
<title>Pattern Recognition</title>
<name>Adam</name>
<name>Jeff</name>
</output>
<output>
<category>Others</category>
<title>Pattern Recognition</title>
<name>Jeff</name>
<name>Adam</name>
</output>
Since the 3 output blocks contain the same information, I only need to pick one.
But, when I use distinct-values() function, I'm getting all three of them in their respective order.
I have assigned the above table as $final and below is what I'm getting
for $f in distinct-values($final)
return $f
output
DBDatabase systemsSmithJohnAdam
DBDatabase systemsJohnSmithAdam
DBDatabase systemsAdamSmithJohn
expected
<output>
<category>DB</category>
<title>Database systems</title>
<name>Smith</name>
<name>John</name>
<name>Adam</name>
</output>
<output>
<category>Others</category>
<title>Pattern Recognition</title>
<name>Adam</name>
<name>Jeff</name>
</output>
no need for ordering in
I tried to sort the name tag but its not working out as it adds too much to the code.
Is there any logic in Xquery to get one copy from the above XML ?

Try something along these lines on your actual xml:
let $inv :=
<doc>
[your xml above]
</doc>
let $titles := $inv//output/title
for $title in distinct-values($titles)
return $inv//output[title[$title]][1]
Output:
<output>
<category>DB</category>
<title>Database systems</title>
<name>Smith</name>
<name>John</name>
<name>Adam</name>
</output>
<output>
<category>Others</category>
<title>Pattern Recognition</title>
<name>Adam</name>
<name>Jeff</name>
</output>

An option could be :
doc("data.xml")//output/*[not(preceding::*=.)]
Output :
<category>DB</category>
<title>Database systems</title>
<name>Smith</name>
<name>John</name>
<name>Adam</name>

In XQuery 3, I think the shortest and most efficient is to use group by:
for $output in //output
group by $title := $output/title
return head($output)
https://xqueryfiddle.liberty-development.net/jyH9Xv5

Related

Validating XML documents against schemas nested inside wsdl:types

I have XML files that I need to validate against XSDs that are nested inside a <wsdl:types></wsdl:types> in a WSDL file retrieved from a web service.
Inside the <wsdl:types></wsdl:types> there are several <xs:schema>s. I am using the ruby gem nokogiri to load the XML files and validate them against said XSDs, however, I am getting following error when I run the program:
Element '{http://schemas.xmlsoap.org/soap/envelope/}Envelope': No
matching global declaration available for the validation root.
So far I have extracted out the <xs:schema>s (all 4 of them) and copied them into a schema.xsd file.
Code:
require 'rubygems'
require 'nokogiri'
def validate(document_path, schema_path)
schema = Nokogiri::XML::Schema(File.read(schema_path))
document = Nokogiri::XML(File.read(document_path))
schema.validate(document)
end
validate('data.xml', 'schema.xsd').each do |error|
puts error.message
end
So basically my schema.xsd has multiple <xs:schema>s in there, which I do not think in and of itself is a problem because nokogiri didn't throw errors when I instantiated the schema object.
schema.xsd
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/">
<xs:element name="anyType" nillable="true" type="xs:anyType"/>
<xs:element name="anyURI" nillable="true" type="xs:anyURI"/>
<!-- data in here -->
</xs:schema>
<!-- three more xs:schema tags removed for brevity -->
data.xml
<?xml version='1.0' ?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header />
<env:Body>
<CreatePerson xmlns="https://person.example.com/">
<oMessageType xmlns:epa="http://schemas.datacontract.org/2004/07/whatever" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:array="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<person:bodyField>
<!-- data in here -->
</person:bodyField>
<!-- more data in here -->
</oMessageType>
</CreatePerson>
</env:Body>
</env:Envelope>
Yes, WSDL not the XSD scheam so you need to extract the schema partial manually or automatic by programming.
Here is the sample code, you need to refactor it and using in your codes.
str = <<EOF
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.examples.com/wsdl/HelloService.wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="HelloService" targetNamespace="http://www.examples.com/wsdl/HelloService.wsdl">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/">
<element name="anyType" nillable="true" type="anyType"/>
<element name="anyURI" nillable="true" type="anyURI"/>
<!-- data in here -->
</schema>
</types>
<message name="SayHelloRequest">
<part name="firstName" type="xsd:string"/>
</message>
<message name="SayHelloResponse">
<part name="greeting" type="xsd:string"/>
</message>
<portType name="Hello_PortType">
<operation name="sayHello">
<input message="tns:SayHelloRequest"/>
<output message="tns:SayHelloResponse"/>
</operation>
</portType>
<binding name="Hello_Binding" type="tns:Hello_PortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="sayHello">
<soap:operation soapAction="sayHello"/>
<input>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:examples:helloservice"/>
</input>
<output>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:examples:helloservice"/>
</output>
</operation>
</binding>
<service name="Hello_Service">
<documentation>WSDL File for HelloService</documentation>
<port name="Hello_Port" binding="tns:Hello_Binding">
<soap:address location="http://www.examples.com/SayHello/"/>
</port>
</service>
</definitions>
EOF
require 'rubygems'
require 'nokogiri'
doc = Nokogiri::XML(str)
doc.root.children.each do |child|
if child.node_name == 'types'
types = child
# p types.inner_html
xsd_doc = Nokogiri::XML(types.inner_html)
# p xsd_doc.root
xsd = Nokogiri::XML::Schema.from_document xsd_doc.root
end
end

awk : parse and write to another file

I have records in XML file like below. I need to search for <keyword>SEARCH</keyword> and if present
then I need to take the entire record and write to another file.(starting from <record> to </record>)
Below is my awk code which is inside loop. $1 holds line by line value of each record.
if(index($1,"SEARCH")>0)
{
print $1>> "output.txt"
}
This logic has two problems,
It is writing to output.txt file, only <keyword>SEARCH</keyword> element and not the whole record(starting from <record> to </record>)
SEARCH can also be present in <detail> tag. This code will even write that tag to output.txt
XML File:
<record category="xyz">
<person ssn="" e-i="E">
<title xsi:nil="true"/>
<position xsi:nil="true"/>
<names>
<first_name/>
<last_name></last_name>
<aliases>
<alias>CDP</alias>
</aliases>
<keywords>
<keyword xsi:nil="true"/>
<keyword>SEARCH</keyword>
</keywords>
<external_sources>
<uri>http://www.google.com</uri>
<detail>SEARCH is present in abc for xyz reason</detail>
</external_sources>
</details>
</record>
<record category="abc">
<person ssn="" e-i="F">
<title xsi:nil="true"/>
<position xsi:nil="true"/>
<names>
<first_name/>
<last_name></last_name>
<aliases>
<alias>CDP</alias>
</aliases>
<keywords>
<keyword xsi:nil="true"/>
<keyword>DONTSEARCH</keyword>
</keywords>
<external_sources>
<uri>http://www.google.com</uri>
<detail>SEARCH is not present in abc for xyz reason</detail>
</external_sources>
</details>
</record>
Use GNU awk for multi-char RS:
$ awk -v RS='</record>\n' '{ORS=RT} /<keyword>SEARCH<\/keyword>/' file
<record category="xyz">
<person ssn="" e-i="E">
<title xsi:nil="true"/>
<position xsi:nil="true"/>
<names>
<first_name/>
<last_name></last_name>
<aliases>
<alias>CDP</alias>
</aliases>
<keywords>
<keyword xsi:nil="true"/>
<keyword>SEARCH</keyword>
</keywords>
<external_sources>
<uri>http://www.google.com</uri>
<detail>SEARCH is present in abc for xyz reason</detail>
</external_sources>
</details>
</record>
If you need to search for any of multiple keywords then simply list them as such:
$ awk -v RS='</record>\n' '{ORS=RT} /<keyword>(SEARCH1|SEARCH2|SEARCH3)<\/keyword>/' file
$ cat x.awk
/<record / { i=1 }
i { a[i++]=$0 }
/<\/record>/ {
if (found) {
for (i=1; i<=length(a); ++i) print a[i] > "output.txt"
}
i=0;
found=0
}
/<keyword>SEARCH<\/keyword>/ { found=1 }
$ awk -f x.awk x.xml
$ cat output.txt
<record category="xyz">
<person ssn="" e-i="E">
<title xsi:nil="true"/>
<position xsi:nil="true"/>
<names>
<first_name/>
<last_name></last_name>
<aliases>
<alias>CDP</alias>
</aliases>
<keywords>
<keyword xsi:nil="true"/>
<keyword>SEARCH</keyword>
</keywords>
<external_sources>
<uri>http://www.google.com</uri>
<detail>SEARCH is present in abc for xyz reason</detail>
</external_sources>
</details>
</record>
You seem to have cross posted this question from Unix & Linux - I give the same answer here as I did there:
I'm going to assume that what you've posted is a sample, because it isn't valid XML. If this assumption isn't valid, my answer doesn't hold... but if that is the case, you really need to hit the person who gave you the XML with a rolled up copy of the XML spec, and demand they 'fix it'.
But really - awk and regular expressions are not the right tool for the job. An XML parser is. And with a parser, it's absurdly simple to do what you want:
#!/usr/bin/env perl
use strict;
use warnings;
use XML::Twig;
#parse your file - this will error if it's invalid.
my $twig = XML::Twig -> new -> parsefile ( 'your_xml' );
#set output format. Optional.
$twig -> set_pretty_print('indented_a');
#iterate all the 'record' nodes off the root.
foreach my $record ( $twig -> get_xpath ( './record' ) ) {
#if - beneath this record - we have a node anywhere (that's what // means)
#with a tag of 'keyword' and content of 'SEARCH'
#print the whole record.
if ( $record -> get_xpath ( './/keyword[string()="SEARCH"]' ) ) {
$record -> print;
}
}
xpath is quite a lot like regular expressions - in some ways - but it's more like a directory path. That means it's context aware, and can handle XML structures.
In the above: ./ means 'below current node' so:
$twig -> get_xpath ( './record' )
Means any 'top level' <record> tags.
But .// means "at any level, below current node" so it'll do it recursively.
$twig -> get_xpath ( './/search' )
Would get any <search> nodes at any level.
And the square brackets denote a condition - that's either a function (e.g. text() to get the text of the node) or you can use an attribute. e.g. //category[#name] would find any category with a name attribute, and //category[#name="xyz"] would filter those further.
XML used for testing:
<XML>
<record category="xyz">
<person ssn="" e-i="E">
<title xsi:nil="true"/>
<position xsi:nil="true"/>
<details>
<names>
<first_name/>
<last_name></last_name>
</names>
<aliases>
<alias>CDP</alias>
</aliases>
<keywords>
<keyword xsi:nil="true"/>
<keyword>SEARCH</keyword>
</keywords>
<external_sources>
<uri>http://www.google.com</uri>
<detail>SEARCH is present in abc for xyz reason</detail>
</external_sources>
</details>
</person>
</record>
<record category="abc">
<person ssn="" e-i="F">
<title xsi:nil="true"/>
<position xsi:nil="true"/>
<details>
<names>
<first_name/>
<last_name></last_name>
</names>
<aliases>
<alias>CDP</alias>
</aliases>
<keywords>
<keyword xsi:nil="true"/>
<keyword>DONTSEARCH</keyword>
</keywords>
<external_sources>
<uri>http://www.google.com</uri>
<detail>SEARCH is not present in abc for xyz reason</detail>
</external_sources>
</details>
</person>
</record>
</XML>
Output:
<record category="xyz">
<person
e-i="E"
ssn="">
<title xsi:nil="true" />
<position xsi:nil="true" />
<details>
<names>
<first_name/>
<last_name></last_name>
</names>
<aliases>
<alias>CDP</alias>
</aliases>
<keywords>
<keyword xsi:nil="true" />
<keyword>SEARCH</keyword>
</keywords>
<external_sources>
<uri>http://www.google.com</uri>
<detail>SEARCH is present in abc for xyz reason</detail>
</external_sources>
</details>
</person>
</record>
Note - the above just prints the record to STDOUT. That's actually... in my opinion, not such a great idea. Not least because - it doesn't print the XML structure, and so it isn't actually 'valid' XML if you've more than one record (there's no "root" node).
So I would instead - to accomplish exactly what you're asking:
#!/usr/bin/env perl
use strict;
use warnings;
use XML::Twig;
my $twig = XML::Twig -> new -> parsefile ('your_file.xml');
$twig -> set_pretty_print('indented_a');
foreach my $record ( $twig -> get_xpath ( './record' ) ) {
if ( not $record -> findnodes ( './/keyword[string()="SEARCH"]' ) ) {
$record -> delete;
}
}
open ( my $output, '>', "output.txt" ) or die $!;
print {$output} $twig -> sprint;
close ( $output );
This instead - inverts the logic, and deletes (from the parsed data structure in memory) the records you don't want, and prints the whole new structure (including XML headers) to a new file called "output.txt".

Error cvc-elt.1.a: Cannot find the declaration of element 'soapenv:Body'

I have already tried some hints but I get this problem not solved. I validated the wsdl with xmlspy-client and it says it and the xsd are valid.
When I send a Request like this with SOAPUI I get the Exception mentioned (cvc-elt.1.a: Cannot find the declaration of element 'soapenv:Body').
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://schemas.domain.com/wsdl/fuelprice/v1" xmlns:mod="http://schemas.domain.com/wsdl/fuelprice/v1/model">
<soapenv:Header/>
<soapenv:Body>
<v1:AuthenticationHeader client="client">
<v1:token>token</v1:token>
</v1:AuthenticationHeader>
<v1:GetAreaFuelStationsRequest provider="p1" prices="true">
<v1:area>
<mod:center ellipsoid="false">
<mod:latitude>22.519172</mod:latitude>
<mod:longitude>13.406093</mod:longitude>
</mod:center>
<mod:radius>10</mod:radius>
</v1:area>
</v1:GetAreaFuelStationsRequest>
</soapenv:Body>
</soapenv:Envelope>
I have tried importing the soap schema in the wsdl. After it I got an error message:
"cvc-complex-type.2.4.a: Invalid content was found starting with element 'v1:latitude'. One of '{"http://schemas.domain.com/wsdl/fuelprice/v1/model":latitude}' is expected.".
I honestly work with rest and json and have some difficulties with this schema-configuration.
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="wsdl-viewer.xsl"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://schemas.domain.com/wsdl/fuelprice/v1" xmlns:model="http://schemas.domain.com/wsdl/fuelprice/v1/model" xmlns:exception="http://schemas.domain.com/wsdl/fuelprice/v1/exception" targetNamespace="http://schemas.domain.com/wsdl/fuelprice/v1">
<wsdl:types>
<xsi:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema" targetNamespace="http://schemas.domain.com/wsdl/fuelprice/v1" elementFormDefault="qualified">
<xsi:import namespace="http://schemas.domain.com/wsdl/fuelprice/v1/model" schemaLocation="common.xsd"/>
<xsi:import namespace="http://schemas.domain.com/wsdl/fuelprice/v1/exception" schemaLocation="exception.xsd"/>
<xsi:element name="GetAreaFuelStationsRequest">
<xsi:complexType>
<xsi:sequence>
<xsi:element name="area" type="model:Area"/>
</xsi:sequence>
<xsi:attribute name="provider" type="xsi:string" use="optional"/>
<xsi:attribute name="prices" type="xsi:boolean" use="required"/>
</xsi:complexType>
</xsi:element>
<xsi:element name="GetAreaFuelStationsResponse">
<xsi:complexType>
<xsi:sequence>
<xsi:element name="entry" type="model:SearchResult" minOccurs="0" maxOccurs="unbounded"/>
</xsi:sequence>
<xsi:attribute name="countTotal" type="xsi:int" use="optional"/>
</xsi:complexType>
</xsi:element>
</xsi:schema>
</wsdl:types>
<wsdl:message name="SearchAreaFuelStationsRequest">
<wsdl:part name="auth" element="tns:AuthenticationHeader"/>
<wsdl:part name="body" element="tns:GetAreaFuelStationsRequest"/>
</wsdl:message>
<wsdl:message name="SearchAreaFuelStationsResponse">
<wsdl:part name="body" element="tns:GetAreaFuelStationsResponse"/>
</wsdl:message>
<wsdl:portType name="FuelDataService">
<wsdl:operation name="GetAreaFuelStations">
<wsdl:input message="tns:GetAreaFuelStationsRequest"/>
<wsdl:output message="tns:GetAreaFuelStationsResponse"/>
<wsdl:fault name="ServiceError" message="tns:ServiceErrorFault"/>
<wsdl:fault name="AuthenticationError" message="tns:AuthenticationErrorFault"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="FuelDataService" type="tns:FuelDataService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetAreaFuelStations">
<soap:operation soapAction="urn:GetAreaFuelStations"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="ServiceError"/>
<wsdl:fault name="AuthenticationError"/>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="FuelDataService">
<wsdl:port name="FuelDataService" binding="tns:FuelDataService">
<soap:address location="No target address"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
The XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xsi:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema" xmlns:model="http://schemas.domain.com/wsdl/fuelprice/v1/model" targetNamespace="http://schemas.domain.com/wsdl/fuelprice/v1/model" elementFormDefault="qualified">
<xsi:complexType name="FuelStation">
<xsi:sequence>
<xsi:element name="location" type="model:GeoLocation"/>
<xsi:element name="name" type="xsi:string"/>
</xsi:sequence>
<xsi:attribute name="id" type="xsi:long" use="optional"/>
</xsi:complexType>
<xsi:complexType name="GeoLocation">
<xsi:sequence>
<xsi:element name="latitude" type="xsi:double"/>
<xsi:element name="longitude" type="xsi:double"/>
</xsi:sequence>
<xsi:attribute name="ellipsoid" type="xsi:string" use="required"/>
</xsi:complexType>
<xsi:complexType name="Area">
<xsi:sequence>
<xsi:element name="center" type="model:GeoLocation"/>
<xsi:element name="radius" type="xsi:float"/>
</xsi:sequence>
</xsi:complexType>
</xsi:schema>
For me is not obvious what I should change to get this working. Does anybody knows what is wrong with the namespace setting? I would appreciate any help.
This Question was solved with the Question validating SOAP-Request with a SOAPHandler
Extracting the body of message, adding the needed namespace in the schema and validating the body as a Document did the trick.

Using WSO2 ESB PassThrough Proxy on WebLogic (Spring) Web Service

I have tried PassThroughu proxy tutorials and all works with build in example where Target Web Service is deployed on Axis (Apache CFX). Source and Proxy Web Service nicely gets tested using "TryIt" on WSO2 ESB.
Now different story - I try to achieve the same using very simple Weblogic Spring Web Service (i don't believe usage of Spring and bottom-up approach and annotations matter). It's deployed on the WebLogic server (running on the same host as WSO2 ESB). No any special WS-* extension included. It's almost hello world web service. I can easily test test it SoapUi, UniversalTestClient (WebLogic) and see WSDL in browser.
Regarding generated proxy PassThrough Web Service (followed same steps from tutorial) I can also see generated WSDL:
http://localhost:8280/services/WebServiceAServicePassThroughProxy?wsdl
However neither SoapUI nor TryIt work and both return FaultString:
The endpoint reference (EPR) for the Operation not found is /services/WebServiceAServicePassThroughProxy.WebServiceAServicePassThroughProxyHttpSoap11Endpoint and the WSA Action = . If this EPR was previously reachable, please contact the server administrator.
Here is function I used for testing "findContactById":
<body>
<p:findContactById xmlns:p="http://webservicea.testtoold.xx.yy.zz.eu/">
<!--Exactly 1 occurrence-->
<arg0>1</arg0>
</p:findContactById>
</body>
which operates on Proxy Web Service. I tried all endpoints that were generated in proxy web service, error is same as above unless if I try httpEndpoint from drop down:
http://localhost:8280/services/WebServiceAServicePassThroughProxy.WebServiceAServicePassThroughProxyHttpEndpoint
then I get Unsupported Media Type as TryItProxyError.
Anyone please help, I am getting nuts with this... should be simple, not the nightmare. Searched all web i saw few similar questions with no answers.
WebLogic Service WSDL:
<?xml version='1.0' encoding='UTF-8'?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.8-b13937 svn-revision#13942. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.8-b13937 svn-revision#13942. --><definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://webservicea.testtoold.xx.yy.zz.eu/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://webservicea.testtoold.xx.yy.zz.eu/" name="WebServiceAService">
<types>
<xsd:schema>
<xsd:import namespace="http://webservicea.testtoold.xx.yy.zz.eu/" schemaLocation="http://localhost:7001/TestToolD/WebServiceAService?xsd=1"/>
</xsd:schema>
</types>
<message name="findContactById">
<part name="parameters" element="tns:findContactById"/>
</message>
<message name="findContactByIdResponse">
<part name="parameters" element="tns:findContactByIdResponse"/>
</message>
<message name="Exception">
<part name="fault" element="tns:Exception"/>
</message>
<message name="findAllContacts">
<part name="parameters" element="tns:findAllContacts"/>
</message>
<message name="findAllContactsResponse">
<part name="parameters" element="tns:findAllContactsResponse"/>
</message>
<portType name="WebServiceA">
<operation name="findContactById">
<input wsam:Action="http://webservicea.testtoold.xx.yy.zz.eu/WebServiceA/findContactByIdRequest" message="tns:findContactById"/>
<output wsam:Action="http://webservicea.testtoold.xx.yy.zz.eu/WebServiceA/findContactByIdResponse" message="tns:findContactByIdResponse"/>
<fault message="tns:Exception" name="Exception" wsam:Action="http://webservicea.testtoold.xx.yy.zz.eu/WebServiceA/findContactById/Fault/Exception"/>
</operation>
<operation name="findAllContacts">
<input wsam:Action="http://webservicea.testtoold.xx.yy.zz.eu/WebServiceA/findAllContactsRequest" message="tns:findAllContacts"/>
<output wsam:Action="http://webservicea.testtoold.xx.yy.zz.eu/WebServiceA/findAllContactsResponse" message="tns:findAllContactsResponse"/>
<fault message="tns:Exception" name="Exception" wsam:Action="http://webservicea.testtoold.xx.yy.zz.eu/WebServiceA/findAllContacts/Fault/Exception"/>
</operation>
</portType>
<binding name="WebServiceAPortBinding" type="tns:WebServiceA">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="findContactById">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
<fault name="Exception">
<soap:fault name="Exception" use="literal"/>
</fault>
</operation>
<operation name="findAllContacts">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
<fault name="Exception">
<soap:fault name="Exception" use="literal"/>
</fault>
</operation>
</binding>
<service name="WebServiceAService">
<port name="WebServiceAPort" binding="tns:WebServiceAPortBinding">
<soap:address location="http://localhost:7001/TestToolD/WebServiceAService"/>
</port>
</service>
</definitions>
WSO ESB Generated PassThroughProxy.wsdl
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:tns="http://webservicea.testtoold.xx.yy.zz.eu/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://webservicea.testtoold.xx.yy.zz.eu/">
<wsdl:types>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="unqualified">
<xsd:import namespace="http://webservicea.testtoold.xx.yy.zz.eu/" schemaLocation="WebServiceAServicePassThroughProxy?xsd=http://localhost:7001/TestToolD/WebServiceAService?xsd=1.xsd"></xsd:import>
</xsd:schema>
</wsdl:types>
<wsdl:message name="findContactById">
<wsdl:part name="parameters" element="tns:findContactById"></wsdl:part>
</wsdl:message>
<wsdl:message name="findContactByIdResponse">
<wsdl:part name="parameters" element="tns:findContactByIdResponse"></wsdl:part>
</wsdl:message>
<wsdl:message name="findAllContacts">
<wsdl:part name="parameters" element="tns:findAllContacts"></wsdl:part>
</wsdl:message>
<wsdl:message name="findAllContactsResponse">
<wsdl:part name="parameters" element="tns:findAllContactsResponse"></wsdl:part>
</wsdl:message>
<wsdl:portType name="WebServiceAServicePassThroughProxyPortType">
<wsdl:operation name="findContactById">
<wsdl:input message="tns:findContactById"></wsdl:input>
<wsdl:output message="tns:findContactByIdResponse" wsaw:Action="http://webservicea.testtoold.xx.yy.zz.eu/WebServiceA/findContactByIdResponse"></wsdl:output>
<wsdl:fault message="tns:Exception" name="Exception" wsaw:Action="http://webservicea.testtoold.xx.yy.zz.eu/WebServiceA/findContactById/Fault/Exception"></wsdl:fault>
</wsdl:operation>
<wsdl:operation name="findAllContacts">
<wsdl:input message="tns:findAllContacts"></wsdl:input>
<wsdl:output message="tns:findAllContactsResponse" wsaw:Action="http://webservicea.testtoold.xx.yy.zz.eu/WebServiceA/findAllContactsResponse"></wsdl:output>
<wsdl:fault message="tns:Exception" name="Exception" wsaw:Action="http://webservicea.testtoold.xx.yy.zz.eu/WebServiceA/findAllContacts/Fault/Exception"></wsdl:fault>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="WebServiceAServicePassThroughProxySoap11Binding" type="tns:WebServiceAServicePassThroughProxyPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding>
<wsdl:operation name="findContactById">
<soap:operation soapAction="" style="document"></soap:operation>
<wsdl:input>
<soap:body use="literal"></soap:body>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"></soap:body>
</wsdl:output>
<wsdl:fault name="Exception">
<soap:fault use="literal" name="Exception"></soap:fault>
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="findAllContacts">
<soap:operation soapAction="" style="document"></soap:operation>
<wsdl:input>
<soap:body use="literal"></soap:body>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"></soap:body>
</wsdl:output>
<wsdl:fault name="Exception">
<soap:fault use="literal" name="Exception"></soap:fault>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="WebServiceAServicePassThroughProxySoap12Binding" type="tns:WebServiceAServicePassThroughProxyPortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap12:binding>
<wsdl:operation name="findContactById">
<soap12:operation soapAction="" style="document"></soap12:operation>
<wsdl:input>
<soap12:body use="literal"></soap12:body>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"></soap12:body>
</wsdl:output>
<wsdl:fault name="Exception">
<soap12:fault use="literal" name="Exception"></soap12:fault>
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="findAllContacts">
<soap12:operation soapAction="" style="document"></soap12:operation>
<wsdl:input>
<soap12:body use="literal"></soap12:body>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"></soap12:body>
</wsdl:output>
<wsdl:fault name="Exception">
<soap12:fault use="literal" name="Exception"></soap12:fault>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="WebServiceAServicePassThroughProxyHttpBinding" type="tns:WebServiceAServicePassThroughProxyPortType">
<http:binding verb="POST"></http:binding>
<wsdl:operation name="findContactById">
<http:operation location="findContactById"></http:operation>
<wsdl:input>
<mime:content type="text/xml" part="parameters"></mime:content>
</wsdl:input>
<wsdl:output>
<mime:content type="text/xml" part="parameters"></mime:content>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="findAllContacts">
<http:operation location="findAllContacts"></http:operation>
<wsdl:input>
<mime:content type="text/xml" part="parameters"></mime:content>
</wsdl:input>
<wsdl:output>
<mime:content type="text/xml" part="parameters"></mime:content>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="WebServiceAServicePassThroughProxy">
<wsdl:port name="WebServiceAServicePassThroughProxyHttpsSoap11Endpoint" binding="tns:WebServiceAServicePassThroughProxySoap11Binding">
<soap:address location="https://supercomputer:8243/services/WebServiceAServicePassThroughProxy.WebServiceAServicePassThroughProxyHttpsSoap11Endpoint"></soap:address>
</wsdl:port>
<wsdl:port name="WebServiceAServicePassThroughProxyHttpSoap11Endpoint" binding="tns:WebServiceAServicePassThroughProxySoap11Binding">
<soap:address location="http://supercomputer:8280/services/WebServiceAServicePassThroughProxy.WebServiceAServicePassThroughProxyHttpSoap11Endpoint"></soap:address>
</wsdl:port>
<wsdl:port name="WebServiceAServicePassThroughProxyHttpSoap12Endpoint" binding="tns:WebServiceAServicePassThroughProxySoap12Binding">
<soap12:address location="http://supercomputer:8280/services/WebServiceAServicePassThroughProxy.WebServiceAServicePassThroughProxyHttpSoap12Endpoint"></soap12:address>
</wsdl:port>
<wsdl:port name="WebServiceAServicePassThroughProxyHttpsSoap12Endpoint" binding="tns:WebServiceAServicePassThroughProxySoap12Binding">
<soap12:address location="https://supercomputer:8243/services/WebServiceAServicePassThroughProxy.WebServiceAServicePassThroughProxyHttpsSoap12Endpoint"></soap12:address>
</wsdl:port>
<wsdl:port name="WebServiceAServicePassThroughProxyHttpsEndpoint" binding="tns:WebServiceAServicePassThroughProxyHttpBinding">
<http:address location="https://supercomputer:8243/services/WebServiceAServicePassThroughProxy.WebServiceAServicePassThroughProxyHttpsEndpoint"></http:address>
</wsdl:port>
<wsdl:port name="WebServiceAServicePassThroughProxyHttpEndpoint" binding="tns:WebServiceAServicePassThroughProxyHttpBinding">
<http:address location="http://supercomputer:8280/services/WebServiceAServicePassThroughProxy.WebServiceAServicePassThroughProxyHttpEndpoint"></http:address>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Few minor remarks:
differences in localhost and supercomputer can't be the cause - tutorials work well with such diffs
i tried lots of things (creating endpoint in registry, or locally, providing WSDL or not when creating proxy, etc etc, but I always get the identical error).
i have cut out 30% lines of code to simplify WSDL (save and delete functions) to reach allowed size of post.
tried adding action names but no difference (kept example without them)
Since ESB 4.6, pass-through transport is enabled by default : The message body is not build so, SOAP Body based dispatching is not supported (can't use the first child node of SOAP body element to determine the operation).
The error in this case is The endpoint reference (EPR) for the Operation not found is...
In your case, you can't use SOAPAction (it's blank), but you can :
append the operation name to the endpoint URL
Or, since ESB 4.8 :
add this parameter in the proxy conf : <parameter name="disableOperationValidation" locked="false">true</parameter>
modify axis2.xml conf in repository/conf/axis2 replacing
<handler class="org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher" name="SOAPMessageBodyBasedDispatcher"/>
with
<handler class="org.apache.synapse.core.axis2.SynapseSOAPMessageBodyBasedDispatcher" name="SOAPMessageBodyBasedDispatcher"/>

How to assign array in a BPEL process

I have a simple string as input and after calling a web service which adds the string to an array.Now i have to assign the array to the output(which i have set as a string array in the schema).The enterprise manager gives a fault and says the result contains multiple nodes for the XPath expression given.The Assign activity is shown as pending.So basically how do i assign an array or a list to the output variable which is also set as an array.The wsdl file used is:
<?xml version = '1.0' encoding = 'UTF-8'?>
<definitions
name="ReturnTypeService"
targetNamespace="http://examples2/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://examples2/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
>
<types>
<xsd:schema>
<xsd:import namespace="http://examples2/" schemaLocation="http://localhost:7101/Examples2-Examples2-context-root/ReturnTypePort?xsd=1"/>
</xsd:schema>
</types>
<message name="display">
<part name="parameters" element="tns:display"/>
</message>
<message name="displayResponse">
<part name="parameters" element="tns:displayResponse"/>
</message>
<portType name="ReturnType">
<operation name="display">
<input message="tns:display"/>
<output name="displayResponse"
message="tns:displayResponse"/>
</operation>
</portType>
<binding name="ReturnTypePortBinding" type="tns:ReturnType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="display">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="ReturnTypeService">
<port name="ReturnTypePort" binding="tns:ReturnTypePortBinding">
<soap:address location="http://localhost:7101/Examples2-Examples2-context-root/ReturnTypePort"/>
</port>
</service>
</definitions>
#vanto Is there a way to assign an array from input variable to invoke_input variable?The problem is there are multiple inputs in my web service so i am not able to copy the wrapping element in input variable to wrapping variable in invoke variable.Will copy the snippet of the code here :
<assign name="Assign1">
<copy>
<from variable="inputVariable" part="payload"
query="/ns2:process/ns2:dsaName"/>
<to variable="Invoke1_processList_InputVariable"
part="parameters" query="/ns1:processList/dsaName"/>
</copy>
<copy>
<from variable="inputVariable" part="payload"
query="/ns2:process/ns2:linesOfData"/>
<to variable="Invoke1_processList_InputVariable"
part="parameters" query="/ns1:processList/linesOfData"/>
</copy>
<copy>
<from variable="inputVariable" part="payload"
query="/ns2:process/ns2:description"/>
<to variable="Invoke1_processList_InputVariable"
part="parameters" query="/ns1:processList/description"/>
</copy>
<copy>
<from variable="inputVariable" part="payload"
query="/ns2:process/ns2:application"/>
<to variable="Invoke1_processList_InputVariable"
part="parameters" query="/ns1:processList/application"/>
</copy>
</assign>
The problem is only one is of list type all others are of string type.The XML for this is:
<element name="process">
<complexType>
<sequence>
<element name="dsaName" type="string" minOccurs="0"/>
<element name="linesOfData" type="string" minOccurs="0" maxOccurs="unbounded"/>
<element name="description" type="string" minOccurs="0"/>
</sequence>
</complexType>
</element>
<element name="processResponse">
<complexType>
<sequence>
<element name="result" type="string" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>
</schema>
A from-spec and to-spec must not select more than one element or attribute. In your case it appears to select all <return> elements in your variable's part (i.e. the items of the array). Try to copy the element that wraps the items (i.e. the ns1:displayResponse element) and copy this element to ns2:processResponse (the wrapping element in the to-variable).
Since both source and target elements seem to be in different namespaces and are of different types, you probably need to run it through an XSLT script (using doXSLTransform) to translate it from the source schema to the target schema.

Resources