JAX-WS - 将异常映射到故障
我正在使用 JAX WS 来公开 Web 服务。此服务的某些操作可能会生成异常。不是内部服务器异常,而是依赖于操作调用的输入参数的异常。
如果我指定我的操作会引发自定义异常,如下所示:
@WebService
@SOAPBinding(style = Style.RPC, use = Use.LITERAL)
public class MyServiceEndpointImpl implements MyServiceEndpoint {
@WebMethod
public void throwsException throws InvalidInputException;
}
在运行应用程序时,我最终得到以下堆栈跟踪:
com.sun.xml.ws.model.RuntimeModelerException: runtime modeler error: Wrapper class com.mypackage.ws.services.jaxws.InvalidInputExceptionBean is not found. Have you run APT to generate them?
at com.sun.xml.ws.model.RuntimeModeler.getClass(RuntimeModeler.java:285)
at com.sun.xml.ws.model.RuntimeModeler.processExceptions(RuntimeModeler.java:1006)
at com.sun.xml.ws.model.RuntimeModeler.processRpcMethod(RuntimeModeler.java:969)
at com.sun.xml.ws.model.RuntimeModeler.processMethod(RuntimeModeler.java:546)
at com.sun.xml.ws.model.RuntimeModeler.processClass(RuntimeModeler.java:370)
at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:256)
at com.sun.xml.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:322)
at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:188)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:467)
at org.jvnet.jax_ws_commons.spring.SpringService.getObject(SpringService.java:333)
at org.jvnet.jax_ws_commons.spring.SpringService.getObject(SpringService.java:45)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport$1.run(FactoryBeanRegistrySupport.java:121)
添加到并不能解决问题。@XmlRootEntity
InvalidInputException
如果这不是通过Web服务报告故障的推荐方法,那么是否有更好的方法?我的异常是否应该继承并依赖于错误处理的传输(即,所有内容最终都将包装在SOAPException中)?我希望能有类似Spring-WS'的东西。JAX-WS 是否有类似的东西可用?RuntimeException
SoapFaultAnnotationExceptionResolver