Why do classes created by wsimport require JAXBElement <ClassName> parameters?

I have a WSDL file that is located from the Axis2 web service. When I create a client stub using wsimport considering the WSDL file, the resulting classes require JAXBElement paramators. Why is this so?

An example of a method from one of the classes:

 JAXBElement<DataBean> value; public void setValue(JAXBElement<DataBean> value) { this.value = ((JAXBElement<DataBean>) value); } 

I expect this to look (without JAXBElement):

 DataBean value; public void setValue(DataBean value) { this.value= (DataBean) value; } 

The tutorials that I saw on the net do not set classes in JAXBElement. What could be the problem? Please note that the server is an Axis2 web service, and the WSDL file is automatically generated by Axis2. I believe that I do not control the server.

How can I do this so that wsimport does not convert the parameters to JAXBElements?

The following is a snippet of the WSDL file: (I ignored some tags to include only the main tags)

 <xs:element name="getData"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="getData" nillable="true" type="ax220:getData"/> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="getData"> <xs:sequence> <xs:element minOccurs="0" name="value" nillable="true" type="ax219:DataBean"/> </xs:sequence> </xs:complexType> <wsdl:message name="getDataRequest"> <wsdl:part name="parameters" element="ns:getData"/> </wsdl:message> <wsdl:message name="getDataResponse"> <wsdl:part name="parameters" element="ns:getDataResponse"/> </wsdl:message> <wsdl:operation name="getData"> <wsdl:input message="ns:getDataRequest" wsaw:Action="urn:getData"/> <wsdl:output message="ns:getDataResponse" wsaw:Action="urn:getDataResponse"/> </wsdl:operation> <wsdl:operation name="getData"> <soap:operation soapAction="urn:getData" style="document"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="getData"> <soap12:operation soapAction="urn:getData" style="document"/> <wsdl:input> <soap12:body use="literal"/> </wsdl:input> <wsdl:output> <soap12:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="getData"> <http:operation location="getData"/> <wsdl:input> <mime:content type="text/xml" part="parameters"/> </wsdl:input> <wsdl:output> <mime:content type="text/xml" part="parameters"/> </wsdl:output> </wsdl:operation> 
+4
source share
2 answers

Let's start with: I don’t think it can be done. That is, I don’t think you can tell wsimport to generate classes in different ways. However, I can tell you how to change the WSDL in a way that generates the circuit in different ways and which still allows you to talk to the service.

I took type definitions from WSDL, adjusted the name of complexType, and added the DataBean type, which was missing above. I put this into the schema and compiled the schema with xjc, the JAXB schema compiler that wsimport uses to generate classes from the type definition. Here is the diagram:

 <?xml version="1.0" encoding="UTF-8"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/DataBean" xmlns:tns="http://www.example.org/DataBean" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="getData"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="getDataType" type="tns:getDataType" /> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="getDataType"> <xs:sequence> <xs:element minOccurs="0" name="value" type="tns:DataBean" /> </xs:sequence> </xs:complexType> <xs:complexType name="DataBean"> <xs:simpleContent> <xs:extension base="xs:int" /> </xs:simpleContent> </xs:complexType> </schema> 

You do not need special parameters for the compiler, just execute xjc and specify it in the schema file, then it will compile the source files.

Generated classes do not use JAXBElement as method parameters. That is, they look like this:

 protected DataBean value; public DataBean getValue() { return value; } 

Why is this? I removed the nillable="true" attributes from the defintions elements and this did the trick. nillable="true" indicates that explicit null values ​​are legal here:

 <DataBean></DataBean> 

If you remove this attribute, your code will run into problems if the service actually writes null values ​​to it. But WSDL is generated, and perhaps Axis2 just thinks that for some reason nileble should be there, although the implementation never uses it. If you're lucky, that is not the case, and everything will work well, although you have changed the WSDL.

Hope this helps! If not, then at least today I learned something; -)

+2
source

As read on this page:

http://www.techdevtips.com/java/java-webservice-client-how-to-remove-jaxbelement

use a data binding file with this code:

 <?xml version="1.0" encoding="UTF-8"?> <jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.0" xmlns:xjc= "http://java.sun.com/xml/ns/jaxb/xjc" jaxb:extensionBindingPrefixes="xjc"> <jaxb:globalBindings generateElementProperty="false"> <xjc:simple /> </jaxb:globalBindings> </jaxb:bindings> 

and use it in your wsimport ant task by filling in the binding attribute (or -b flag argument if you use runnable)

Greetings :)

+6
source

All Articles