/[cvs]/nfo/php/libs/org.netfrag.glib/DataSource/Proxy/XMLRPC.php
ViewVC logotype

Diff of /nfo/php/libs/org.netfrag.glib/DataSource/Proxy/XMLRPC.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by joko, Thu Mar 27 16:05:01 2003 UTC revision 1.5 by joko, Fri Mar 28 06:56:52 2003 UTC
# Line 14  Line 14 
14  ##    $Id$  ##    $Id$
15  ##    --------------------------------------------------------------------------  ##    --------------------------------------------------------------------------
16  ##    $Log$  ##    $Log$
17    ##    Revision 1.5  2003/03/28 06:56:52  joko
18    ##    updated logging/debugging code
19    ##
20    ##    Revision 1.4  2003/03/28 03:00:12  joko
21    ##    enhanced error- and exception-handling
22    ##
23  ##    Revision 1.3  2003/03/27 16:05:01  joko  ##    Revision 1.3  2003/03/27 16:05:01  joko
24  ##    enhanced 'function _call': debugging, tracing and autodisconnect now parametrized  ##    enhanced 'function _call': debugging, tracing and autodisconnect now parametrized
25  ##  ##
# Line 95  loadModule('Class::Logger'); Line 101  loadModule('Class::Logger');
101  class DataSource_Proxy_XMLRPC extends Class_Logger {  class DataSource_Proxy_XMLRPC extends Class_Logger {
102    
103    var $configured;    var $configured;
104    var $meta;    var $meta = array();
105      var $response = null;
106      var $errors = array();
107        
108    function DataSource_Proxy_XMLRPC($args = array()) {    function DataSource_Proxy_XMLRPC($args = array()) {
109    
110      parent::constructor();      parent::constructor();
111    
112      //print Dumper($this, $args);      //print Dumper($this, $args);
113        //print Dumper($args);
114    
115      global $Data_Driver_RPC_Remote_meta;      global $Data_Driver_RPC_Remote_meta;
116      session_register_safe("Data_Driver_RPC_Remote_meta");      session_register_safe("Data_Driver_RPC_Remote_meta");
117      $this->meta = $Data_Driver_RPC_Remote_meta;      $this->meta = $Data_Driver_RPC_Remote_meta;
118    
119        // force connect?
120        
121        // V1
122        /*
123      if (!isset($this->meta[connected]) || $args[connect]) {      if (!isset($this->meta[connected]) || $args[connect]) {
124        $this->meta[connected] = 1;        $this->meta[connected] = 1;
125      }      }
126        */
127    
128        // V2
129        $this->FORCE_CONNECT = $args[connect];
130    
131      $this->_save_meta();      $this->_save_meta();
132    
133    
134      // merge args - V1      // merge args - V1
135      //if ($args['Host']) { $this->HOST = $args['Host']; }      //if ($args['Host']) { $this->HOST = $args['Host']; }
136      //if ($args['Port']) { $this->PORT = $args['Port']; }      //if ($args['Port']) { $this->PORT = $args['Port']; }
# Line 122  class DataSource_Proxy_XMLRPC extends Cl Line 141  class DataSource_Proxy_XMLRPC extends Cl
141      //print Dumper($args);      //print Dumper($args);
142      if (is_array($args)) {      if (is_array($args)) {
143        foreach ($args as $key => $val) {        foreach ($args as $key => $val) {
144            //print "key: $key<br/>";
145          $key = strtoupper($key);          $key = strtoupper($key);
146          $this->$key = $val;          $this->$key = $val;
147        }        }
# Line 151  class DataSource_Proxy_XMLRPC extends Cl Line 171  class DataSource_Proxy_XMLRPC extends Cl
171    
172      $this->log(get_class($this) . "->send: " . $command, PEAR_LOG_DEBUG);      $this->log(get_class($this) . "->send: " . $command, PEAR_LOG_DEBUG);
173            
174        /*
175      if (!$this->isConnected()) {      if (!$this->isConnected()) {
176        $this->_raiseException( "->send[ command=$command ]: not connected while trying to send command!");        $this->_raiseException( "->send[ command=$command ]: not connected while trying to send command!");
177        return;        return;
178      }      }
179        */
180            
181      // do 'encode' here and ...      // do 'encode' here and ...
182      if ($options[utf8]) {      if ($options[utf8]) {
# Line 182  class DataSource_Proxy_XMLRPC extends Cl Line 204  class DataSource_Proxy_XMLRPC extends Cl
204      $data_debug = $data;      $data_debug = $data;
205      if (is_array($data_debug)) { $data_debug = join(", ", $data_debug); }      if (is_array($data_debug)) { $data_debug = join(", ", $data_debug); }
206      $options_debug = join(", ", $options_list);      $options_debug = join(", ", $options_list);
207      $this->log(get_class($this) . ": " . $command . "(" . $data_debug . ") [" . $options_debug . "]", PEAR_LOG_DEBUG);      $this->log(get_class($this) . "->_call: " . $command . "(" . $data_debug . ") [" . $options_debug . "]", PEAR_LOG_DEBUG);
208    
209      // trace      // trace
210        //print "call: $command<hr>";        //print "call: $command<hr>";
# Line 206  class DataSource_Proxy_XMLRPC extends Cl Line 228  class DataSource_Proxy_XMLRPC extends Cl
228      // done: now possible to declare tracing at this point in configuration      // done: now possible to declare tracing at this point in configuration
229      //    Please look inside your {appname}/etc/hosts/{hostname}.php      //    Please look inside your {appname}/etc/hosts/{hostname}.php
230      $rpc->setDebug($this->TRACE);      $rpc->setDebug($this->TRACE);
231        //$rpc->setDebug(1);
232            
233      if ( !$msg_response = $rpc->send($msg) ) {      if ( $this->response = $rpc->send($msg) ) {
234          // intermediate result error checking
235          $this->_checkException();
236        } else {
237        // TODO: redirect this error elsewhere!        // TODO: redirect this error elsewhere!
238        //print "RPC-error!<br>";        //print "RPC-error!<br>";
239        $this->_raiseException( "->_call: no response");        $this->_raiseException( "->_call: no response");
240        return;        return;
241      }      }
242        
243      // message - response      // message - response
244      $response_enc = $msg_response->value();      $response_enc = $this->response->value();
   
     // error handling  
     //    Please look inside your {appname}/etc/hosts/{hostname}.php for toggling $this->DEBUG  
     if ($this->DEBUG && $error_code = $msg_response->faultCode()) {  
       //print $msg_response->faultString();  
       $this->_raiseException( "->_call: " . $msg_response->faultString() );  
     }  
245    
246      // TODO: what's this? prematurely returning here should not be considered "stable"....      // TODO: what's this? prematurely returning here should not be considered "stable"....
247      return $this->decodeData($response_enc, $options);      return $this->decodeData($response_enc, $options);
# Line 243  class DataSource_Proxy_XMLRPC extends Cl Line 262  class DataSource_Proxy_XMLRPC extends Cl
262            $encoder->toISO();            $encoder->toISO();
263          //}          //}
264                    
265          $this->meta[connected] = 1;          $this->_be_connected();
266          $this->_save_meta();          
   
267          return $data;          return $data;
268        } else {        } else {
269          //print "ERROR!<br>";          //print "ERROR!<br>";
# Line 253  class DataSource_Proxy_XMLRPC extends Cl Line 271  class DataSource_Proxy_XMLRPC extends Cl
271        }        }
272    }    }
273        
274    function _raiseException($message) {    function _be_connected() {
275        $this->meta[connected] = 1;
276        $this->_save_meta();
277      }
278      
279      function _raiseException($message, $code = null) {
280        
281        $classname = get_class($this);
282        
283        // aggregate errors for this run/query
284        $this->_add_error($classname . $message, $code);
285            
286      // spout out the error message of the raised exception      // spout out the error message of the raised exception
287      $this->log(get_class($this) . $message, PEAR_LOG_ERR);      $this->log($classname . $message, PEAR_LOG_ERR);
288    
289      // handle some stuff regarding more special behaviour (will this get a 'rule' sometimes?)      // handle some stuff regarding more special behaviour (will this get rule-based sometimes?)
290      if ($this->isConnected() && $this->DISCONNECT_ON_ERROR) {      
291        // handle 'FORCE_CONNECT'
292        $connect_condition = $this->FORCE_CONNECT = ($this->isConnected() && $this->DISCONNECT_ON_ERROR);
293        if ($connect_condition) {
294        $message = '->_raiseException: [DISCONNECT_ON_ERROR] done transparently. Please reconnect manually.';        $message = '->_raiseException: [DISCONNECT_ON_ERROR] done transparently. Please reconnect manually.';
295        $this->log(get_class($this) . $message, PEAR_LOG_WARNING);        $this->_add_error($classname . $message, $code);
296          //$this->log($classname . $message, PEAR_LOG_WARNING);
297          $this->log($classname . $message, PEAR_LOG_ERR);
298        $this->meta[connected] = 0;        $this->meta[connected] = 0;
299        $this->_save_meta();        $this->_save_meta();
300      }      }
# Line 275  class DataSource_Proxy_XMLRPC extends Cl Line 308  class DataSource_Proxy_XMLRPC extends Cl
308      $this->_call('ping');      $this->_call('ping');
309    }    }
310        
311    
312      function _checkException() {
313        //    Please look inside your {appname}/etc/hosts/{hostname}.php for toggling $this->DEBUG
314        if ($error_code = $this->response->faultCode()) {
315          //print $msg_response->faultString();
316          $this->_raiseException( "->_call: " . $this->response->faultString(), $error_code );
317        }
318      }
319    
320        //if ($this->DEBUG && $error_code = $msg_response->faultCode()) {
321    
322    
323      function _add_error($message, $code) {
324        array_push( $this->errors, array(code => $code, message => $message) );
325      }
326      
327      function getStatus() {
328        return array( connected => $this->isConnected(), errors => $this->errors );
329      }
330      
331  }  }
332    
333  ?>  ?>

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.5

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed