You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by ho...@gmx.de on 2007/06/14 16:44:51 UTC

[Axis2] wsdl2java code generation errors with jaxb and soap header

Hello,

I generate client code out of a wsdl with axis2 (v. 1.2) wsdl2java and jaxbri(v. 2.0.2) databinding.
the wsdl not only defines request and reply messages but also the header element of the soap message.

i have the following problems with the generated code:
1) The generated code for the client stub doesn't compile because of a parameter error in the "toOM"-Method for the Header.
2) When i fix the error, the invocation of "toOM" fails because of incorrect/ missing values when creating the OMElement for the Header
3) When i fix this error too by filling in the correct values for the HeaderType, the client code works. 

I think the wsdl is correct because generated code with adb binding out of this wsdl works fine.

It seems that axis2 code generation doesn't generate correct code with jaxb binding when you have defined a soap header in the wsdl. 
Does someone have a similiar problem (or fixed it)?

greetings from sunny munich :)
andi

some code snippets from the generated stub:

"toOM"-Method call. "mMS150_Display0" represents the request data type, "mws1" the header data type.
1)------------------------------------------
**snip**
env = toEnvelope(getFactory(
	_operationClient.getOptions().getSoapVersionURI()), 
	mMS150_Display0, 
	optimizeContent(new javax.xml.namespace.QName("", "MMS150_Display")));
env.build();
// add the children only if the parameter is not null
if (mws1!=null){
	env.getHeader().addChild(
		toOM(mws1, optimizeContent(new javax.xml.namespace.QName("", "MMS150_Display"))));
}
**snap**

"toOM"-Method for the header:
2)------------------------------------------
**snip**
private org.apache.axiom.om.OMElement toOM(net.company.mws.mws2.HeaderType param, org.apache.axiom.soap.SOAPFactory factory, boolean optimizeContent) {
    try {
        javax.xml.bind.JAXBContext context = net_company_mws_mws2_HeaderType;
        javax.xml.bind.Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FRAGMENT, Boolean.TRUE);            

        JaxbRIDataSource source = new JaxbRIDataSource( net.company.mws.mws2.HeaderType.class,
                                                        param,
                                                        marshaller,
                                                        "",
                                                        "");
        org.apache.axiom.om.OMNamespace namespace = factory.createOMNamespace("",
                                                           null);
        return factory.createOMElement(source, "", namespace);
    } catch (javax.xml.bind.JAXBException bex){
        throw new RuntimeException(bex);
    }
}

**snap**

the call of the "toOM"-Method (with Parameters HeaderType, boolean) doesn't fit with the signature of the toOm-Method (HeaderType, SOAPFactory, boolean)
i can correct this error by adding "getFactory(_operationClient.getOptions().getSoapVersionURI())" to the toOM-Method call in the generated stub.
then i run into the second error i mentioned above. 

The following code snippet shows the correct values for in the "toOM"-Method:
3)------------------------------------------
**snip**
JaxbRIDataSource source = new JaxbRIDataSource( net.company.mws.mws2.HeaderType.class,
                                                param,
                                                marshaller,
                                                "http://mws.company.net/mws2",
                                                "mws");
org.apache.axiom.om.OMNamespace namespace = factory.createOMNamespace("",
                                                   null);
return factory.createOMElement(source, "mws", namespace);
**snap**

the wsdl:
------------------------------------------
**snip**
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
	xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
	xmlns:mws="http://mws.company.net/mws2" 
	xmlns:tns="http://schemas.company.com/KKTEST2" 
	xmlns:mms150_display="http://schemas.company.com/KKTEST2/MMS150_Display" 
	name="KKTEST2" targetNamespace="http://schemas.company.com/KKTEST2">
  <wsdl:types>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://schemas.company.com/KKTEST2/MMS150_Display" elementFormDefault="qualified">
      <xsd:element name="MMS150_Display" type="mms150_display:MMS150_DisplayType" />
      <xsd:complexType name="MMS150_DisplayType">
        <xsd:sequence>
          <xsd:element name="MMS150" type="mms150_display:ct_0" />
        </xsd:sequence>
      </xsd:complexType>
      <xsd:complexType name="ct_0">
        <xsd:sequence>
          <xsd:element name="User" nillable="true" maxOccurs="1" minOccurs="0">
            <xsd:simpleType>
              <xsd:restriction base="xsd:string">
                <xsd:maxLength value="10" />
              </xsd:restriction>
            </xsd:simpleType>
          </xsd:element>
        </xsd:sequence>
      </xsd:complexType>
      <xsd:element name="MMS150_DisplayResponse" type="mms150_display:MMS150_DisplayResponseType" />
      <xsd:complexType name="MMS150_DisplayResponseType">
        <xsd:sequence>
          <xsd:element name="MMS150" type="mms150_display:ct_1" />
        </xsd:sequence>
      </xsd:complexType>
      <xsd:complexType name="ct_1">
        <xsd:sequence>
          <xsd:element name="Description">
            <xsd:simpleType>
              <xsd:restriction base="xsd:string">
                <xsd:maxLength value="40" />
              </xsd:restriction>
            </xsd:simpleType>
          </xsd:element>
        </xsd:sequence>
      </xsd:complexType>
    </xsd:schema>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    	xmlns:tns="http://mws.company.net/mws2" 
    	targetNamespace="http://mws.company.net/mws2" elementFormDefault="qualified">
      <xsd:element name="mws" type="tns:headerType" />
      <xsd:complexType name="headerType">
        <xsd:sequence>
          <xsd:element name="user" type="xsd:string" />
          <xsd:element name="password" type="xsd:string" />
          <xsd:element name="company" type="xsd:integer" nillable="true" />
          <xsd:element name="division" type="xsd:string" nillable="true" />
        </xsd:sequence>
      </xsd:complexType>
    </xsd:schema>
  </wsdl:types>
  <wsdl:message name="MMS150_Display">
    <wsdl:part element="mms150_display:MMS150_Display" name="MMS150_Display" />
  </wsdl:message>
  <wsdl:message name="MMS150_DisplayResponse">
    <wsdl:part element="mms150_display:MMS150_DisplayResponse" name="MMS150_DisplayResponse" />
  </wsdl:message>
  <wsdl:message name="MwsHeader001">
    <wsdl:part element="mws:mws" name="MwsHeader" />
  </wsdl:message>
  <wsdl:portType name="KKTEST2">
    <wsdl:operation name="MMS150_Display">
      <wsdl:input message="tns:MMS150_Display" />
      <wsdl:output message="tns:MMS150_DisplayResponse" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="KKTEST2SoapBinding" type="tns:KKTEST2">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="MMS150_Display">
      <soap:operation soapAction="MMS150_Display" />
      <wsdl:input>
        <soap:body use="literal" parts="MMS150_Display" />
        <soap:header use="literal" part="MwsHeader" message="tns:MwsHeader001" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="KKTEST2">
    <wsdl:port name="KKTEST2Port" binding="tns:KKTEST2SoapBinding">
      <soap:address location="http://host:port/ws/services/KKTEST2" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>
**snap**


-- 
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org