users@jax-ws.java.net

"from java" exceptions

From: Levi Purvis <javanet_at_purvis.ws>
Date: Tue, 24 Oct 2006 11:48:51 -0400

I posted the question below to the forum a few days ago:

http://forums.java.net/jive/thread.jspa?messageID=166395

I thought I'd send it here as well, since I still can't get it to work
and it looks like it might be a bug. I also tried again with jax-ws
2.1 ea2.

I'm using jax-ws & jax-b using the "from java" annotations approach. I
have clients and servers working fine that share the same service
interfaces and jax-b payloads.

However, the only way I can get the client to use the same exception
class as is defined on the service interface is to use the @WebFault
annotation on the exception with a pointer to a faultBean and
hand-code the two "magic" exception constructors and the "magic"
getFaultInfo() method. Is this possible *without* the @WebFault
annotation and the "magic" exception constructors/method?

For example, lets say I have service interface:

@WebService
public interface Echo {

   @WebMethod
   public String echo(String s) throws EchoException;
}

And simple exception:

public class EchoException extends Exception {
}

I deploy this interface and exception on the client and create a
dynamic proxy using javax.xml.ws.Service. I want my client to be able
to use code such as this:

try {
echo.echo("foo");
} catch (EchoException e) {
// handle exception
}

Note that I'm not catching EchoException_Exception (I want to share
the same exception class as on the server).

Is this possible? When I try it out I get the following exception from
within the jax-ws (2.1 EA 2) runtime. It looks like it *should* be
possible from reading the code in
SOAPFaultBuilder.createUserDefinedException() and
RuntimeModeler.processExceptions().

javax.xml.ws.WebServiceException: java.lang.NoSuchMethodException:
com.xyz.EchoException.setELEMENT_NODE()
        at com.sun.xml.ws.fault.SOAPFaultBuilder.createUserDefinedException(SOAPFaultBuilder.java:210)
        at com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:94)
        at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:248)
        at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:212)
        at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:101)
        at $Proxy26.echo(Unknown Source)
        ...
Caused by: java.lang.NoSuchMethodException:
com.xyz.EchoException.setELEMENT_NODE()
        at java.lang.Class.getMethod(Class.java:1581)
        at com.sun.xml.ws.fault.SOAPFaultBuilder.createUserDefinedException(SOAPFaultBuilder.java:205)
        ... 23 more


Note that it *does* work if I add the "magic" constructors/methods
that are put in generated code:

        public EchoException(String message, EchoFault faultInfo) {
                super(message);
                this.fault = faultInfo;
        }

        public EchoException(
                        String message,
                        EchoFault faultInfo,
                        Throwable cause) {
                super(message, cause);
                this.fault = faultInfo;
        }

        public EchoFault getFaultInfo() {
                return fault;
        }