| 14 |
## $Id$ |
## $Id$ |
| 15 |
## -------------------------------------------------------------------------- |
## -------------------------------------------------------------------------- |
| 16 |
## $Log$ |
## $Log$ |
| 17 |
|
## Revision 1.4 2003/03/28 03:00:12 joko |
| 18 |
|
## enhanced error- and exception-handling |
| 19 |
|
## |
| 20 |
## Revision 1.3 2003/03/27 16:05:01 joko |
## Revision 1.3 2003/03/27 16:05:01 joko |
| 21 |
## enhanced 'function _call': debugging, tracing and autodisconnect now parametrized |
## enhanced 'function _call': debugging, tracing and autodisconnect now parametrized |
| 22 |
## |
## |
| 98 |
class DataSource_Proxy_XMLRPC extends Class_Logger { |
class DataSource_Proxy_XMLRPC extends Class_Logger { |
| 99 |
|
|
| 100 |
var $configured; |
var $configured; |
| 101 |
var $meta; |
var $meta = array(); |
| 102 |
|
var $response = null; |
| 103 |
|
var $errors = array(); |
| 104 |
|
|
| 105 |
function DataSource_Proxy_XMLRPC($args = array()) { |
function DataSource_Proxy_XMLRPC($args = array()) { |
| 106 |
|
|
| 107 |
parent::constructor(); |
parent::constructor(); |
| 108 |
|
|
| 109 |
//print Dumper($this, $args); |
//print Dumper($this, $args); |
| 110 |
|
//print Dumper($args); |
| 111 |
|
|
| 112 |
global $Data_Driver_RPC_Remote_meta; |
global $Data_Driver_RPC_Remote_meta; |
| 113 |
session_register_safe("Data_Driver_RPC_Remote_meta"); |
session_register_safe("Data_Driver_RPC_Remote_meta"); |
| 114 |
$this->meta = $Data_Driver_RPC_Remote_meta; |
$this->meta = $Data_Driver_RPC_Remote_meta; |
| 115 |
|
|
| 116 |
|
// force connect? |
| 117 |
|
|
| 118 |
|
// V1 |
| 119 |
|
/* |
| 120 |
if (!isset($this->meta[connected]) || $args[connect]) { |
if (!isset($this->meta[connected]) || $args[connect]) { |
| 121 |
$this->meta[connected] = 1; |
$this->meta[connected] = 1; |
| 122 |
} |
} |
| 123 |
|
*/ |
| 124 |
|
|
| 125 |
|
// V2 |
| 126 |
|
$this->FORCE_CONNECT = $args[connect]; |
| 127 |
|
|
| 128 |
$this->_save_meta(); |
$this->_save_meta(); |
| 129 |
|
|
| 130 |
|
|
| 131 |
// merge args - V1 |
// merge args - V1 |
| 132 |
//if ($args['Host']) { $this->HOST = $args['Host']; } |
//if ($args['Host']) { $this->HOST = $args['Host']; } |
| 133 |
//if ($args['Port']) { $this->PORT = $args['Port']; } |
//if ($args['Port']) { $this->PORT = $args['Port']; } |
| 198 |
$data_debug = $data; |
$data_debug = $data; |
| 199 |
if (is_array($data_debug)) { $data_debug = join(", ", $data_debug); } |
if (is_array($data_debug)) { $data_debug = join(", ", $data_debug); } |
| 200 |
$options_debug = join(", ", $options_list); |
$options_debug = join(", ", $options_list); |
| 201 |
$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); |
| 202 |
|
|
| 203 |
// trace |
// trace |
| 204 |
//print "call: $command<hr>"; |
//print "call: $command<hr>"; |
| 222 |
// done: now possible to declare tracing at this point in configuration |
// done: now possible to declare tracing at this point in configuration |
| 223 |
// Please look inside your {appname}/etc/hosts/{hostname}.php |
// Please look inside your {appname}/etc/hosts/{hostname}.php |
| 224 |
$rpc->setDebug($this->TRACE); |
$rpc->setDebug($this->TRACE); |
| 225 |
|
//$rpc->setDebug(1); |
| 226 |
|
|
| 227 |
if ( !$msg_response = $rpc->send($msg) ) { |
if ( $this->response = $rpc->send($msg) ) { |
| 228 |
|
// intermediate result error checking |
| 229 |
|
$this->_checkException(); |
| 230 |
|
} else { |
| 231 |
// TODO: redirect this error elsewhere! |
// TODO: redirect this error elsewhere! |
| 232 |
//print "RPC-error!<br>"; |
//print "RPC-error!<br>"; |
| 233 |
$this->_raiseException( "->_call: no response"); |
$this->_raiseException( "->_call: no response"); |
| 234 |
return; |
return; |
| 235 |
} |
} |
| 236 |
|
|
| 237 |
// message - response |
// message - response |
| 238 |
$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() ); |
|
|
} |
|
| 239 |
|
|
| 240 |
// TODO: what's this? prematurely returning here should not be considered "stable".... |
// TODO: what's this? prematurely returning here should not be considered "stable".... |
| 241 |
return $this->decodeData($response_enc, $options); |
return $this->decodeData($response_enc, $options); |
| 256 |
$encoder->toISO(); |
$encoder->toISO(); |
| 257 |
//} |
//} |
| 258 |
|
|
| 259 |
$this->meta[connected] = 1; |
$this->_be_connected(); |
| 260 |
$this->_save_meta(); |
|
|
|
|
| 261 |
return $data; |
return $data; |
| 262 |
} else { |
} else { |
| 263 |
//print "ERROR!<br>"; |
//print "ERROR!<br>"; |
| 265 |
} |
} |
| 266 |
} |
} |
| 267 |
|
|
| 268 |
function _raiseException($message) { |
function _be_connected() { |
| 269 |
|
$this->meta[connected] = 1; |
| 270 |
|
$this->_save_meta(); |
| 271 |
|
} |
| 272 |
|
|
| 273 |
|
function _raiseException($message, $code = null) { |
| 274 |
|
|
| 275 |
|
// aggregate errors for this run/query |
| 276 |
|
$this->_add_error($message, $code); |
| 277 |
|
|
| 278 |
// spout out the error message of the raised exception |
// spout out the error message of the raised exception |
| 279 |
$this->log(get_class($this) . $message, PEAR_LOG_ERR); |
$this->log(get_class($this) . $message, PEAR_LOG_ERR); |
| 280 |
|
|
| 281 |
// 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?) |
| 282 |
if ($this->isConnected() && $this->DISCONNECT_ON_ERROR) { |
|
| 283 |
|
// handle 'FORCE_CONNECT' |
| 284 |
|
$connect_condition = $this->FORCE_CONNECT = ($this->isConnected() && $this->DISCONNECT_ON_ERROR); |
| 285 |
|
if ($connect_condition) { |
| 286 |
$message = '->_raiseException: [DISCONNECT_ON_ERROR] done transparently. Please reconnect manually.'; |
$message = '->_raiseException: [DISCONNECT_ON_ERROR] done transparently. Please reconnect manually.'; |
| 287 |
$this->log(get_class($this) . $message, PEAR_LOG_WARNING); |
$this->_add_error($message, $code); |
| 288 |
|
//$this->log(get_class($this) . $message, PEAR_LOG_WARNING); |
| 289 |
|
$this->log(get_class($this) . $message, PEAR_LOG_ERR); |
| 290 |
$this->meta[connected] = 0; |
$this->meta[connected] = 0; |
| 291 |
$this->_save_meta(); |
$this->_save_meta(); |
| 292 |
} |
} |
| 300 |
$this->_call('ping'); |
$this->_call('ping'); |
| 301 |
} |
} |
| 302 |
|
|
| 303 |
|
|
| 304 |
|
function _checkException() { |
| 305 |
|
// Please look inside your {appname}/etc/hosts/{hostname}.php for toggling $this->DEBUG |
| 306 |
|
if ($error_code = $this->response->faultCode()) { |
| 307 |
|
//print $msg_response->faultString(); |
| 308 |
|
$this->_raiseException( "->_call: " . $this->response->faultString(), $error_code ); |
| 309 |
|
} |
| 310 |
|
} |
| 311 |
|
|
| 312 |
|
//if ($this->DEBUG && $error_code = $msg_response->faultCode()) { |
| 313 |
|
|
| 314 |
|
|
| 315 |
|
function _add_error($message, $code) { |
| 316 |
|
array_push( $this->errors, array(code => $code, message => $message) ); |
| 317 |
|
} |
| 318 |
|
|
| 319 |
|
function getStatus() { |
| 320 |
|
return array( connected => $this->isConnected(), errors => $this->errors ); |
| 321 |
|
} |
| 322 |
|
|
| 323 |
} |
} |
| 324 |
|
|
| 325 |
?> |
?> |