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
感謝您的幫助。我已經找到了這個問題的解決方案。 –