简体   繁体   English

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

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

I am trying to send an EXCEPTION from a Web Server to a Client using JAX-WS ... When the exception is thrown by the server the client does catch it ... but the contents are not the expected message... 我正在尝试使用JAX-WS从Web服务器向客户端发送EXCEPTION ...服务器抛出异常时,客户端会捕获到该异常...但是内容不是预期的消息...

Server.java 服务器.java

package pck;

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

Exception.java 异常

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;
    }
}

Client.java 客户端.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());
        }
    }
}

Now, as I mentioned, when the exception is thrown by the server the client does catch it, but ex.ErrorMessage() returns the string “pck.UserException” instead of “Something” which it was created with in the Server... any clues as to why? 现在,正如我提到的,当服务器抛出异常时,客户端会捕获该异常,但是ex.ErrorMessage()返回字符串“ pck.UserException”,而不是在服务器中使用它创建的“ Something”。为什么有任何线索?

Also, when I run my WebService I keep getting the following messages in the output: com.sun.xml.internal.ws.model.RuntimeModeler getExceptionBeanClass 另外,当我运行WebService时,我不断在输出中得到以下消息:com.sun.xml.internal.ws.model.RuntimeModeler getExceptionBeanClass
INFO: Dynamically creating exception bean Class pck.jaxws.UserExceptionBean INFO:动态创建异常bean类pck.jaxws.UserExceptionBean

Any clues or help would be much appreciated. 任何线索或帮助将不胜感激。 Thanks, 谢谢,

Not sure, but your custom exception looks odd. 不确定,但是您的自定义异常看起来很奇怪。 You should in fact super the message: 实际上,您应该super提示:

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

This way you can get it by e.getMessage() . 这样,您可以通过e.getMessage()获得它。 See if it helps. 看看是否有帮助。

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

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