I am sorry but I think your answer did not help … probably because my previous question confusing …

 

Here with I’ll give you another example hopefully this would be clear …

 

Suppose I have a Server =

 

public class TesServer {

   public TesServer() {

        WebServer webserver = null;

        try {

            webserver = new WebServer (7001);

        } catch (UnknownHostException e) {

            e.printStackTrace();  //To change body of catch statement use Options | File Templates.

            System.out.println("lewat");

        }

 

        webserver.addHandler("Something",new SomethingHandler());

        webserver.start();

    }

 

    public static void main(String [] args)

    {

 

          new TesServer();

 

    }

 

}

 

with a Handler =

 

class SomethingHandler implements XmlRpcHandler

{

    public Object execute(String method, Vector params)

    { 

       // DO SOMETHING

       //  CONNECTION BROKEN …………………… SOMEHOW                           

       return params;

    }

}

 

 

and a Client =

 

public class TesXmlRPC  {

 

    public static void main(String[] args) {

        try {

 

            XmlRpcClient xmlrpc = new XmlRpcClient("http://10.0.7.222:7001");

 

            Vector v = new Vector(1);

            v.add(“TEST”);

            Vector result = (Vector) xmlrpc.execute("Something.methodX", v);

        } catch (Exception e) {

            e.printStackTrace();

        }

 

    }

}

 

 

Then I run my Server …..

 

Then I run my Client …..

 

When my client “try to” execute

           

Vector result = (Vector) xmlrpc.execute("Something.methodX", v);  // plz see TesXmlRPC class

 

Then the Client connect to server  .But Before the server produce any result (so the method above not done yet) …. The connection is somehow broken ….. // see  class SomethingHandler

 

 

Then in the Server console screen is written something like this…………………. java.net.SocketException: Connection reset by peer: socket write error  // this happen because I kill the Client in the middle of executing “xmlrpc.execute” …

 

My Question is where can I catch the exception (example : java.net.SocketException: Connection reset by peer: socket write error  ) in my Server class or Handler Class?

 

Is my question is clear now? If not please ask me for more information …

 

Thank you …..

 

 

 

 

 

 

 

 

-----Original Message-----
From: Waldron, Terry [mailto:[EMAIL PROTECTED]]
Sent
:
Saturday, March 20, 2004 1:15 AM
To: [EMAIL PROTECTED]
Subject: RE: [Newbie Quetion] How can I check my RPC return value

 

Try Catch Block will do the trick...

-----Original Message-----
From: Dave Stewart [mailto:[EMAIL PROTECTED]
Sent:
March 19, 2004 1:00 PM
To: [EMAIL PROTECTED]
Subject: Re: [Newbie Quetion] How can I check my RPC return value

Hi Bagas!

 

(Caution: I'm not any certified expert in any way, just played with this myself a bit ...)

 

I'm not sure I'm following your question, but I'll give it a shot anyway ...

 

On Mar 18, 2004, at 10:49 PM, bagas wrote:

 

Dear All, 

 

I am building a XML-RPC Server using org.apache.xmlrpc.WebServer.

I now encounter a problem; the problem is how can I track my response (result). 

 

Here is an example : 

 

Suppose I have a Class = 

 

Public class AServer implements XmlRpcHandler

{

            WebServer serv;

 

            public static void main(String [] args)

            {

                        Aserver(100);

            }           

 

            public AServer(int i)

            {

                        serv = Webserver(i);

                        serv.addHandler("$default", this);

            }

 

public Object execute(String method, Vector params)

            {

                        //do something

                        return something;

            }

 

after AServer running ….. there are 3 message coming …..

 

Um, clarification here ... you mean you've called execute with a method name and 3 arguments in params, right?

 

 

then the server send a response (result of the method) right ??

 

According to the documentation, execute() should either return a result *OR THROW AN EXCEPTION*. The result will be a java.lang.Object unless something went wrong, in which case it will throw a java.lang.Exception that will need to be caught somewhere.

 

 

 

My question is how can I track the response (result) of the message if I urgently needed to know whether the response (result) is sent or fail to be sent.

 

Well, how is your server (AServer) dealing with it? You could either be trapping the exception with a try/catch block or passing it back to the caller (the class that invoked execute() and sent 3 messages in params).

 

Maybe that's the hint you need, the documentation for the interface XmlRpcHandler specifies that the execute() method will either return a result (as a java.lang.Object) or will throw an exception (specifically a java.lang.Exception). If the result was sent, it will be in the Object returned. If it failed, details will be in the Exception.

 

If you are trapping that Exception in AServer itself, then I would suggest creating an Object that you could return that will be recognized as a problem and testing for that in the calling method. If you are passing the Exception back to the invoker (which is what I would do), then I don't get the question since it should be obvious if it worked or not (you'll either get an Object back or you'll catch an Exception, which kind of answers the question doesn't it?)

 

 

 

Thank you very much …

 

I just hope I've been of some help. ;-)



Dave Stewart

Aqua~Flo Supply (Goleta CA)

dstewart at aquaflo dot com

 

Law of Probability Dispersal:

Whatever it is that hits the fan

will not be evenly distributed.

Reply via email to