2

我的 Web 服务的某些方法应该向客户端返回自定义异常。但是 jax-ws 在发布端点时会忽略自定义异常的声明。
服务和方法的描述如下(这个接口的实现有相同的注解):

@WebService(name = "ContainerProxy")
@SOAPBinding(style = Style.RPC)
public interface ContainerProxy {

    @WebMethod
    public Response processRequest(Request request) throws
        BadRequestException, // Custom exception
        ApplicationNotFoundException, // Custom exception
        ClassNotFoundException,
        NoSuchMethodException,
        IllegalAccessException,
        InvocationTargetException;
}

为此服务生成的 WSDL 如下所示:

<?xml...
    <portType name="ContainerProxyImpl">
        <operation name="processRequest">
            <input wsam:Action="http://proxy.container.hive.org/ContainerProxyImpl/processRequestRequest"
               message="tns:processRequest"></input>
            <output wsam:Action="http://proxy.container.hive.org/ContainerProxyImpl/processRequestResponse"
                message="tns:processRequestResponse"></output>
            <fault message="tns:ClassNotFoundException" name="ClassNotFoundException"
               wsam:Action="http://proxy.container.hive.org/ContainerProxyImpl/processRequest/Fault/ClassNotFoundException"></fault>
            <fault message="tns:NoSuchMethodException" name="NoSuchMethodException"
               wsam:Action="http://proxy.container.hive.org/ContainerProxyImpl/processRequest/Fault/NoSuchMethodException"></fault>
            <fault message="tns:IllegalAccessException" name="IllegalAccessException"
               wsam:Action="http://proxy.container.hive.org/ContainerProxyImpl/processRequest/Fault/IllegalAccessException"></fault>
            <fault message="tns:InvocationTargetException" name="InvocationTargetException"
               wsam:Action="http://proxy.container.hive.org/ContainerProxyImpl/processRequest/Fault/InvocationTargetException"></fault>
        </operation>
        ...
    </portType>
    ...
    <binding name="ContainerProxyImplPortBinding" type="tns:ContainerProxyImpl">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding>
        <operation name="processRequest">
            <soap:operation soapAction=""></soap:operation>
            <input>
                <soap:body use="literal"></soap:body>
            </input>
            <output>
                <soap:body use="literal"></soap:body>
            </output>
            <fault name="ClassNotFoundException">
                <soap:fault name="ClassNotFoundException" use="literal"></soap:fault>
            </fault>
            <fault name="NoSuchMethodException">
                <soap:fault name="NoSuchMethodException" use="literal"></soap:fault>
            </fault>
            <fault name="IllegalAccessException">
                <soap:fault name="IllegalAccessException" use="literal"></soap:fault>
            </fault>
            <fault name="InvocationTargetException">
                <soap:fault name="InvocationTargetException" use="literal"></soap:fault>
            </fault>
        </operation>
        ...

那么如何将自定义异常返回给客户端?

4

2 回答 2

1

问题是由于自定义异常必须是类的扩展 Exception或其他扩展的类Exception。但我不知道,我的自定义异常是Throwable.

于 2013-09-26T08:37:42.773 回答
0

您是否使用以下内容注释了 Web Service 类:

@WebService(serviceName = "CustomWsName")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
public class WebServiceClass{

@WebMethod
..method...


}

还是使用另一个 SOAPBinding?

于 2013-09-25T16:29:39.867 回答