Configuring Java JAXB wsimport packages

I am trying to create a client with maven and jaxb from a wsdl file with two schemes inside and some elements with the same name from different schemes

When I try to compile, I get the following error:

Two declarations cause a collision in the ObjectFactory class. 

WSDL schemes :

 <wsdl:types> <schema targetNamespace="http://ws.services" xmlns="http://www.w3.org/2001/XMLSchema">...</schema> <schema targetNamespace="http://ws.models" xmlns="http://www.w3.org/2001/XMLSchema">...</schema> </wsdl:types> 

I tried to rename the elements that cause the error, but then my spring client will get the correct SOAP message, but it does not populate the response object properly (all its attributes are zero) , I think the problem may be renaming the response classes, so I'm trying create different packages, keeping the original name of all classes.

To do this, I wrote the following bindings file, but I don’t know what I am doing wrong, because it does not work.

bindings.xml file :

 <?xml version="1.0" encoding="UTF-8"?> <jaxb:bindings version="2.1" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" > <jaxb:bindings schemaLocation="mywsdl.wsdl#types?schema1" node="/xs:schema[@targetNamespace='http://ws.services']"> <jaxb:schemaBindings> <jaxb:package name="package1" /> </jaxb:schemaBindings> </jaxb:bindings> <jaxb:bindings schemaLocation="mywsdl.wsdl#types?schema2" node="/xs:schema[@targetNamespace='http://ws.models']"> <jaxb:schemaBindings> <jaxb:package name="package2" /> </jaxb:schemaBindings> </jaxb:bindings> </jaxb:bindings> 

My configuration in the maven file is the following, just in case it is useful:

 <groupId>org.jvnet.jax-ws-commons</groupId> <artifactId>jaxws-maven-plugin</artifactId> <version>2.3</version> <executions> <execution> <goals> <goal>wsimport</goal> </goals> </execution> </executions> <configuration> <wsdlLocation>wsdl/mywsdl.wsdl</wsdlLocation> <wsdlDirectory>src/main/resources/wsdl</wsdlDirectory> <wsdlFiles> <wsdlFile>mywsdl.wsdl</wsdlFile> </wsdlFiles> <bindingDirectory>src/main/resources/wsdl</bindingDirectory> <bindingFiles> <bindingFile>bindings.xml</bindingFile> </bindingFiles> <packageName>original.package</packageName> <sourceDestDir>${basedir}/src/main/java</sourceDestDir> </configuration> 

When compiling with these binding files, the same error appears. So I think that maybe this is wrong.

Do you find any errors?

Thanks.

+5
source share
1 answer

From my experience, it is best to create 2 bind files (one for each WSDL file). Update your pom.xml and make sure the root element of the jaxws: bindings binding files (not jaxb: bindings!)

Some tips:

  • Be sure to set the "wsdlLocation" attribute correctly! It must point to the WSDL file using the relative path!
  • The jaxws: package package defines the package that will be used for the generated service classes. (material annotated using @WebService)
  • Enable or disable wrapperStyle and asyncMapping as you wish .; -)

Example binding file for "package1":

 <?xml version="1.0" encoding="UTF-8"?> <jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema" wsdlLocation="mywsdl.wsdl" version="2.0"> <jaxws:package name="package1"/> <jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle> <jaxws:enableAsyncMapping>true</jaxws:enableAsyncMapping> <jaxws:bindings node="//wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='http://ws.services']"> <jaxb:schemaBindings> <jaxb:package name="package1"/> </jaxb:schemaBindings> </jaxws:bindings> </jaxws:bindings> 
+7
source

Source: https://habr.com/ru/post/1202961/


All Articles