Skip to main content

Packaging Service Interface and Exception of WSDL with JAXB Binding

No replies
Jivix
Offline
Joined: 2013-12-10
Points: 0

Hi,

I'm trying to customize package swhere the service interface and the exceptions of WSDL are generated under using an external JAXB binding document. I'm doing this via wsimport 2.2.4 (and 2.1), but regardless of my binding, it places them in the (reversed) default namespace of WSDL. However, using a customized JAXB binding file(s), the schemas (XSD's) do get placed in the correct packages. Here are my WSDL and external JAXB binding file:

(As I said, the schema bindings work, but the service and exception binding in the WSDL do not)

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
             version="2.1">

    <jaxb:bindings schemaLocation="MyType.xsd">
      <jaxb:schemaBindings>
        <jaxb:package name="my.namespace.mytype" />
      </jaxb:schemaBindings>
    </jaxb:bindings>

    <jaxb:bindings schemaLocation="MyOtherType.xsd">
      <jaxb:schemaBindings>
        <jaxb:package name="my.namespace.myothertype" />
      </jaxb:schemaBindings>
    </jaxb:bindings>

    <jaxws:bindings wsdlLocation="MyService.wsdl"
     xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
        xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
        <jaxws:bindings
        node="wsdl:definitions/wsdl:service[@name='MyService']">
            <jaxws:package name="com.myservice.service" />
        </jaxws:bindings>
    </jaxws:bindings>   

    <jaxws:bindings wsdlLocation="MyService.wsdl"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
        xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
        <jaxws:bindings
        node="wsdl:definitions/wsdl:portType[@name='MyService']/wsdl:operation[@name='getMyService']/wsdl:fault[@name='fault']">
            <jaxws:package name="com.myservice.exception" />
        </jaxws:bindings>
    </jaxws:bindings>

</jaxb:bindings>

And the WSDL:

 <?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions        name="MyService"
          targetNamespace="http://my.namespace"
               xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
                xmlns:tns="http://my.namespace"
               xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <wsdl:types>
      <xsd:schema targetNamespace="http://my.namespace"
                   xmlns:Q1="http://my.namespace.myothertype">

      <xsd:include schemaLocation="MyType.xsd"></xsd:include>
      <xsd:import schemaLocation="MyOtherType.xsd"
                 namespace="http://my.namespace.myothertype"/>
      <xsd:import schemaLocation="MyFault.xsd"
                 namespace="http://my.namespace.myfault"/>
      <!-- ... -->
      </xsd:schema>
    </wsdl:types>

     <!-- messages and operations -->

  <wsdl:portType name="MyService">

<wsdl:operation name="getMyService">
<wsdl:input message="tns:getMyServiceRequest"></wsdl:input>
<wsdl:output message="tns:getMyServiceResponse"></wsdl:output>
        <wsdl:fault name="fault" message="tns:ServiceFault"></wsdl:fault>
    </wsdl:operation>

  </wsdl:portType>


  <wsdl:service name="MyService">
    <wsdl:port binding="tns:MyServiceSOAP" name="MyServiceSOAP">
      <soap:address location="http://localhost:9080/services/MyService"/>
    </wsdl:port>
  </wsdl:service>

</wsdl:definitions>

This would place the XSD types that are imported/included in the WSDL under "my.namespace.mytype" and "my.namespace.myothertype" accordingly. However, the exception (ServiceFault) and the service interface (and the implementation respectively) are generated under "namespace.my" (the WSDL's reversed default namespace) rather than "com.myservice.service" and "com.myservice.exception".

I am running the wsimport with the following (all the files are in the same directory: WSDL, XSD's, and JAXB binding documents; MyService.wsdl, MyType.xsd, MyOtherType.xsd, MyFault.xsd (which contains schema for the fault details), MyBinding.xml, ServiceFaultBinding.xml (a binding to place MyFault.xsd type in its own package, which, like other XSD's, do get placed in the correct package)):

C:\>wsimport MyService.wsdl -b MyBinding.xml -b ServiceFaultBinding.xml -s .\