vgritsenko    2003/12/11 06:06:16

  Modified:    java/src/org/apache/xindice/client/xmldb/xmlrpc
                        CollectionImpl.java
               java/src/org/apache/xindice/server/rpc
                        RPCDefaultMessage.java RPCMessageInterface.java
  Log:
  Attempt to pass at least some diagnostic info through xmlrpc.
  This is really dirty hack and better suggestions are very welcome.
  Add exception handling TODOs.
  
  Revision  Changes    Path
  1.36      +29 -16    
xml-xindice/java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java
  
  Index: CollectionImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- CollectionImpl.java       21 Aug 2003 18:14:53 -0000      1.35
  +++ CollectionImpl.java       11 Dec 2003 14:06:16 -0000      1.36
  @@ -73,6 +73,7 @@
   import org.apache.xindice.xml.dom.DOMParser;
   import org.apache.xindice.xml.dom.DocumentImpl;
   import org.apache.xmlrpc.XmlRpcClient;
  +import org.apache.xmlrpc.XmlRpcException;
   
   import org.w3c.dom.Document;
   import org.xml.sax.InputSource;
  @@ -89,6 +90,7 @@
   import java.net.MalformedURLException;
   import java.util.Hashtable;
   import java.util.Vector;
  +import java.util.StringTokenizer;
   
   /**
    * Implementation of XML:DB's <code>Collection</code> interface using
  @@ -148,6 +150,7 @@
               /* Just check the collection does actually exist */
               Hashtable params = new Hashtable();
               params.put(RPCDefaultMessage.COLLECTION, collPath);
  +            // TODO: In case of error get error code. Current XMLPRC does 
not provide place for detailed error code.
               String exists = (String) 
runRemoteCommand("GetCollectionConfiguration", params);
   
               if (!"yes".equals(exists)) {
  @@ -161,13 +164,11 @@
               throw x;  // propagate any xmldb exception.
           } catch (IOException e) {
               client = null;
  -            // TODO: What is appropriate error code?
  -            throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR,
  +            throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR, 
FaultCodes.GEN_GENERAL_ERROR,
                                        "Cannot communicate with the server: " 
+ xmlRpcURL, e);
           } catch (Exception e) {
               client = null;
  -            // TODO: What is appropriate error code?
  -            throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION,
  +            throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR, 
FaultCodes.JAVA_RUNTIME_ERROR,
                                        "Collection not found: " + collPath, e);
           }
       }
  @@ -184,11 +185,27 @@
        */
       private Object runRemoteCommand(String cmdName, Hashtable params) throws 
