How to make java class Serializable which is generated by wsdl - java

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

Related

JAXB different datatypes parsing per namespace

I have got the JAXB bindings config file like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.1">
<jaxb:globalBindings generateElementProperty="false">
<jaxb:javaType name="java.util.Date" xmlType="xs:dateTime"
parseMethod="com.utils.EmptyDateTimeAdapter.parseDateTime"
printMethod="com.utils.EmptyDateTimeAdapter.printDateTimeWithZone"/>
<xjc:serializable uid="-1"/>
</jaxb:globalBindings>
</jaxb:bindings>
In xml above I declared that every wsdl dateTime element will be parsed by these methods.
My question is:
How can I change this JAXB config file to specify multiple parse methods for element type per package name or per wsdl?
<jaxws:bindings wsdlLocation="SampleService.wsdl"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<jaxws:bindings node="wsdl:definitions/wsdl:types/xs:schema[#targetNamespace='http://example.com/service/SampleService/']">
<jxb:globalBindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:javaType name="java.util.Date" xmlType="xs:date"
parseMethod="org.apache.cxf.tools.common.DataTypeAdapter.parseDateTime"
printMethod="org.apache.cxf.tools.common.DataTypeAdapter.printDateTime"/>
</jxb:globalBindings>
</jaxws:bindings>
</jaxws:bindings>
references :
JBoss Community Archive (Read Only)
JAXB bindings and xs:date to java.util.Date
Custom Jax-b bindings for xs:date to JAVA 8 java.time.LocalDate using Adapter

JAXB maven plugin bindings does not generate classes with interface

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?

Multiple <schemaBindings> for the target namespace in single file

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.

How to Generate class with JAXB from XSD with imports

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

get <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" > in wsdl

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>

Categories

Resources