/** * Constructor, requires the url of the remote Hessian service * * @param string url Url of the remote service **/ function __construct($url, $options = false) { $this->__hessian__proxy__ =& Hessian_Hessian::getHessianProxy($url, $options); }
/** * Publishes the service, check incoming calls and routes them to the wrapped object.<BR> * This method uses streams to retrieve raw POST bytes and a * {@link HessianPHP.HessianParser HessianParser} and {@link HessianPHP.HessianWriter HessianWriter} * to execute the call and send results back to the client. * * As defined in Hessian 1.0 spec, the service requires POST to execute. It is advised not to call<BR> * any other php code that writes to the default screen output (echo, print, etc.) as it can corrupt * the reply. * * @access public **/ function service() { if (!is_object($this->serviceInfo->service)) { header("HTTP/1.0 500 Hessian not configured"); die('Serviced object not registered!'); } if ($_SERVER['REQUEST_METHOD'] != 'POST') { if ($this->displayInfo) { $this->serviceInfo->displayInfo(); exit; } else { header("HTTP/1.0 500 Hessian Requires POST"); die('<h1>Hessian Requires POST</h1>'); } } ob_start(); // apparently it wins a few milliseconds // handle errorReporting if ($this->errorReporting) { $this->_restoreError = error_reporting($this->errorReporting); } // uso de streams para obtener informaci�n cruda del post $ph = fopen("php://input", "rb"); $postData = ''; while (!feof($ph)) { $postData .= fread($ph, 4096); } fclose($ph); $this->parser->setStream($postData); $method =& $this->parser->parseCall(); $result = null; if (Hessian_Hessian::isError($method)) { $this->writer->setFault($method->code, $method->message, $method->getError()); } else { $params = array(); $error = false; while (!$this->parser->endStream()) { $param =& $this->parser->parseObject(); if (Hessian_Hessian::isError($param)) { $this->writer->setFault($param->code, $param->message, $param->getError()); $error = true; break; } else { $params[] =& $param; } } // little hack to get rid of the finishing code 'z' in the parameter list if (!$error) { $last = count($params) - 1; unset($params[$last]); // end hack $result = $this->serviceInfo->callMethod($method, $params, $this->writer); } } $reply = trim($this->writer->writeReply($result)); header('Content-type: application/binary'); header('Content-length: ' . strlen($reply)); header('Connection: close'); $nfp = fopen("php://output", "wb+"); fwrite($nfp, trim($reply)); fclose($nfp); //echo $reply; ob_end_flush(); // restore error reporting level if ($this->errorReporting) { error_reporting($this->_restoreError); } }