<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
Re: Custom exceptions with @WebFault
</h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/jfitzpatrick">John Fitzpatrick</a> in <i>JBoss Web Services</i> - <a href="https://community.jboss.org/message/647717#647717">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>Have you tried defining the fault in your wsdl file and then using wsimport to have the JAXB artifacts generated for you?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Example that I think should work:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>wsdl:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><?xml version="1.0" encoding="UTF-8"?></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><definitions</p><p>    name="SubtractNumbers"</p><p><span>    targetNamespace="</span><a class="jive-link-external-small" href="http://duke.example.org" target="_blank">http://duke.example.org</a><span>"</span></p><p><span>    xmlns:tns="</span><a class="jive-link-external-small" href="http://duke.example.org" target="_blank">http://duke.example.org</a><span>"</span></p><p><span>    xmlns="</span><a class="jive-link-external-small" href="http://schemas.xmlsoap.org/wsdl/" target="_blank">http://schemas.xmlsoap.org/wsdl/</a><span>"</span></p><p><span>    xmlns:xsd="</span><a class="jive-link-external-small" href="http://www.w3.org/2001/XMLSchema" target="_blank">http://www.w3.org/2001/XMLSchema</a><span>"</span></p><p><span>    xmlns:soap="</span><a class="jive-link-external-small" href="http://schemas.xmlsoap.org/wsdl/soap/" target="_blank">http://schemas.xmlsoap.org/wsdl/soap/</a><span>"></span></p><p>    <types></p><p>        <xsd:schema</p><p><span>            xmlns="</span><a class="jive-link-external-small" href="http://www.w3.org/2001/XMLSchema" target="_blank">http://www.w3.org/2001/XMLSchema</a><span>"</span></p><p><span>            targetNamespace="</span><a class="jive-link-external-small" href="http://duke.example.org" target="_blank">http://duke.example.org</a><span>"</span></p><p>            elementFormDefault="qualified"></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>            <complexType name="subtractNumbersResponse"></p><p>                <sequence></p><p>                    <element name="return" type="xsd:int" /></p><p>                </sequence></p><p>            </complexType></p><p>            <element name="subtractNumbersResponse" type="tns:subtractNumbersResponse"/></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>            <complexType name="subtractNumbers"></p><p>                <sequence></p><p>                    <element name="arg0" type="xsd:int" /></p><p>                    <element name="arg1" type="xsd:int" /></p><p>                </sequence></p><p>            </complexType></p><p>            <element name="subtractNumbers" type="tns:subtractNumbers"/></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>            <element name="permissionDeniedFault"></p><p>                <complexType></p><p>                    <sequence></p><p>                        <element name="message" type="xsd:string"/></p><p>                    </sequence></p><p>                </complexType></p><p>            </element></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>        </xsd:schema></p><p>    </types></p><p>    <message name="subtractNumbers"></p><p>        <part name="parameters" element="tns:subtractNumbers" /></p><p>    </message></p><p>    <message name="subtractNumbersResponse"></p><p>        <part name="result" element="tns:subtractNumbersResponse" /></p><p>    </message></p><p>    <message name="permissionDeniedException"></p><p>        <part name="permissionDeniedFault" element="tns:permissionDeniedFault"/></p><p>    </message></p><p>    <portType name="SubtractNumbersPortType"></p><p>        <operation name="subtractNumbers"></p><p>            <input message="tns:subtractNumbers" /></p><p>            <output message="tns:subtractNumbersResponse" /></p><p>            <fault name="permissionDeniedFault" message="tns:permissionDeniedException" /></p><p>        </operation></p><p>    </portType></p><p>    <binding name="SubtractNumbersBinding" type="tns:SubtractNumbersPortType"></p><p><span>        <soap:binding transport="</span><a class="jive-link-external-small" href="http://schemas.xmlsoap.org/soap/http" target="_blank">http://schemas.xmlsoap.org/soap/http</a><span>" style="document" /></span></p><p>        <operation name="subtractNumbers"></p><p>            <soap:operation soapAction="" /></p><p>            <input></p><p>                <soap:body use="literal" /></p><p>            </input></p><p>            <output></p><p>                <soap:body use="literal" /></p><p>            </output></p><p>            <fault name="permissionDeniedFault"></p><p>                <soap:fault use="literal" name="permissionDeniedFault" /></p><p>            </fault></p><p>        </operation></p><p>    </binding></p><p>    <service name="SubtractNumbersService"></p><p>        <port name="SubtractNumbersPort" binding="tns:SubtractNumbersBinding"></p><p>            <soap:address location="REPLACE_WITH_ACTUAL_URL" /></p><p>        </port></p><p>    </service></p><p></definitions></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Generated fault/exception related artificats:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>@XmlAccessorType(XmlAccessType.FIELD)</p><p>@XmlType(name = "", propOrder = {</p><p>    "message"</p><p>})</p><p>@XmlRootElement(name = "permissionDeniedFault")</p><p>public class PermissionDeniedFault {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    @XmlElement(required = true)</p><p>    protected String message;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    /**</p><p>     * Gets the value of the message property.</p><p>     * </p><p>     * @return</p><p>     *     possible object is</p><p>     *     {@link String }</p><p>     *     </p><p>     */</p><p>    public String getMessage() {</p><p>        return message;</p><p>    }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    /**</p><p>     * Sets the value of the message property.</p><p>     * </p><p>     * @param value</p><p>     *     allowed object is</p><p>     *     {@link String }</p><p>     *     </p><p>     */</p><p>    public void setMessage(String value) {</p><p>        this.message = value;</p><p>    }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span>@WebFault(name = "permissionDeniedFault", targetNamespace = "</span><a class="jive-link-external-small" href="http://duke.example.org" target="_blank">http://duke.example.org</a><span>")</span></p><p>public class PermissionDeniedException</p><p>    extends Exception</p><p>{</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    /**</p><p>     * Java type that goes as soapenv:Fault detail element.</p><p>     * </p><p>     */</p><p>    private PermissionDeniedFault faultInfo;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    /**</p><p>     * </p><p>     * @param message</p><p>     * @param faultInfo</p><p>     */</p><p>    public PermissionDeniedException(String message, PermissionDeniedFault faultInfo) {</p><p>        super(message);</p><p>        this.faultInfo = faultInfo;</p><p>    }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    /**</p><p>     * </p><p>     * @param message</p><p>     * @param faultInfo</p><p>     * @param cause</p><p>     */</p><p>    public PermissionDeniedException(String message, PermissionDeniedFault faultInfo, Throwable cause) {</p><p>        super(message, cause);</p><p>        this.faultInfo = faultInfo;</p><p>    }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    /**</p><p>     * </p><p>     * @return</p><p>     *     returns fault bean: provider.server.PermissionDeniedFault</p><p>     */</p><p>    public PermissionDeniedFault getFaultInfo() {</p><p>        return faultInfo;</p><p>    }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Implementation class:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>@WebService (serviceName = "SubtractNumbersService",</p><p>        portName = "SubtractNumbersPort",</p><p>        endpointInterface = "provider.server.SubtractNumbersPortType" )</p><p>public class  SubtractNumbersImpl {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    public int subtractNumbers(int arg1, int arg2) throws PermissionDeniedException {</p><p>     </p><p>          PermissionDeniedFault permissionDeniedFault = new PermissionDeniedFault();</p><p>          permissionDeniedFault.setMessage("Your custom message here explain why permission was denied.");</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>         throw new PermissionDeniedException("Permission denied.", permissionDeniedFault);</p><p>    }</p><p>}</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/647717#647717">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss Web Services at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2044">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>