我的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>
...
那么如何将自定义异常返回给客户端呢?
答案 0 :(得分:1)
问题是由于自定义异常必须是类的扩展
Exception
或其他扩展Exception
的类。但我不知道它,我的自定义异常是Throwable
的扩展。
答案 1 :(得分:0)
您是否使用以下命令注释Web Service类:
@WebService(serviceName = "CustomWsName")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
public class WebServiceClass{
@WebMethod
..method...
}
或者使用另一个SOAPBinding?