vgritsenko    2004/02/18 19:05:15

  Modified:    java/src/org/apache/xindice/client/xmldb/xmlrpc
                        CollectionImpl.java
               java/src/org/apache/xindice/core FaultCodes.java
               java/src/org/apache/xindice/server/rpc
                        RPCDefaultMessage.java RPCMessageInterface.java
               .        status.xml
  Log:
  Improve XML-RPC interface: pass XMLDB exceptions as XML-RPC faults.
  Combine XMLDB error code and Xindice FaultCode into one number using
  FaultCode.MAX_CODE
  
  Revision  Changes    Path
  1.45      +15 -19    
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.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- CollectionImpl.java       13 Feb 2004 03:34:17 -0000      1.44
  +++ CollectionImpl.java       19 Feb 2004 03:05:14 -0000      1.45
  @@ -111,21 +111,13 @@
               return ((Hashtable) client.execute("run", 
v)).get(RPCDefaultMessage.RESULT);
           } catch (XmlRpcException e) {
               if (log.isDebugEnabled()) {
  -                log.debug("Got XmlRpc exception running command " + cmdName, 
e);
  +                log.debug("Got XmlRpc exception running command " + cmdName 
+ ", code: " + e.code + ", msg: " + e.getMessage());
               }
   
  -            // 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
  -                }
  +            if (e.code != 0) {
  +                throw new XMLDBException(e.code /  FaultCodes.MAX_CODE,
  +                                         e.code % FaultCodes.MAX_CODE,
  +                                         e.getMessage());
               }
   
               throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR, 
FaultCodes.GEN_GENERAL_ERROR,
  @@ -582,24 +574,28 @@
       /* 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
  +        if (null == childName || childName.length() == 0) {
  +            throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION,
  +                                     FaultCodes.COL_COLLECTION_NOT_FOUND,
  +                                     "Cannot remove child collection '" + 
childName + "': Name is empty");
  +        }
   
           checkOpen();
           try {
               Hashtable params = new Hashtable();
               params.put(RPCDefaultMessage.COLLECTION, collPath);
               params.put(RPCDefaultMessage.NAME, childName);
  -            String result = (String) runRemoteCommand("RemoveCollection", 
params);
   
  +            String result = (String) runRemoteCommand("RemoveCollection", 
params);
               if (!result.equals("yes")) {
                   throw new XMLDBException(ErrorCodes.INVALID_COLLECTION,
  -                                         "Cannot remove child collection[" + 
childName + "]");
  +                                         "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);
  +                                     "Cannot remove child collection '" + 
childName + "'", e);
           }
       }
   
  
  
  
  1.20      +7 -2      
xml-xindice/java/src/org/apache/xindice/core/FaultCodes.java
  
  Index: FaultCodes.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/core/FaultCodes.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- FaultCodes.java   8 Feb 2004 02:51:06 -0000       1.19
  +++ FaultCodes.java   19 Feb 2004 03:05:14 -0000      1.20
  @@ -32,6 +32,11 @@
    */
   public abstract class FaultCodes {
   
  +    /**
  +     * Defines maximum possible fault code
  +     */
  +    public static final int MAX_CODE  = 10000;
  +
       private static final Map faultMessages = new HashMap();
   
       public static final int GEN  =    0;
  
  
  
  1.14      +19 -8     
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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- RPCDefaultMessage.java    8 Feb 2004 02:54:26 -0000       1.13
  +++ RPCDefaultMessage.java    19 Feb 2004 03:05:15 -0000      1.14
  @@ -19,10 +19,18 @@
   package org.apache.xindice.server.rpc;
   
   import org.apache.xindice.core.Collection;
  +import org.apache.xindice.core.DBException;
   import org.apache.xindice.core.Database;
  +import org.apache.xmlrpc.XmlRpcException;
  +
  +import org.xmldb.api.base.ErrorCodes;
  +import org.xmldb.api.base.XMLDBException;
   
   /**
  + * Base class for all XML-RPC messages.
  + *
    * @author <a href="mailto:[EMAIL PROTECTED]">Kimbro Staken</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a>
    * @version CVS $Revision$, $Date$
    */
   public abstract class RPCDefaultMessage implements RPCMessage {
  @@ -61,9 +69,9 @@
        *
        * @param name The collection to retrieve
        * @return The Collection value
  -     * @exception Exception
  +     * @exception XmlRpcException
        */
  -    protected Collection getCollection(String name) throws Exception {
  +    protected Collection getCollection(String name) throws XmlRpcException, 
XMLDBException, DBException {
           // Get rid of any trailling slashes.
           while (name.endsWith("/")) {
               name = name.substring(0, name.lastIndexOf("/"));
  @@ -88,17 +96,20 @@
   
               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");
  +                throw new XMLDBException(ErrorCodes.NO_SUCH_DATABASE,
  +                                         "Database '" + dbName + "' could 
not be found");
               }
  +
               Collection col = db.getCollection(colName);
               if (col == null) {
  -                throw new Exception("Collection " + colName + " could not be 
found");
  +                throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION,
  +                                         "Collection '" + colName + "' could 
not be found");
               }
   
               return col;
           } else {
  -            throw new Exception("Collection name must begin with a '/'");
  +            throw new XMLDBException(ErrorCodes.INVALID_URI,
  +                                     "Collection name must begin with a 
'/'");
           }
       }
   }
  
  
  
  1.9       +12 -5     
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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- RPCMessageInterface.java  8 Feb 2004 02:54:26 -0000       1.8
  +++ RPCMessageInterface.java  19 Feb 2004 03:05:15 -0000      1.9
  @@ -20,11 +20,13 @@
   
   import org.apache.xindice.core.DBException;
   import org.apache.xindice.core.Collection;
  +import org.apache.xindice.core.FaultCodes;
   import org.apache.xmlrpc.XmlRpcException;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
   import org.xmldb.api.base.ErrorCodes;
  +import org.xmldb.api.base.XMLDBException;
   
   import java.util.Hashtable;
   
  @@ -44,13 +46,18 @@
           try {
               RPCMessage handler = (RPCMessage) 
Class.forName("org.apache.xindice.server.rpc.messages." + type).newInstance();
               return handler.execute(message);
  +        } catch (XMLDBException e) {
  +            if (log.isDebugEnabled()) {
  +                log.debug("Exception while processing XmlRpc command " + 
type, e);
  +            }
  +
  +            throw new XmlRpcException(e.errorCode * FaultCodes.MAX_CODE + 
e.vendorErrorCode, e.getMessage());
           } 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());
  +
  +            throw new XmlRpcException(ErrorCodes.VENDOR_ERROR * 
FaultCodes.MAX_CODE + e.faultCode, e.getMessage());
           }
       }
   }
  
  
  
  1.33      +3 -0      xml-xindice/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/xml-xindice/status.xml,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- status.xml        13 Feb 2004 03:34:17 -0000      1.32
  +++ status.xml        19 Feb 2004 03:05:15 -0000      1.33
  @@ -70,6 +70,9 @@
       <changes>
           <release version="1.1b4-dev" date="February 11 2004">
               <action dev="VG" type="update">
  +                XML-RPC interface now passes XMLDBException codes as XML-RPC 
faults.
  +            </action>
  +            <action dev="VG" type="update">
                   Xindice server and XML-RPC driver support basic HTTP 
authentication.
               </action>
               <action dev="VG" type="update">
  
  
  

Reply via email to