Checked exception hierarchy in WebServices using JAX-WS Maven Plugin (wsimport)

I am working on a project in which we want to use checked exceptions to notify the user (for example) of an incorrect entry or of an incorrect action. Such exceptions should have a hierarchy, such as:

public abstract class BusinessException extends java.lang.Exception {...} public class InvalidInputException extends BusinessException {...} public class InvalidActionException extends BusinessException {...} 

We generate Java code from WSDL / XSD (contract-first approach) using Maven, jaxws-maven-plugin , goal wsimport .

I tried to go through this ( http://www.ibm.com/developerworks/xml/library/ws-tip-jaxrpc.html ) tutorial (this is for jax-rpc, but it seems to work on jax -ws as well). I wrote

 <definitions ...> <message name="empty"/> <message name="ExceptionMessage"> <part name="fault" element="ows:ValidationException"/> </message> <portType name="TestWebService"> <operation name="throwException"> <input message="tns:empty"/> <output message="tns:empty"/> <fault name="fault" message="tns:ExceptionMessage"/> </operation> </portType> <binding name="TestWebServicePortBinding" type="tns:TestWebService"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> <operation name="throwException"> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> <fault name="fault"> <soap:fault name="fault" use="literal"/> </fault> </operation> </binding> ... </definitions> 

with types defined in ows: namespace

 <xs:complexType name="BusinessException" abstract="true"> <xs:sequence> <xs:element name="code" type="xs:int"/> </xs:sequence> </xs:complexType> <xs:complexType name="InvalidInputException"> <xs:complexContent> <xs:extension base="tns:BusinessException"> <xs:sequence> <xs:element name="validationMessage" type="xs:string"/> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="InvalidActionException"> <xs:complexContent> <xs:extension base="tns:BusinessException"> <xs:sequence> <xs:element name="actionName" type="xs:string"/> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> <xs:element name="ValidationException" type="tns:InvalidInputException"/> 

When I run mvn clean package , I get the following (getters, seters, ctors and annotations removed):

 public interface TestWebService { @WebMethod public void throwException() throws ExceptionMessage; } public class ExceptionMessage extends Exception { private InvalidInputException faultInfo; (...) } public abstract class BusinessException implements Serializable { protected int code; (...) } public class InvalidActionException extends BusinessException implements Serializable { protected String actionName; (...) } public class InvalidInputException extends BusinessException implements Serializable { protected String validationMessage; (...) } 

This is not what I wanted because there is one exception, and it may contain different faultInto data. Is there a way to create an Exception hierarchy, as mentioned above, only in XSD / WSDL? Since the ExceptionMessage class is generated directly from the <message> , I could not find a way to create the parent / child object.

+6
java inheritance exception jax-ws wsimport
source share
2 answers

This seems to be impossible using the technologies mentioned above (WSDL / XSD (contract-first approach) using the Maven target, jaxws-maven-plugin , wsimport ).

0
source share

Could you change the WSDL operation to ...

 <portType name="TestWebService"> <operation name="throwException"> <input message="tns:empty"/> <output message="tns:empty"/> <fault name="fault" message="tns:BusinessException"/> </operation> </portType> 
0
source share

All Articles