views:

221

answers:

1

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,

A: 

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.

BalusC
Nope - gives me the same string...
Shaitan00