繁体   English   中英

客户端捕获Web服务用户异常[Java 6.0.17]

[英]Client catching Web Service User Exceptions [Java 6.0.17]

我正在尝试使用JAX-WS从Web服务器向客户端发送EXCEPTION ...服务器抛出异常时,客户端会捕获到该异常...但是内容不是预期的消息...

服务器.java

package pck;

@WebService()
public class Server
{
    @WebMethod()
    public function() throws UserException
    {
    throw new UserException(“Something”);
    }
}

异常

import javax.xml.ws.WebFault;

@WebFault()
public class UserException
        extends Exception
{
    private String ErrMessage;

    public UserException(String message)
    {
        this.ErrMessage = message;
    }

    public String ErrorMessage()
    {
        return this.ErrMessage;
    }
}

客户端.java

public class Client
{
    public static void main(String[] args) throws Exception
    {
    try
        {
        Server.function();
        }
    catch (UserException ex)
        {
        System.out.println("User Exception: " + ex.ErrorMessage());
        }
    }
}

现在,正如我提到的,当服务器抛出异常时,客户端会捕获该异常,但是ex.ErrorMessage()返回字符串“ pck.UserException”,而不是在服务器中使用它创建的“ Something”。为什么有任何线索?

另外,当我运行WebService时,我不断在输出中得到以下消息:com.sun.xml.internal.ws.model.RuntimeModeler getExceptionBeanClass
INFO:动态创建异常bean类pck.jaxws.UserExceptionBean

任何线索或帮助将不胜感激。 谢谢,

不确定,但是您的自定义异常看起来很奇怪。 实际上,您应该super提示:

public UserException(String message) {
    super(message);
}

这样,您可以通过e.getMessage()获得它。 看看是否有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM