JAXB2 parsing WSDL containing soap encoded type - maven

I have a problem with jaxb2 in my spring WS.
the Spring ws has to parse a wsdl file (no xsd) containing soap encoded types (Array).What maven plugin can i use to be able to marshall the wsdl file with JAXB2?
Here is the wsdl file:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://xml.cibg.org/irisbox/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:impl="http://xml.cibg.org/irisbox/" xmlns:intf="http://xml.cibg.org/irisbox/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
<wsdl:types>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://xml.cibg.org/irisbox/">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="soap-encoding.xsd"/>
<xsd:complexType name="ArrayOf_xsd_anyType">
<xsd:complexContent>
<xsd:restriction base="soapenc:Array">
<xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:anyType[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="ExternalIdsResponse">
<xsd:sequence>
<xsd:element name="externalIdsResponse" nillable="true" type="impl:ArrayOf_xsd_anyType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<message name="getExternalIdsRequest">
<part name="organizationCode" type="xsd:string"/>
<part name="externalModuleName" type="xsd:string"/>
<part name="fromDate" type="xsd:dateTime"/>
<part name="toDate" type="xsd:dateTime"/>
</message>
<message name="getExternalIdsResponse">
<part name="getExternalIdsReturn" type="impl:ExternalIdsResponse"/>
</message>
<portType name="ExternalIdsService">
<operation name="getExternalIds" parameterOrder="organizationCode externalModuleName fromDate toDate">
<input name="getExternalIdsRequest" message="impl:getExternalIdsRequest"/>
<output name="getExternalIdsResponse" message="impl:getExternalIdsResponse"/>
</operation>
</portType>
<binding name="ExternalIdsSoapBinding" type="impl:ExternalIdsService">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getExternalIds">
<wsdlsoap:operation soapAction=""/>
<input name="getExternalIdsRequest">
<wsdlsoap:body use="encoded" namespace="http://xml.cibg.org/irisbox/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output name="getExternalIdsResponse">
<wsdlsoap:body use="encoded" namespace="http://xml.cibg.org/irisbox/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="ExternalIdsServiceService">
<port name="ExternalIds" binding="impl:ExternalIdsSoapBinding">
<wsdlsoap:address location="http://172.31.50.155:8988/irisbox/anonymous/services/ExternalIds"/>
</port>
</service>
</wsdl:definitions>

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

undefined complextype is used as a base for complex type extension

What is the problem in my WSDL file? The Visual Studio complains about an undefined complex type.
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns1="http://osmc.synium.com/services/presence" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns2="http://types.osqq.syqq.com" xmlns:impl="com.syqq.osqq.services.presence" xmlns:intf="com.syqq.osqq.services.presence" targetNamespace="com.syqq.osqq.services.presence" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://types.osqq.syqq.com">
<xsd:import namespace="http://osqq.syqq.com/services/presence" />
<xsd:import namespace="com.syqq.osqq.services.presence" />
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<xsd:complexType name="SoapBinaryMessage" abstract="true">
<xsd:sequence>
<xsd:element name="data64" nillable="true" type="xsd:string" />
<xsd:element name="version" nillable="true" type="xsd:int" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://osmc.synium.com/services/presence">
<xsd:import namespace="com.syqq.osqq.services.presence" />
<xsd:import namespace="http://types.osqq.syqq.com" />
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<xsd:complexType name="PresenceStatusBinary">
<xsd:complexContent mixed="false">
<xsd:extension base="tns2:SoapBinaryMessage">
<xsd:sequence />
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>
...
</wsdl:types>
Any ideas?
The problem occurs in line xsd:extension base="tns2:SoapBinaryMessage
You're missing the prefix declaration for tns2; this needs to be added somewhere such that it'll be in scope for the <xsd:extension base="tns2:SoapBinaryMessage"> node (the best place as far as I am concerned might be the second xsd:schema declaration):
xmlns:tns2="http://types.osqq.syqq.com"

xsd validation in CodeIgniter

I am using CodeIgniter, and I want to validate xml with below xsd
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xsd:simpleType name="non_empty_string">
<xsd:restriction base="xsd:string">
<xsd:minLength value="1" />
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="xml">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="item">
<xsd:simpleType>
<xsd:union memberTypes="non_empty_string xsd:integer"/>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
when I am trying to validate xml against this xsd, only first member type is getting validated (non_empty_string ), not the second one, any guess why this is happening. Thank you.
You can use XMLReader to validate your XML against xsd file.
refer this link for more information
http://de.php.net/manual/en/xmlreader.setschema.php

Oracle Service Bus (11.1.1.6.0): <xsd:include> issue

IF I use this schema:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xsd:element name="Chick">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="count" type="xsd:decimal" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
With this wsdl:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.example.org/test/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="test"
xmlns:chi="chick"
targetNamespace="http://www.example.org/test/">
<wsdl:types>
<xsd:schema targetNamespace="http://www.example.org/test/">
<xsd:include schemaLocation="testschema.xsd"></xsd:include>
<xsd:include id="ada" schemaLocation="testschema.xsd" />
<xsd:element name="doTheRightThing">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Chick" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="doTheRightThingResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="out" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="doTheRightThingRequest">
<wsdl:part element="tns:doTheRightThing" name="parameters" />
</wsdl:message>
<wsdl:message name="doTheRightThingResponse">
<wsdl:part element="tns:doTheRightThingResponse" name="parameters" />
</wsdl:message>
<wsdl:portType name="test">
<wsdl:operation name="doTheRightThing">
<wsdl:input message="tns:doTheRightThingRequest" />
<wsdl:output message="tns:doTheRightThingResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="testSOAP" type="tns:test">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="doTheRightThing">
<soap:operation
soapAction="http://www.example.org/test/doTheRightThing" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="test">
<wsdl:port binding="tns:testSOAP" name="testSOAP">
<soap:address location="http://www.example.org/" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
I get this error message:
Error building the Schema Type system for the WSDL:
D:\Oracle\Middleware_11.1.1.6.0\user_projects\domains\osb_cookbook_domain\test:0: error: src-resolve.a: Could not find element 'Chick'. Do you mean to refer to the element named Chick#http://www.example.org/test/ (in testschema)?
If I change this line in wsdl:
<xsd:element ref="Chick" />
to this:
<xsd:element ref="tns:Chick" />
I could not deploy, OEPE returns this error message:
The WSDL is not semantically valid: error: src-resolve: element 'Chick#http://www.example.org/test/' not found..
Is this a bug?
Patch 14003546 solved this issue:
WSDL WITH EMBEDDED SCHEMA INCLUDE TO NO-NAMESPACE FAILS VALIDATION

Validating XML: No matching global declaration available for the validation root

I'm trying to validate the following XML against a XSD schema using Ruby.
It simply won't work, stops with an error message telling me
Error: Element 'request': No matching global declaration available for the validation root.
Maybe it's the namespace? Any ideas?
XML
<?xml version="1.0" encoding="UTF-8"?>
<request type="test" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<channel name="channel">
<username>user</username>
<password>pass</password>
</channel>
<hotel id="1">
<date from="2009-07-07" to="2009-07-17"/>
<room id="1">
<allocation>10</allocation>
</room>
</hotel>
</request>
XSD
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- channel -->
<xsd:element name="channel">
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:sequence>
<xsd:element username="name" use="required" type="xsd:string"/>
<xsd:element password="country" use="required" type="xsd:string"/>
</xsd:sequence>
</xsd:element>
<!-- hotel -->
<xsd:element name="hotel">
<xsd:attribute name="id" use="required" type="xsd:string" />
<xsd:sequence>
<xsd:element name="hotel">
<xsd:attribute name="from" use="required" type="xsd:string" />
<xsd:attribute name="to" use="required" type="xsd:string" />
</xsd:element>
<xsd:element ref="room" minOccurs="1"/>
</xsd:sequence>
</xsd:element>
<!-- room -->
<xsd:element name="room">
<xsd:sequence>
<xsd:element name="allocation" type="xsd:string"></xsd:element>
<xsd:element ref="hotel" minOccurs="1"/>
</xsd:sequence>
<xsd:attribute name="id" use="required" type="xsd:string" />
</xsd:element>
<!-- building all together -->
<xsd:element name="request">
<xsd:attribute name="type" use="required" type="xsd:string" />
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="channel" maxOccurs="1"/>
<xsd:element ref="hotel" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Ruby code
require "xml"
document = LibXML::XML::Document.file("/tmp/test.xml")
schema = LibXML::XML::Document.file("/tmp/request.xsd")
result = document.validate_schema(schema) do |message,flag|
log.debug(message)
puts message
end
It's a cryptic error, but it's probably because your XSD is malformed. For example, the contents of the channel, hotel (both the inner and outer elements), room, and request xsd:element tags should all be wrapped in xsd:complexType tags. Also, use is only valid on xsd:attribute, not xsd:element. For elements, use minOccurs and maxOccurs (although both default to 1, so they aren't actually necessary in this case). In addition, your outer hotel element contains a room element, which must contain a hotel element, creating an infinite loop. Further, you don't name your username and password elements properly. Finally, that inner hotel element should probably be date. Here's what I think you're looking for:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- channel -->
<xsd:element name="channel">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="username" type="xsd:string"/>
<xsd:element name="password" type="xsd:string"/>
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<!-- hotel -->
<xsd:element name="hotel">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="date">
<xsd:complexType>
<xsd:attribute name="from" use="required" type="xsd:string" />
<xsd:attribute name="to" use="required" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element ref="room" minOccurs="1"/>
</xsd:sequence>
<xsd:attribute name="id" use="required" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<!-- room -->
<xsd:element name="room">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="allocation" type="xsd:string"></xsd:element>
</xsd:sequence>
<xsd:attribute name="id" use="required" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<!-- building all together -->
<xsd:element name="request">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="channel" maxOccurs="1"/>
<xsd:element ref="hotel" maxOccurs="1"/>
</xsd:sequence>
<xsd:attribute name="type" use="required" type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:schema>
Just shooting from the hip here, but have you tried converting the XML::Document holding the schema into an XML::Schema?
http://libxml.rubyforge.org/rdoc/classes/LibXML/XML/Schema.html
I don't know that it would make a difference, but it's worth a shot.
I received the same cryptic error message for a different reason.
The first line of my schema file had an unprefixed namespace:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.sec.gov/edgar/document/thirteenf/informationtable" xmlns:ns1="http://www.sec.gov/edgar/common" targetNamespace="http://www.sec.gov/edgar/document/thirteenf/informationtable" elementFormDefault="qualified" attributeFormDefault="unqualified">
Note the 'xmlns=' attribute. This placed all the elements declared in the schema into the namespace http://www.sec.gov/edgar/document/thirteenf/informationtable (unless otherwise specified with a namespace prefix). But the XML file that I was trying to validate did not have a matching unprefixed/default namespace:
<informationTable xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
So its elements didn't match the schema because they were in "different" namespaces. I hope this is useful to others.

Resources