Exception {
   
  -        params.put(RPCMessageInterface.MESSAGE_PARAM, cmdName);
  -
  -        Vector v = new Vector();
  -        v.add(params);
  -        return ((Hashtable) client.execute("run", 
v)).get(RPCDefaultMessage.RESULT);
  +        try {
  +            params.put(RPCMessageInterface.MESSAGE_PARAM, cmdName);
  +            Vector v = new Vector();
  +            v.add(params);
  +            return ((Hashtable) client.execute("run", 
v)).get(RPCDefaultMessage.RESULT);
  +        } catch (XmlRpcException e) {
  +            // HACK: Dirty hack to pass at least some diagnostic info 
through XmlRpc
  +            //       See also RPCMessageInterface.run()
  +            StringTokenizer st = new StringTokenizer(e.getMessage(), ":");
  +            if (st.countTokens() >= 4) {
  +                try {
  +                    st.nextToken();
  +                    throw new 
XMLDBException(Integer.parseInt(st.nextToken().trim()),
  +                                             
Integer.parseInt(st.nextToken().trim()),
  +                                             st.nextToken("").trim());
  +                } catch (NumberFormatException e1) {
  +                    // Ignore
  +                }
  +            }
  +            throw e;
  +        }
       }
   
       /**
  @@ -610,26 +627,22 @@
       /* see superclass for documentation */
       public void removeCollection(String childName) throws XMLDBException {
   
  -        // TODO: shortcut the call and fail immediatly if the collection 
name is null or empty
  +        // TODO: Shortcut the call and fail immediatly if the collection 
name is null or empty
   
           checkOpen();
           try {
  -
               Hashtable params = new Hashtable();
               params.put(RPCDefaultMessage.COLLECTION, collPath);
               params.put(RPCDefaultMessage.NAME, childName);
               String result = (String) runRemoteCommand("RemoveCollection", 
params);
   
               if (!result.equals("yes")) {
  -
                   throw new XMLDBException(ErrorCodes.INVALID_COLLECTION,
                                            "Cannot remove child collection[" + 
childName + "]");
               }
           } catch (XMLDBException x) {
  -
               throw x;  // propagate any xmldb exception.
           } catch (Exception e) {
  -
               throw new XMLDBException(ErrorCodes.INVALID_COLLECTION,
                                        "Cannot remove child collection[" + 
childName + "]", e);
           }
  
  
  
  1.11      +3 -2      
xml-xindice/java/src/org/apache/xindice/server/rpc/RPCDefaultMessage.java
  
  Index: RPCDefaultMessage.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/server/rpc/RPCDefaultMessage.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- RPCDefaultMessage.java    7 Aug 2003 20:13:23 -0000       1.10
  +++ RPCDefaultMessage.java    11 Dec 2003 14:06:16 -0000      1.11
  @@ -128,6 +128,7 @@
   
               Database db = Database.getDatabase(dbName);
               if (db == null) {
  +                // TODO: Pass an error code. Current XMLPRC does not provide 
place for detailed error code.
                   throw new Exception("Database " + dbName + " could not be 
found");
               }
               Collection col = db.getCollection(colName);
  
  
  
  1.7       +24 -4     
xml-xindice/java/src/org/apache/xindice/server/rpc/RPCMessageInterface.java
  
  Index: RPCMessageInterface.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/server/rpc/RPCMessageInterface.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- RPCMessageInterface.java  7 Aug 2003 20:13:23 -0000       1.6
  +++ RPCMessageInterface.java  11 Dec 2003 14:06:16 -0000      1.7
  @@ -59,6 +59,14 @@
   
   package org.apache.xindice.server.rpc;
   
  +import org.apache.xindice.core.DBException;
  +import org.apache.xindice.core.Collection;
  +import org.apache.xmlrpc.XmlRpcException;
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
  +
  +import org.xmldb.api.base.ErrorCodes;
  +
   import java.util.Hashtable;
   
   /**
  @@ -67,11 +75,23 @@
    */
   public final class RPCMessageInterface {
   
  +    private static final Log log = LogFactory.getLog(Collection.class);
  +
       public static final String MESSAGE_PARAM = "message";
   
       public Hashtable run(Hashtable message) throws Exception {
           // The method determines what class we load to handle the message.
  -        RPCMessage handler = (RPCMessage) 
Class.forName("org.apache.xindice.server.rpc.messages." + 
message.get(MESSAGE_PARAM)).newInstance();
  -        return handler.execute(message);
  +        String type = (String)message.get(MESSAGE_PARAM);
  +        try {
  +            RPCMessage handler = (RPCMessage) 
Class.forName("org.apache.xindice.server.rpc.messages." + type).newInstance();
  +            return handler.execute(message);
  +        } catch (DBException e) {
  +            if (log.isDebugEnabled()) {
  +                log.debug("Exception while processing XmlRpc command " + 
type, e);
  +            }
  +            // HACK: Dirty hack to pass at least some diagnostic info 
through XmlRpc
  +            //       See also 
org.apache.xindice.client.xmldb.xmlrpc.CollectionImpl.runRemoteCommand()
  +            throw new XmlRpcException(0, ErrorCodes.VENDOR_ERROR + ":" + 
e.faultCode + ":" + e.getMessage());
  +        }
       }
   }
  
  
  

Reply via email to