我创建了一个自定义异常类来处理我项目的所有错误
它与SOAP Web服务相关联,这就是@WebFault
的原因。
@WebFault(name = "GTWFaultBean", targetNamespace = "http://www.test.com")
public class GTWException extends Exception implements Serializable
{
/**
*
*/
private static final long serialVersionUID = 6512673270706929264L;
private String errorDescription;
private String errorLocation;
public GTWException(String errorDescription, String errorLocation) {
super();
this.errorDescription = errorDescription;
this.errorLocation = errorLocation;
}
public String getException()
{
String error = "location:"+errorLocation+"|*SEP*|"+"description:"+errorDescription;
return error;
}
public int getExceptionId()
{
int exceptionId = 1;
if(errorDescription!=null)
{
exceptionId = 0;
}
return exceptionId;
}
public static String toString(Throwable th) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
th.printStackTrace(pw);
return sw.toString();
}
}
这是我的控制台输出
javax.xml.ws.WebServiceException: java.lang.NoSuchMethodException: lu.br.ged.exception.GTWException.<init>(java.lang.String)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createUserDefinedException(SOAPFaultBuilder.java:312)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:130)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:108)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:135)
at com.sun.proxy.$Proxy10.create(Unknown Source)
at controller.WSconsumer.consumeWS(WSconsumer.java:69)
at controller.WSconsumer.main(WSconsumer.java:87)
Caused by: java.lang.NoSuchMethodException: lu.br.ged.exception.GTWException.<init>(java.lang.String)
at java.lang.Class.getConstructor0(Class.java:2892)
at java.lang.Class.getConstructor(Class.java:1723)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createUserDefinedException(SOAPFaultBuilder.java:308)
... 7 more
我自己搜索了很多,但我无法解决问题。
编辑:
正如提议的那样,我添加了一个带有单个字符串参数的新构造函数。
错误已更改为
exception.GTWException
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:526)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createUserDefinedException(SOAPFaultBuilder.java:309)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:130)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:108)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:135)
at com.sun.proxy.$Proxy10.create(Unknown Source)
at controller.WSconsumer.consumeWS(WSconsumer.java:69)
at controller.WSconsumer.main(WSconsumer.java:87)
我做错了什么?