2 Replies Latest reply on Apr 3, 2007 5:40 AM by magnus.ahlander

    Name of generated exception class

    magnus.ahlander

      In my endpoint implementation I have a user-defined exception thrown by some operations. The generated wsdl then looks something like:

      ...
      <xs:complexType name='AuthorizationException'>
       <xs:sequence>
       <xs:element minOccurs='0' name='message' type='xs:string'/>
       </xs:sequence>
      </xs:complexType>
      ...
       <operation name='read'>
      ...
       <fault name='AuthorizationException'>
       <soap:fault name='AuthorizationException' use='literal'/>
       </fault>
      </operation>
      ...


      From this wsdl wsconsume generates the following client-side artifacts:
      AuthorizationException (jaxb type)
      AuthorizationException_Exception (java exception)

      In the client I then I then get some awkward code like

      try {...}
      catch (AuthorizationException_Exception ex) {...}


      To get around these problems I defined a custom jax-ws binding, which is then provided to wsconsume:

      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      <bindings
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
       xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
       wsdlLocation="http://localhost:8080/static/test.wsdl"
       xmlns="http://java.sun.com/xml/ns/jaxws">
       <bindings node="wsdl:definitions">
       <package name="com.test"/>
       </bindings>
       <bindings node="wsdl:definitions/wsdl:types/xsd:schema[@targetNamespace='http://com.test']">
       <jaxb:schemaBindings>
       <jaxb:package name="com.test.jaxb"/>
       </jaxb:schemaBindings>
       </bindings>
      </bindings>


      basically this puts jaxws and jaxb generated artifacts into separate packages.

      However, this works only if I remove the 'package' attribute from the wsconsume task. From this I conclude that the 'package' attribute takes precedence over any custom bindings. Why is this so?

      Is there any other way to get nice exception class names with wsconsume?

      Regards,
      Magnus

        • 1. Re: Name of generated exception class
          jason.greene

          Yes, the package name passed to wsconsume is an override, and is not really part of the standard. It's just their for ease of use.

          You can change the name of the exception class by using
          <jaxws:class name="MyNewException" node="..."/> to point to the wsdl:fault element.

          You can also change the name of the fault bean by using a JAXB customization that points to the schema complex type:

          <jaxb:class name="AuthorizationFaultBean" node="..."/>

          -Jason

          • 2. Re: Name of generated exception class
            magnus.ahlander

            Thanks for the reply.

            It seems like in the wsconsume task, the package name specified in the 'package' attribute takes precedence over any custom jaxws or jaxb bindings.

            Wouldn't it be more appropriate to initially apply any custom bindings and then fall back to the value of the 'package' attribute only if no appropriate bindings are available?

            Lp, Magnus