[geeklog-cvs] Auth_Enterprise/Client AEXMLRPCClient.class.php,1.4,1.5

tony at iowaoutdoors.org tony at iowaoutdoors.org
Mon Jun 21 00:58:24 EDT 2004


Update of /var/cvs/Auth_Enterprise/Client
In directory www:/tmp/cvs-serv4572

Modified Files:
	AEXMLRPCClient.class.php 
Log Message:
Now checks for XMLRPC faults and if one is encountered it throws a PHP5 exception

Index: AEXMLRPCClient.class.php
===================================================================
RCS file: /var/cvs/Auth_Enterprise/Client/AEXMLRPCClient.class.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** AEXMLRPCClient.class.php	19 Jun 2004 20:45:00 -0000	1.4
--- AEXMLRPCClient.class.php	21 Jun 2004 04:58:22 -0000	1.5
***************
*** 17,25 ****
  
  /**
! * Abstract client provider
  */
  require_once 'Auth_Enterprise/Client/AEBaseClientProvider.class.php';
  
  /**
  * PEAR's XML RPC Client
  */
--- 17,35 ----
  
  /**
! * Auth_Enterprise abstract client provider
  */
  require_once 'Auth_Enterprise/Client/AEBaseClientProvider.class.php';
  
  /**
+ * Auth_Enterprise constants
+ */
+ require_once 'Auth_Enterprise/Common/AEConstants.php';
+ 
+ /**
+ * Auth_Enterprise exceptions
+ */
+ require_once 'Auth_Enterprise/Common/AEExceptions.php';
+ 
+ /**
  * PEAR's XML RPC Client
  */
***************
*** 116,119 ****
--- 126,140 ----
                  , new XML_RPC_Value($password, 'string')));
          $response = $this->XMLRPCClient->send($xmlRequest);
+         
+         // If we got a fault, throw an exception back to the calling
+         // application
+         if ($response->faultCode()) {
+             try {
+                 throw $this->faultToException($response->faultCode(), $response->faultString());
+             } catch (AEBaseException $e) {
+                 throw $e;
+             }
+         }
+         
          $retval = $response->value();
          $retval = XML_RPC_decode($retval);
***************
*** 140,146 ****
          }
          $user->setGroups($groupArray);
!         /*if (!$response->faultCode()) {
!             
!         }*/
          return $user;
      }
--- 161,166 ----
          }
          $user->setGroups($groupArray);
!         
!         
          return $user;
      }
***************
*** 163,166 ****
--- 183,191 ----
                  , new XML_RPC_Value($password, 'string')));
          $response = $this->_XMLRPCClient->send($xmlRequest);
+         // If we got a fault, throw an exception back to the calling
+         // application
+         if ($response->faultCode()) {
+             throw $this->faultToException($response->faultCode(), $response->faultString());
+         }
          $retval = $response->value();
          $retval = XML_RPC_decode($retval);
***************
*** 182,187 ****
                  , new XML_RPC_Value($newPassword, 'string')));
          $response = $this->_XMLRPCClient->send($xmlRequest);
!         $retval = $response->value();
!         $retval = XML_RPC_decode($retval);
      }
      
--- 207,215 ----
                  , new XML_RPC_Value($newPassword, 'string')));
          $response = $this->_XMLRPCClient->send($xmlRequest);
!         // If we got a fault, throw an exception back to the calling
!         // application
!         if ($response->faultCode()) {
!             throw $this->faultToException($response->faultCode(), $response->faultString());
!         }
      }
      
***************
*** 204,209 ****
                  , new XML_RPC_Value($newPassword, 'string')));
          $response = $this->_XMLRPCClient->send($xmlRequest);
!         $retval = $response->value();
!         $retval = XML_RPC_decode($retval);
      }
      
--- 232,240 ----
                  , new XML_RPC_Value($newPassword, 'string')));
          $response = $this->_XMLRPCClient->send($xmlRequest);
!         // If we got a fault, throw an exception back to the calling
!         // application
!         if ($response->faultCode()) {
!             throw $this->faultToException($response->faultCode(), $response->faultString());
!         }
      }
      
***************
*** 222,225 ****
--- 253,261 ----
                  , new XML_RPC_Value($userName, 'string')));
          $response = $this->_XMLRPCClient->send($xmlRequest);
+         // If we got a fault, throw an exception back to the calling
+         // application
+         if ($response->faultCode()) {
+             throw $this->faultToException($response->faultCode(), $response->faultString());
+         }
          $retval = $response->value();
          $retval = XML_RPC_decode($retval);
