Currently my WSDLhas <xs:schema attributeFormDefault="unqualified" elementFormDefault="unqualified"
I want o make it as <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
Can some one tell the way to achieve it.
Thanks.
Example 2 in this can help you. You have to specify the annotation something like:
xmlns = { #javax.xml.bind.annotation.XmlNs(prefix = "po",
namespaceURI="http://www.example.com/myPO1") }
in #XmlSchema or wherever you provide the schema config.
EDIT :
Also, let me show you two examples of XML Schemas:
In the first case, XML namespace is prefixed with wsdl. This is an example of qualified.
<wsdl:definitions xmlns:wsdl='http://www.w3.org/2002/06/wsdl' >
<wsdl:message />
</wsdl:definitions>
However, in this case, XML namespace is not prefixed. This is an example of unqualified.
<definitions xmlns='http://www.w3.org/2002/06/wsdl' >
<message />
</definitions>
Related
I'm trying to generate the java files from XSD with use of jaxb2-maven-plugin. This works without any issues and I can see generated classes in target directory.
Now I decided to let all generated classes implement some interface. So I set up bindings.xjb file where I'm defining the interface. The issue is the plugin can not recognize correct namespace which defines inheritance.
Unsupported binding namespace "http://jaxb2-commons.dev.java.net/basic/inheritance". Perhaps you meant "http://jaxb.dev.java.net/plugin/code-injector"?
I think code-injector is not what I'm looking for, since this allow to define custom pieces of code to add to generated file.
I'm trying to use latest maven plugin:
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>3.1.0</version>
The bindings.xjb file contains following content:
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
jaxb:extensionBindingPrefixes="inheritance"
version="3.0">
<jaxb:bindings schemaLocation="application.xsd" node="/xs:schema">
<jaxb:bindings node="//xs:complexType[#name='applicationType']">
<inheritance:implements>com.example.SomeInterface</inheritance:implements>
<jaxb:property name="inheritance"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
And the application.xsd file:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="application" type="applicationType"/>
<xs:complexType name="applicationType">
<xs:sequence>
<xs:element type="xs:string" name="language"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
I have found this namespace xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance" on the internet.
Also notice plugin requires version 3.0 of bindings.xjb file.
What is the correct definition of namespace to let plugin generate classes with interface?
In my project, classes are generated by wsdl. One of these classes is User class. This class must be Serializable. How can I change my pom.xml file for making User Serializable?
I can find example but can't apply it to my project
https://pragmaticintegrator.wordpress.com/2009/03/14/make-serializable-jax-ws-clients-with-maven2/
Finally I could find answer for my question. In our project we use org.apache.cxf plugin to generate classes. I created binding.xml file in resources folder.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
elementFormDefault="qualified" attributeFormDefault="unqualified"
jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.1">
<xs:annotation>
<xs:appinfo>
<jaxb:globalBindings>
<xjc:serializable uid="1337" />
</jaxb:globalBindings>
</xs:appinfo>
</xs:annotation>
</xs:schema>
Then I referenced to this xml file from my pom.xml, for this I added
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/binding.xml</bindingFile>
</bindingFiles>
under wsdlOptions/wsdlOption tag. That's all
I'm using maven-jaxb2-plugin for generating java files from wsdl one. After running "generate-sources" goal I get the following error
[ERROR] Error while parsing schema(s).Location[
file:/home/*/src/main/resources/soap/binding.xjb{8,30} ].
com.sun.istack.SAXParseException2; systemId: file:/home/*/src/main/resources/soap/binding.xjb; lineNumber: 8; columnNumber: 30;
Multiple <schemaBindings> are defined for the target namespace "http://schemas.***"
There are several wsdl files and for each of them I need different target package, so I tried using binding file, but for only 1 wsdl for now.
Here is my plugin configuraiton
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<schemaDirectory>
${basedir}/src/main/resources/soap
</schemaDirectory>
<schemaIncludes>
<include>manager/*.wsdl</include>
</schemaIncludes>
<bindingDirectory>
${basedir}/src/main/resources/soap
</bindingDirectory>
</configuration>
Here is binding.xjb file
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
version="2.1"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jaxb:bindings schemaLocation="manager/service.wsdl" multiple="true" node="//xs:schema">
<jaxb:schemaBindings>
<jaxb:package name="com.test.manager"/>
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
Beginning of service.wsdl file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:sch0="http://schemas.***"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://schemas.***"
targetNamespace="http://schemas.***">
<wsdl:types>
<xs:schema xmlns="http://schemas.***"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://schemas.***">
<xs:simpleType name="NumericReference">
***
</xs:simpleType>
<xs:simpleType name="EntityNumber">
***
</xs:simpleType>
</xs:schema>
<xs:schema xmlns="http://schemas.***"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://schemas.***">
<xs:complexType name="DisplayGroup">
Looks like the problem is connected with multiple xs:schema elements with same targetNamespace, but I can't find how to fix it without modifying wsdl.
JAXB typically maps one target namespace onto one package, so you can't specify different schemaBindings for the same target namespace.
I have an XSD where use types of another XSDs , exemple:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
targetNamespace="http://www.tce.sp.gov.br/audesp/xml/tagcomum" version="1.0" xml:lang="pt-BR"
xmlns:tag="http://www.tce.sp.gov.br/audesp/xml/tagcomum"
xmlns:gen="http://www.tce.sp.gov.br/audesp/xml/generico"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://www.tce.sp.gov.br/audesp/xml/generico"
schemaLocation="../generico/AUDESP_TIPOSGENERICOS_2016_A.XSD"/>
How to make a JAXB code generator understand that a reference to another ?
my tentatives were frustrated by not filenotfound errors
I am pretty new to xsds, and currently the xsd I am using is only validating on some machines. It works on my local machine, but when I try doing this on a machine where there are some proxies or firewalls, it no longer works. The schemas I am using are used locally, though.
Here is the error I get when the xsd schema is attempting to validate:
src-resolve: Cannot resolve the name 'xenc:EncryptedDataType' to a(n)
'type definition' component.
Which comes from this code:
boolean validate(URL schemaUrl) {
SchemaFactory schemaFactory = SchemaFactory
.newInstance("http://www.w3.org/2001/XMLSchema");
Schema schema = null;
try {
schema = schemaFactory.newSchema(schemaUrl); //this is where the exception is thrown
} catch (SAXException e) {
//exception is caught here
return false;
}
//... more code here
}
The error has the same stack trace as this one:
SAXParseException; src-resolve: Cannot resolve the name '...' to a(n) 'type definition' component
I have my main xsd that begins something like this:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:tns="http://customization.elster.com/shipment"
targetNamespace="http://customization.client.com/introduction"
attributeFormDefault="unqualified"
elementFormDefault="qualified"
version="1.1" >
<xs:import namespace="http://www.w3.org/2001/04/xmlenc#" schemaLocation="xenc-schema.xsd"/>
<xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd"/>
in this main XML I need the "xenc:EncryptedDataType"
<xs:complexType name="NamedEncryptedDataType">
<xs:complexContent>
<xs:extension base="xenc:EncryptedDataType">
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
which is defined in the xenc-schema.xsd (which is in the same folder as my main xsd)
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE schema PUBLIC "-//W3C//DTD XMLSchema 200102//EN"
"http://www.w3.org/2001/XMLSchema.dtd"
[
<!ATTLIST schema
xmlns:xenc CDATA #FIXED 'http://www.w3.org/2001/04/xmlenc#'
xmlns:ds CDATA #FIXED 'http://www.w3.org/2000/09/xmldsig#'>
<!ENTITY xenc 'http://www.w3.org/2001/04/xmlenc#'>
<!ENTITY % p ''>
<!ENTITY % s ''>
]>
<schema xmlns='http://www.w3.org/2001/XMLSchema' version='1.0'
xmlns:xenc='http://www.w3.org/2001/04/xmlenc#'
xmlns:ds='http://www.w3.org/2000/09/xmldsig#'
targetNamespace='http://www.w3.org/2001/04/xmlenc#'
elementFormDefault='qualified'>
<import namespace='http://www.w3.org/2000/09/xmldsig#'
schemaLocation='xmldsig-core-schema.xsd'/>
in this xenc-schema, there is the culprit data type:
<element name='EncryptedData' type='xenc:EncryptedDataType'/>
<complexType name='EncryptedDataType'>
<complexContent>
<extension base='xenc:EncryptedType'>
</extension>
</complexContent>
</complexType>
I've tried to keep this question shorter, let me know if more information is needed, thanks for reading.
The best way to diagnose these sort of problems is to install an HTTP debugger. For e.g., Fiddler is a good one that should work for you. It should tell you what resource is resolved externally (on the Internet).
In your case, most likely the culprit is the DTD in your xenc-schema.xsd file. To quickly prove it, simply get rid of any embedded DTDs. Once you prove the issue, you may choose to simply keep the edited XSDs, or use a custom EntityResolver, or see if your particular library has some sort of property you can set to disable DTD processing (which is really useless here).