我正在使用JAX WS来公开WebService.此服务的某些操作可能会生成异常.不是内部服务器异常,而是依赖于操作调用的输入参数的异常.
如果我指定我的操作抛出自定义异常,如下所示:
@WebService
@SOAPBinding(style = Style.RPC, use = Use.LITERAL)
public class MyServiceEndpointImpl implements MyServiceEndpoint {
@WebMethod
public void throwsException throws InvalidInputException;
}
Run Code Online (Sandbox Code Playgroud)
运行应用程序时,我最终得到以下堆栈跟踪:
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)
Run Code Online (Sandbox Code Playgroud)
添加@XmlRootEntity到InvalidInputException不解决问题.
如果这不是报告Web服务故障的推荐方法,那么有更好的方法吗?我的异常是应该继承RuntimeException并依赖于传输进行错误处理(即,所有内容最终都将包含在SOAPException中)?我希望有类似Spring-WS的东西SoapFaultAnnotationExceptionResolver.是否有类似的东西可用于JAX-WS?