***************
*** 242,245 ****
--- 278,286 ----
                  , new XML_RPC_Value($userName, 'string')));
          $response = $this->_XMLRPCClient->send($xmlRequest);
+         // If we got a fault, throw an exception back to the calling
+         // application
+         if ($response->faultCode()) {
+             throw $this->faultToException($response->faultCode(), $response->faultString());
+         }
          $retval = $response->value();
          $retval = XML_RPC_decode($retval);
***************
*** 263,268 ****
                  , new XML_RPC_Value($privArray, 'array')));
          $response = $this->_XMLRPCClient->send($xmlRequest);
!         $retval = $response->value();
!         $retval = XML_RPC_decode($retval);
      }
      
--- 304,312 ----
                  , new XML_RPC_Value($privArray, 'array')));
          $response = $this->_XMLRPCClient->send($xmlRequest);
!         // If we got a fault, throw an exception back to the calling
!         // application
!         if ($response->faultCode()) {
!             throw $this->faultToException($response->faultCode(), $response->faultString());
!         }
      }
      
***************
*** 282,285 ****
--- 326,334 ----
                  , new XML_RPC_Value($adminPassword, 'string')));
          $response = $this->_XMLRPCClient->send($xmlRequest);
+         // If we got a fault, throw an exception back to the calling
+         // application
+         if ($response->faultCode()) {
+             throw $this->faultToException($response->faultCode(), $response->faultString());
+         }
          $retval = $response->value();
          $retval = XML_RPC_decode($retval);
***************
*** 302,305 ****
--- 351,359 ----
                  , new XML_RPC_Value($userName, 'string')));
          $response = $this->_XMLRPCClient->send($xmlRequest);
+         // If we got a fault, throw an exception back to the calling
+         // application
+         if ($response->faultCode()) {
+             throw $this->faultToException($response->faultCode(), $response->faultString());
+         }
          $retval = $response->value();
          $retval = XML_RPC_decode($retval);
***************
*** 323,328 ****
                  , new XML_RPC_Value($groupArray, 'array')));
          $response = $this->_XMLRPCClient->send($xmlRequest);
!         $retval = $response->value();
!         $retval = XML_RPC_decode($retval);
      }
      
--- 377,385 ----
                  , new XML_RPC_Value($groupArray, 'array')));
          $response = $this->_XMLRPCClient->send($xmlRequest);
!         // If we got a fault, throw an exception back to the calling
!         // application
!         if ($response->faultCode()) {
!             throw $this->faultToException($response->faultCode(), $response->faultString());
!         }
      }
      
***************
*** 350,353 ****
--- 407,459 ----
          return $groupArray;
      }
+     
+     /**
+     * Converts XML_RPC faults into exceptions
+     *
+     * @author Tony Bibbs <tony at geeklog.net>
+     * @access private
+     * @param int $faultCode XMLRPC fault code
+     * @param string $faultMessage XMLRPC fault message
+     * @return object PHP5 exception
+     *
+     */
+     private function faultToException($faultCode, $faultMessage)
+     {
+         switch ($faultCode) {
+             case AESQLExceptionResp:
+                 throw new AESQLException($faultMessage);
+                 break;
+             case AEInvalidUserCredentialsResp:
+                 throw new AEInvalidUserCredentials($faultMessage);
+                 break;
+             case AEAccountLockedResp:
+                 throw new AEAccountLocked($faultMessage);
+                 break;
+             case AEPasswordExpiredResp:
+                 throw new AEPasswordExpired($faultMessage);
+                 break;
+             case AEPasswordInHistoryResp:
+                 throw new AEPasswordInHistory($faultMessage);
+                 break;
+             case AEPasswordInvalidResp:
+                 throw new AEPasswordInvalid($faultMessage);
+                 break;
+             case AEUnableToConnectResp:
+                 throw new AEUnableToConnect($faultMessage);
+                 break;
+             case AEUserNotAuthorizedResp:
+                 throw new AEUserNotAuthorized($faultMessage);
+                 break;
+             case AEInvalidPrivilegeResp:
+                 throw new AEInvalidPrivilege($faultMessage);
+                 break;
+             case AEInsufficientClientOptionsResp:
+                 throw new AEInsufficientClientOptions($faultMessage);
+                 break;
+             case defaut:
+                 throw new Exception($faultMessage);
+             
+         }
+     }
  }
  




More information about the geeklog-cvs mailing list