2
我的Web服务的一些方法应该向客户端返回自定义例外。但是,在发布端点期间,jax-ws会忽略自定义异常的声明。服务和方法的
描述看起来像(实现此接口具有相同的注解):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>
...
所以,我怎么能返回自定义异常给客户?
当然可以。我已经更新了这个问题。 –
尝试在我的示例中使用SOAPBinding进行测试。通过这种方式,我可以看到发布的wsdl中包含的自定义异常。 – umanganiello
感谢您的帮助。我已经找到了这个问题的解决方案。 –