Note that there are some explanatory texts on larger screens.

plurals
  1. POChecked exceptions hierarchy in WebServices using JAX-WS Maven Plugin (wsimport)
    primarykey
    data
    text
    <p>I'm working on a project where we want to use checked exceptions to notify user of (for example) wrong input or wrong action taken. Such exceptions should have hierarchy such as:</p> <pre><code>public abstract class BusinessException extends java.lang.Exception {...} public class InvalidInputException extends BusinessException {...} public class InvalidActionException extends BusinessException {...} </code></pre> <p>We generate java code from WSDL/XSD (contract-first approach) using Maven, <code>jaxws-maven-plugin</code>, goal <code>wsimport</code>.</p> <p>I've tried to go along this ( <a href="http://www.ibm.com/developerworks/xml/library/ws-tip-jaxrpc.html" rel="noreferrer">http://www.ibm.com/developerworks/xml/library/ws-tip-jaxrpc.html</a> ) tutorial (it is for jax-rpc, but seems to work for jax-ws as well). I wrote</p> <pre><code>&lt;definitions ...&gt; &lt;message name="empty"/&gt; &lt;message name="ExceptionMessage"&gt; &lt;part name="fault" element="ows:ValidationException"/&gt; &lt;/message&gt; &lt;portType name="TestWebService"&gt; &lt;operation name="throwException"&gt; &lt;input message="tns:empty"/&gt; &lt;output message="tns:empty"/&gt; &lt;fault name="fault" message="tns:ExceptionMessage"/&gt; &lt;/operation&gt; &lt;/portType&gt; &lt;binding name="TestWebServicePortBinding" type="tns:TestWebService"&gt; &lt;soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/&gt; &lt;operation name="throwException"&gt; &lt;input&gt; &lt;soap:body use="literal"/&gt; &lt;/input&gt; &lt;output&gt; &lt;soap:body use="literal"/&gt; &lt;/output&gt; &lt;fault name="fault"&gt; &lt;soap:fault name="fault" use="literal"/&gt; &lt;/fault&gt; &lt;/operation&gt; &lt;/binding&gt; ... &lt;/definitions&gt; </code></pre> <p>with types defined in ows: namespace</p> <pre><code>&lt;xs:complexType name="BusinessException" abstract="true"&gt; &lt;xs:sequence&gt; &lt;xs:element name="code" type="xs:int"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;xs:complexType name="InvalidInputException"&gt; &lt;xs:complexContent&gt; &lt;xs:extension base="tns:BusinessException"&gt; &lt;xs:sequence&gt; &lt;xs:element name="validationMessage" type="xs:string"/&gt; &lt;/xs:sequence&gt; &lt;/xs:extension&gt; &lt;/xs:complexContent&gt; &lt;/xs:complexType&gt; &lt;xs:complexType name="InvalidActionException"&gt; &lt;xs:complexContent&gt; &lt;xs:extension base="tns:BusinessException"&gt; &lt;xs:sequence&gt; &lt;xs:element name="actionName" type="xs:string"/&gt; &lt;/xs:sequence&gt; &lt;/xs:extension&gt; &lt;/xs:complexContent&gt; &lt;/xs:complexType&gt; &lt;xs:element name="ValidationException" type="tns:InvalidInputException"/&gt; </code></pre> <p>When i run <code>mvn clean package</code>, i get the following (getters, setters, ctors and annotations removed):</p> <pre><code>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; (...) } </code></pre> <p>Which is not what i wanted, because there is one exception and it can hold different <code>faultInto</code> data. Is there a way to create Exception hierarchy as noted above purely in XSD/WSDL? As the <code>ExceptionMessage</code> class is generated directly from <code>&lt;message&gt;</code> tag, I was not able to find a way of creating a parent/child there.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload