我制作了一个JAX-WS WebService,它应该在身份验证过程中抛出一些业务异常,以便客户端可以处理异常并向用户提供正确的信息。
WS开始在4个月前使用,到那时一切都运行良好,但从那时起我们的客户已经提出了很多新功能,而且合同已经改变了几乎每个开发人员都在这里,我无法弄明白有什么不对。
请问你能帮帮我吗?
@WebService
@ApplicationScoped
public class MyWS {
@WebMethod
public MyVO doSomething(parameters...) throws UserAuthenticationException {
throw new UserAuthenticationException(
"The message the business guys asked to send..."
);
}
现在是Exception类:
public class UserAuthenticationException extends Exception {
private String details;
/**
*
*/
private static final long serialVersionUID = -3173043626093972452L;
public UserAuthenticationException(String msg, Throwable t) {
super(msg, t);
}
public UserAuthenticationException(String reason, String details) {
super(reason);
this.details = details;
}
public UserAuthenticationException(String msg) {
super(msg);
this.details = msg;
}
public String getFaultInfo() {
return this.details;
}
}
可以在WSDL中看到我的异常被映射到错误
<portType name="MyWS"><operation name="doSomething"><input message="tns:doSomething" wsam:Action="http://ws.../MyWS/doSomethingRequest">
...
</output><fault name="UserAuthenticationException" message="tns:UserAuthenticationException" wsam:Action="http://ws.../MyWS/doSomething/Fault/UserAuthenticationException">
</fault></operation>
这是客户端方法调用,它总是进入catch(WebServiceException e)块
**所有存根/工件都是由WSImport创建的。
public void callMyWs() {
try {
//we use a proxy
MyWS myWsPort = MyWS.getMyWSPort();
myWsPort.doSomething()
} catch (UserAuthenticationException_Exception e) {
JOptionPane.showMessageDialog(e.getMessage());
->>>> //Here is where I expect it shoud go...
} catch (MalformedURLException e) {
...
} catch (WebServiceException e) {
...
//here is where it goes
} catch (Exception e) {
....
}
}
最后,WSImport使用我的WS方法创建的接口
@WebService(name = "MyWS", targetNamespace = "...")
@XmlSeeAlso({
ObjectFactory.class
})
public interface MyWS {
/**
*
* @return
* returns MyVO
* @throws UserAuthenticationException_Exception
*/
@WebMethod
@WebResult(targetNamespace = "")
@RequestWrapper(...", className = "...")
@ResponseWrapper(localName = "...", targetNamespace = "...", className = "...")
@Action(input = "...", output = "...", fault = {
@FaultAction(className = UserAuthenticationException_Exception.class, value = "ws.../MyWS/doSomething/Fault/UserAuthenticationException")
})
public MyVO doSomething(params...)
throws UserAuthenticationException_Exception
;
我只是看不出有什么问题
--- ---- EDITED
堆栈跟踪
javax.xml.ws.ProtocolException: The message the business guys asked to send...
at org.apache.axis2.jaxws.ExceptionFactory.createProtocolException(ExceptionFactory.java:199)
at org.apache.axis2.jaxws.ExceptionFactory.makeProtocolException(ExceptionFactory.java:97)
at org.apache.axis2.jaxws.marshaller.impl.alt.MethodMarshallerUtils.createSystemException(MethodMarshallerUtils.java:1370)
at org.apache.axis2.jaxws.marshaller.impl.alt.MethodMarshallerUtils.demarshalFaultResponse(MethodMarshallerUtils.java:1089)
at org.apache.axis2.jaxws.marshaller.impl.alt.DocLitWrappedMethodMarshaller.demarshalFaultResponse(DocLitWrappedMethodMarshaller.java:680)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.getFaultResponse(JAXWSProxyHandler.java:626)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.createResponse(JAXWSProxyHandler.java:566)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invokeSEIMethod(JAXWSProxyHandler.java:432)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invoke(JAXWSProxyHandler.java:213)
at com.sun.proxy.$Proxy29.callMyService(Unknown Source)
at package(Main.java:154)
at package.Main$1.actionPerformed(Main.java:84)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6525)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6290)
at java.awt.Container.processEvent(Container.java:2234)
at java.awt.Component.dispatchEventImpl(Component.java:4881)
at java.awt.Container.dispatchEventImpl(Container.java:2292)
at java.awt.Component.dispatchEvent(Component.java:4703)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
at java.awt.Container.dispatchEventImpl(Container.java:2278)
at java.awt.Window.dispatchEventImpl(Window.java:2750)
at java.awt.Component.dispatchEvent(Component.java:4703)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
答案 0 :(得分:0)
最后,我让它再次运作。
我注意到一些例子在创建代理之前使用QName对象来获取服务实例,所以我试试看它是否有效!
{{1}}