Click to See Complete Forum and Search --> : Client catching Web Service User Exceptions [Java 6.0.17]


Shaitan00
November 18th, 2009, 06:51 PM
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,

Deliverance
November 18th, 2009, 08:42 PM
http://java.sun.com/javaee/5/docs/api/javax/xml/ws/WebFault.html

should be used on the exception class you want to be marshalled and information included about in your wsdl otherwise the client won't see it, but it will be wrapped in a general soap exception.

Shaitan00
November 18th, 2009, 10:40 PM
UserException has @WebFault already - or is it missing something?
I catch the exception, and it is in the WSDL, but it looks like either the String ErrorMessage isn't returning correctly...

Deliverance
November 19th, 2009, 10:29 AM
what version of metro is this?

Shaitan00
November 19th, 2009, 10:54 PM
What do you mean "Metro"?

Deliverance
November 20th, 2009, 09:49 AM
http://java.sun.com/webservices/

Do you see the soap fault definition in the generated wsdl?

I would expect the definition to look similar to something like this:


<message name="function">
<part name="fault" element="tns:UserException"/>
</message>

...

<operation name="functionEvent">
<input message="tns:functionResponseEvent"/>
<output message="tns:functionEventResponse"/>
<fault message="tns:UserException" name="UserException"/>
</operation>

...

<fault name="UserException">
<soap:fault name="UserException" use="literal"/>
</fault>

Shaitan00
November 21st, 2009, 06:34 PM
Yes I see something similar, the difference is the custom GetMessage() function is not in the WSDL.
Actually - it looks like using the super (Message) solved the problem ...