You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by sn...@apache.org on 2005/12/11 04:51:03 UTC

svn commit: r355890 - /incubator/roller/trunk/src/org/roller/presentation/xmlrpc/BaseAPIHandler.java

Author: snoopdave
Date: Sat Dec 10 19:51:01 2005
New Revision: 355890

URL: http://svn.apache.org/viewcvs?rev=355890&view=rev
Log:
Better error reporting for XML-RPC APIs

Modified:
    incubator/roller/trunk/src/org/roller/presentation/xmlrpc/BaseAPIHandler.java

Modified: incubator/roller/trunk/src/org/roller/presentation/xmlrpc/BaseAPIHandler.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/xmlrpc/BaseAPIHandler.java?rev=355890&r1=355889&r2=355890&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/xmlrpc/BaseAPIHandler.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/xmlrpc/BaseAPIHandler.java Sat Dec 10 19:51:01 2005
@@ -37,21 +37,33 @@
     public static final String UNKNOWN_EXCEPTION_MSG = 
             "An error occured processing your request";
     
-    public static final int BLOGGERAPI_DISABLED = 1000;
-    public static final String BLOGGERAPI_DISABLED_MSG = 
-            "You have not enabled Blogger API support for your weblog";
-    
     public static final int UNSUPPORTED_EXCEPTION = 1001;
     public static final String UNSUPPORTED_EXCEPTION_MSG = 
             "Unsupported method - Roller does not support this method";
             
+    public static final int USER_DISABLED = 1002;
+    public static final String USER_DISABLED_MSG = 
+            "User is disabled";
+    
+    public static final int WEBLOG_NOT_FOUND = 1003;
+    public static final String WEBLOG_NOT_FOUND_MSG = 
+            "Weblog is not found or is disabled";
+    
+    public static final int WEBLOG_DISABLED = 1004;
+    public static final String WEBLOG_DISABLED_MSG = 
+            "Weblog is not found or is disabled";
+    
+    public static final int BLOGGERAPI_DISABLED = 1005;
+    public static final String BLOGGERAPI_DISABLED_MSG = 
+            "Weblog does not exist or XML-RPC disabled in web";
+    
     public static final int INVALID_POSTID = 2000;
     public static final String INVALID_POSTID_MSG = 
             "The entry postid you submitted is invalid";
             
-    public static final int NOBLOGS_EXCEPTION = 3000;
-    public static final String NOBLOGS_EXCEPTION_MSG = 
-            "There are no categories defined for your user";
+    //public static final int NOBLOGS_EXCEPTION = 3000;
+    //public static final String NOBLOGS_EXCEPTION_MSG = 
+            //"There are no categories defined for your user";
 
     public static final int UPLOAD_DENIED_EXCEPTION = 4000;
     public static final String UPLOAD_DENIED_EXCEPTION_MSG = 
@@ -80,7 +92,10 @@
     throws Exception
     {
         boolean authenticated = false;
-        boolean enabled = false;
+        boolean userEnabled = false;
+        boolean weblogEnabled = false;
+        boolean apiEnabled = false;
+        boolean weblogFound = false;
         WebsiteData website = null;
         UserData user = null;
         try
@@ -89,13 +104,17 @@
             RollerRequest rreq = RollerRequest.getRollerRequest();
             
             UserManager userMgr = RollerFactory.getRoller().getUserManager();
-            website = userMgr.getWebsiteByHandle(blogid);
             user = userMgr.getUser(username);
+            userEnabled = user.getEnabled().booleanValue();
             
-            enabled = website.getEnableBloggerApi().booleanValue() 
-                   && website.getEnabled().booleanValue() 
-                      && user.getEnabled().booleanValue();
-            if (enabled)
+            website = userMgr.getWebsiteByHandle(blogid);
+            if (website != null) {
+                weblogFound = true;
+                weblogEnabled = website.getEnabled().booleanValue();
+                apiEnabled = website.getEnableBloggerApi().booleanValue();
+            }
+            
+            if (user != null)
             {    
                 // are passwords encrypted?
                 RollerContext rollerContext = 
@@ -121,17 +140,31 @@
             mLogger.error("ERROR internal error validating user", e);
         }
         
-        if ( !enabled )
-        {
-            throw new XmlRpcException(
-                BLOGGERAPI_DISABLED, BLOGGERAPI_DISABLED_MSG);
-        }
-        
         if ( !authenticated )
         {
             throw new XmlRpcException(
                 AUTHORIZATION_EXCEPTION, AUTHORIZATION_EXCEPTION_MSG);
         }
+        if ( !userEnabled )
+        {
+            throw new XmlRpcException(
+                USER_DISABLED, USER_DISABLED_MSG);
+        }        
+        if ( !weblogEnabled )
+        {
+            throw new XmlRpcException(
+                WEBLOG_DISABLED, WEBLOG_DISABLED_MSG);
+        }        
+        if ( !weblogFound )
+        {
+            throw new XmlRpcException(
+                WEBLOG_NOT_FOUND, WEBLOG_NOT_FOUND_MSG);
+        }        
+        if ( !apiEnabled )
+        {
+            throw new XmlRpcException(
+                BLOGGERAPI_DISABLED, BLOGGERAPI_DISABLED_MSG);
+        }        
         return website;
     }
 
@@ -141,6 +174,7 @@
      * @param username Username sent in request
      * @param password Password sent in requeset
      */
+    /*
     protected boolean validateUser(String username, String password) 
     throws Exception
     {
@@ -194,7 +228,7 @@
                 AUTHORIZATION_EXCEPTION, AUTHORIZATION_EXCEPTION_MSG);
         }
         return authenticated;
-    }
+    }*/
     
     //------------------------------------------------------------------------
     protected void flushPageCache(WebsiteData website) throws Exception