开发者

Client catching Web Service User Exceptions [Java 6.0.17]

开发者 https://www.devze.com 2022-12-12 00:57 出处:网络
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...

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...

Server.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

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?

Also, when I run my WebService I keep开发者_运维百科 getting the following messages in the output: com.sun.xml.internal.ws.model.RuntimeModeler getExceptionBeanClass

INFO: Dynamically creating exception bean Class 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:

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

This way you can get it by e.getMessage(). See if it helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消