Update of /cvsroot/monetdb/java/src/nl/cwi/monetdb/xquery/xrpc/client
In directory 
sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv19545/src/nl/cwi/monetdb/xquery/xrpc/client

Modified Files:
        XRPCTestClient.java 
Log Message:
be more precise with the exceptions we throw, to make it easier to
dicide which ones should be reported to the calling peer, and which ones
not.



Index: XRPCTestClient.java
===================================================================
RCS file: 
/cvsroot/monetdb/java/src/nl/cwi/monetdb/xquery/xrpc/client/XRPCTestClient.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- XRPCTestClient.java 5 Dec 2007 17:02:00 -0000       1.1
+++ XRPCTestClient.java 6 Dec 2007 18:18:48 -0000       1.2
@@ -76,13 +76,13 @@
     private CmdLineOpts opts;
 
        XRPCTestClient()
-        throws Exception
+        throws OptionsException
     {
         opts = initCmdLineOpts();
     }
 
     private static CmdLineOpts initCmdLineOpts()
-        throws Exception
+        throws OptionsException
     {
                CmdLineOpts copts = new CmdLineOpts();
 
@@ -126,7 +126,7 @@
     }
 
     private void parseOptions(String[] args)
-        throws Exception
+        throws OptionsException
     {
         String usage = 
             "Usage: java -jar xrpcwrapper-test.jar [options]\n" +
@@ -176,8 +176,14 @@
                             "\" extracted to \"" + toFile + "\"");
                 }
             }
-        } catch (Exception e){
-            e.printStackTrace();
+        } catch (OptionsException oe){
+            oe.printStackTrace();
+            System.exit(1);
+        } catch (FileNotFoundException fe){
+            fe.printStackTrace();
+            System.exit(1);
+        } catch (IOException ioe){
+            ioe.printStackTrace();
             System.exit(1);
         }
     }
@@ -195,14 +201,14 @@
                             fn + "\" deleted");
                 }
             }
-        } catch (Exception e){
+        } catch (OptionsException e){
             e.printStackTrace();
             System.exit(1);
         }
     }
 
     private String generateRequestMessage()
-        throws Exception
+        throws OptionsException, XRPCException
     {
         String method = opts.getOption("function").getArgument();
         String rootdir = opts.getOption("rootdir").getArgument();
@@ -312,7 +318,7 @@
                         ) ));
 
             } else {
-                throw new Exception("generateRequestMessage(): " +
+                throw new XRPCException("generateRequestMessage(): " +
                         "unknow function " + method);
             }
         }
@@ -328,7 +334,9 @@
     }
 
     private void extractResults(StringBuffer response)
-        throws Exception
+        throws XRPCException, XPathExpressionException,
+                          TransformerConfigurationException,
+                          TransformerException
     {
         String msg = response.toString();
         
@@ -345,7 +353,7 @@
         /* Find and check the prefix of the XRPC namespace URI */
         int i = response.indexOf(":sequence");
         if (i < 0) {
-            throw new Exception("Invalid response message: " +
+            throw new XRPCReceiverException("Invalid response message: " +
                     "no sequence element found");
         }
         int j = i - 1;
@@ -354,7 +362,7 @@
         /* check the namespace */
         String nsURI = XRPCMessage.getNamespaceURI(msg, xrpcPrefix);
         if(!nsURI.equals(XRPCMessage.XRPC_NS)){
-            throw new Exception("Expected namespace URI: " +
+            throw new XRPCReceiverException("Expected namespace URI: " +
                     XRPCMessage.XRPC_NS + "; " +
                     "found namespace URI: " + nsURI);
         }
@@ -393,29 +401,32 @@
     }
 
     private void doXRPCCall()
-        throws Exception
     {
-        String reqMsg = generateRequestMessage();
-        if(opts.getOption("verbose").isPresent()){
-            System.out.println("doXRPCCall(): " +
-                    "request message to send: \n");
-            System.out.print(reqMsg.toString());
-        }
+        try{
+            String reqMsg = generateRequestMessage();
+            if(opts.getOption("verbose").isPresent()){
+                System.out.println("doXRPCCall(): " +
+                        "request message to send: \n");
+                System.out.print(reqMsg.toString());
+            }
 
-        StringBuffer respMsg = XRPCHTTPConnection.sendReceive(
-                opts.getOption("server").getArgument() + XRPCD_CALLBACK,
-                reqMsg);
-        if(opts.getOption("verbose").isPresent()){
-            System.out.println("doXRPCCall(): " +
-                    "response message received: \n");
-            System.out.println(respMsg.toString());
-        }
+            StringBuffer respMsg = XRPCHTTPConnection.sendReceive(
+                    opts.getOption("server").getArgument() + XRPCD_CALLBACK,
+                    reqMsg);
+            if(opts.getOption("verbose").isPresent()){
+                System.out.println("doXRPCCall(): " +
+                        "response message received: \n");
+                System.out.println(respMsg.toString());
+            }
 
-        extractResults(respMsg);
+            extractResults(respMsg);
+        } catch (Exception e){
+            e.printStackTrace();
+            System.exit(1);
+        }
     }
 
     private void callAllFunctions()
-        throws Exception
     {
         String[] functions = {
             "echoVoid",
@@ -429,13 +440,18 @@
             "buyerAndAuction",
             "auctionsOfBuyer"};
 
-        CmdLineOpts.OptionContainer funcOpt = opts.getOption("function");
-        for(int i = 0; i < functions.length; i++){
-            funcOpt.resetArguments();
-            funcOpt.addArgument(functions[i]);
-            System.out.println("\n********** callAllFunctions(): " +
-                    "calling function \"" + functions[i] + "\" **********");
-            doXRPCCall();
+        try {
+            CmdLineOpts.OptionContainer funcOpt = opts.getOption("function");
+            for(int i = 0; i < functions.length; i++){
+                funcOpt.resetArguments();
+                funcOpt.addArgument(functions[i]);
+                System.out.println("\n********** callAllFunctions(): " +
+                        "calling function \"" + functions[i] + "\" 
**********");
+                doXRPCCall();
+            }
+        } catch (OptionsException oe){
+            oe.printStackTrace();
+            System.exit(1);
         }
     }
 
@@ -455,8 +471,8 @@
 
             /* delete temporiry files, if necessary */
             tc.deleteFiles();
-        } catch (Exception e) {
-            e.printStackTrace();
+        } catch (OptionsException oe) {
+            oe.printStackTrace();
             System.exit(1);
         }
     }


-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins

Reply via email to