【发布时间】:2011-12-06 13:54:57
【问题描述】:
这是我第一次在这里发帖,所以请耐心等待,并在必要时纠正我......
我正在使用带有 GlassFish 的 NetBeans 构建简单的基于 Web 服务的应用程序。 NetBeans 在为新的 Web 服务及其操作生成代码方面确实有很大帮助,但有一件事让我抓狂——Web 服务异常处理。操作如:
@WebMethod(operationName = "checkUserExist")
public String checkUserExist(@WebParam(name = "login") String login, @WebParam(name = "password") String password) throws LoginException {
String auth_code = "";
bk_end.Validate val = new bk_end.Validate();
boolean isValidated = val.check(login, password);
if(isValidated)
{
auth_code = val.return_AuthCode();
bank_services.CustomerSerice.setAuth_Code(auth_code);
return auth_code;
}
throw new LoginException("Something is wrong!");
}
以及异常类:
public class LoginException extends Exception
{
String message;
public LoginException(String message)
{
super();
this.message = message;
}
public String getErrorMessage()
{
return this.message;
}
}
抛出一个巨大的 异常详情:java.lang.reflect.InvocationTargetException 加上大量其他例外.. 我意识到这是一个非常愚蠢的问题,但是在尝试了很多小时后,我只是不知道该怎么做。 我已经阅读了有关 @WebFault 的内容,但不知道如何正确指定它(将我的异常附加到特定方法..)
请帮忙,我们欢迎所有想法!
我遇到的例外情况: 服务调用抛出异常消息:null;有关详细信息,请参阅服务器日志
Exceptions details : java.lang.reflect.InvocationTargetException
javax.servlet.ServletException: java.lang.reflect.InvocationTargetException
at org.glassfish.webservices.monitoring.WebServiceTesterServlet.doPost(WebServiceTesterServlet.java:330)
at org.glassfish.webservices.monitoring.WebServiceTesterServlet.invoke(WebServiceTesterServlet.java:106)
at org.glassfish.webservices.EjbWebServiceServlet.service(EjbWebServiceServlet.java:114)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at com.sun.grizzly.http.servlet.ServletAdapter$FilterChainImpl.doFilter(ServletAdapter.java:1002)
at com.sun.grizzly.http.servlet.ServletAdapter$FilterChainImpl.invokeFilterChain(ServletAdapter.java:942)
at com.sun.grizzly.http.servlet.ServletAdapter.doService(ServletAdapter.java:404)
...
Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.glassfish.webservices.monitoring.WebServiceTesterServlet.doPost(WebServiceTesterServlet.java:301)
... 24 more
Caused by: bank_services.LoginException_Exception: excepts.LoginException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:145)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:123)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:93)
at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:144)
at $Proxy383.checkUserExist(Unknown Source) ... 29 more
【问题讨论】:
-
你说当你抛出 LoginException 时,你会得到“几十个其他异常,但我想要的那个”。您能否向我们展示一下引发了哪些异常?
-
没错,用所需的详细信息更新了我的问题!
-
有人...?我已经一整天了,必须有解决方案,这是一个初学者的问题......
-
你“想要”什么例外?我不明白他的问题是什么。
InvocationTargetException的原因应该是导致问题的异常。 -
好的,我上面的错误 - 不是我“想要”任何异常,而是我想要实现的是能够(在客户端)获得“出现问题”异常消息当被抓住时......
标签: java exception soap service web