users@jax-rpc.java.net

RE: Re: exception handling

From: Ian Jones <ijones_at_piper-group.com>
Date: Wed, 11 May 2005 10:01:18 +0100

Hi Doug,

Thanks for that. However I have tried your suggestion and I still get
the same result. Here are a few more details about what I'm doing - any
more help you can give will be greatly appreciated:

This is where I throw the exception in my implementation class:

    public String login(String password) throws RemoteException,
InvalidPasswordException {
        Environment env = Environment.getInstance();
        String dmPassword =
env.getMainConfig().getDataManagerPassword();
        if (password.equals(dmPassword)) {
            String sessionId = getSessionId();
            return sessionId;
        } else {
            throw new InvalidPasswordException();
        }
    }

And here is my latest version of the InvalidPasswordException class,
with your suggested changes:

public class InvalidPasswordException extends Exception {

    public InvalidPasswordException() {
        super("Invalid password");
    }

}

When the exception gets thrown by the implementation class the server
generates the following stack trace (this is just the first few lines):



SEVERE: JAXRPC.TIE.01: caught exception while handling request:
com.piper.trilogiview.datamanager.exceptions.InvalidPasswordException:
Invalid password
com.piper.trilogiview.datamanager.exceptions.InvalidPasswordException:
Invalid password
        at
com.piper.trilogiview.datamanager.DataManagerImpl.login(DataManagerImpl.
java:53)
        at
com.piper.trilogiview.datamanager.DataManagerIF_Tie.invoke_login(DataMan
agerIF_Tie.java:248)
        at
com.piper.trilogiview.datamanager.DataManagerIF_Tie.processingHook(DataM
anagerIF_Tie.java:1445)
        at
com.sun.xml.rpc.server.StreamingHandler.handle(StreamingHandler.java:228
)
        at
com.sun.xml.rpc.server.http.JAXRPCServletDelegate.doPost(JAXRPCServletDe
legate.java:316)



Meanwhile the stack trace of the exception caught on the client is this
(again, just the first few lines):



java.rmi.ServerException: JAXRPC.TIE.04: Internal Server Error
(JAXRPC.TIE.01: caught exception while handling request:
com.piper.trilogiview.datamanager.exceptions.InvalidPasswordException:
Invalid password)
        at
com.sun.xml.rpc.client.StreamingSender._raiseFault(StreamingSender.java:
372)
        at
com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:224)
        at
com.piper.datamanagertest.jaxrpc.DataManagerIF_Stub.login(DataManagerIF_
Stub.java:188)
        at
com.piper.datamanagertest.testclient.LoginTest.testInvalidLogin(LoginTes
t.java:71)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
a:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.java:25)


As you can see the client exception is a ServerException which seems to
reference the InvalidPasswordException within it.

I'm using wscompile to generate WSDL, server ties and client stubs from
the Java interface. Is there anything I need to add to any of the
config files for these to do with exceptions, as I haven't added
anything at the moment? Or is there a flag I need to specify on
wscompile? Here are the flags I'm using for wscompile at the moment:

For WSDL generation:
-define -g com/piper/datamanager/wsdl-gen-config.xml -model
WEB-INF/DataManager.gz -classpath WEB-INF/classes -nd WEB-INF

For generating server ties:
-g -gen:server -f:searchschema com\piper\datamanager\tie-gen-config.xml

For generating client stubs:
-gen:client -keep com/piper/datamanagertest/jaxrpc/client-stubs.xml
-f:searchschema

Again, many thanks for any further help with this,

Ian.

-----Original Message-----
From: Doug Kohlert [mailto:Doug.Kohlert_at_Sun.COM]
Sent: 10 May 2005 18:28
To: users_at_jax-rpc.dev.java.net
Subject: Re: exception handling

Ian,
InvalidPasswordException_Exception is the proper name on the client. Try

modifying your
exception class on the server to be:

public class InvalidPasswordException extends Exception {

public InvalidPasswordException() {

super("bad password");

}


}

and see if that works.

Ian Jones wrote:

> All,
>
> I'm attempting to throw a service-specific exception in my JAX-RPC web

> service. This exception is defined, simply, as follows:
>
> public class InvalidPasswordException extends Exception {
>
> public InvalidPasswordException() {
>
> }
>
> }
>
> and is thrown in the interface of my web service here:
>
> String login(String password) throws RemoteException,
>
> InvalidPasswordException;
>
> I then use wscompile to generate the WSDL, server ties and client
> stubs. However the client stub generated for the exception is called
> InvalidPasswordException_Exception and this is thrown by the login
> method's client stub. Is this what should happen?
>
> In my client I attempt to catch this
> InvalidPasswordException_Exception exception as follows:
>
> try {
>
> client.login("random");
>
> fail("Password was not invalid");
>
> } catch (InvalidPasswordException_Exception e) {
>
> return;
>
> } catch (ServerException e) {
>
> fail(e.getMessage());
>
> } catch (Exception e) {
>
> e.printStackTrace();
>
> fail("failed due to exception " + e.getMessage());
>
> }
>
> In this case the server correctly attempts to throw a new
> InvalidPasswordException, but the client catches a ServerException
> which mentions the InvalidPasswordException within it's message. Is
> this also correct? Shouldn't I just be able to catch an
> InvalidPasswordException as specified by the service's interface?
>
> Many thanks for any help,
>
> Ian Jones
>
> Senior Analyst Developer
>
> Piper Group plc
>
> Email: ijones_at_piper-group.com
>
> Tel: + 44 (0) 1454 284900
>
> Fax: + 44 (0) 1454 284950
>
> www.piper-group.com <http://www.piper-group.com/>
>
> Information contained in this e-mail is intended for the use of the
> addressee only, and is confidential and may be the subject of legal
> professional privilege. Any dissemination, distribution, copying or
> use of this communication without permission of the addressee is
> strictly prohibited. The views expressed in this communication may not

> necessarily be the views held by Piper Group plc.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jax-rpc.dev.java.net
For additional commands, e-mail: users-help_at_jax-rpc.dev.java.net