示例#1
0
文件: Server.php 项目: knatorski/SMS
 public function handle($request = null)
 {
     $startTime = $this->_getCurrentTimestamp();
     if (null === $request) {
         $request = file_get_contents('php://input');
     }
     $db = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('multidb')->getDb('log');
     $cm = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('smssoapserverlogger');
     $write = new Zend_Log_Writer_Db($db, 'log.sms_soap_server', array('created_at' => 'created_at', 'in_method' => 'in_method', 'in_client_hash' => 'in_client_hash', 'in_service_hash' => 'in_service_hash', 'in_user_ip' => 'in_user_ip', 'in_xml' => 'in_xml', 'out_created_at' => 'out_created_at', 'out_xml' => 'out_xml'));
     $cm->setWriter($write);
     $logger = $cm->getLogObject();
     try {
         $functions = $this->getFunctions();
         $dom = new DOMDocument();
         $dom->loadXML($request);
         foreach ($functions as $function) {
             if ($dom->getElementsByTagName($function)->item(0)) {
                 $method = $function;
                 break;
             }
         }
         try {
             $preparedRequest = $this->_prepareSoapEnvelope($request);
         } catch (Exception $exc) {
             $this->_getSoap()->fault('043', "Błąd podczas tworzenia logów." . $exc->getMessage());
         }
         $clientHash = $dom->getElementsByTagName('clientHash')->item(0)->nodeValue;
         $serviceHash = $dom->getElementsByTagName('serviceHash')->item(0)->nodeValue;
         $logger->setEventItem('in_user_ip', $_SERVER['REMOTE_ADDR']);
         $logger->setEventItem('in_client_hash', $clientHash);
         $logger->setEventItem('in_service_hash', $serviceHash);
         $logger->setEventItem('in_method', $method);
         $logger->setEventItem('in_xml', json_encode($preparedRequest));
         $response = parent::handle($request);
         try {
             $preparedResponse = $this->_prepareSoapEnvelope($response);
         } catch (Exception $exc) {
             $this->_getSoap()->fault('043', "Błąd podczas tworzenia logów." . $exc->getMessage());
         }
         $logger->setEventItem('out_xml', json_encode($preparedResponse));
         $logger->setEventItem('created_at', new Zend_Db_Expr("timestamp with time zone '{$startTime}'"));
         $logger->setEventItem('out_created_at', new Zend_Db_Expr("timestamp with time zone '" . $this->_getCurrentTimestamp() . "'"));
         echo $this->_response;
         $logger->log('Wykonano.', Zend_Log::INFO);
     } catch (Exception $e) {
         $logger->setEventItem('in_user_ip', $_SERVER['REMOTE_ADDR']);
         $logger->setEventItem('in_client_hash', $clientHash);
         $logger->setEventItem('in_service_hash', $serviceHash);
         $logger->setEventItem('in_method', $method);
         $logger->setEventItem('created_at', new Zend_Db_Expr("timestamp with time zone '{$startTime}'"));
         $logger->setEventItem('in_xml', json_encode($preparedRequest));
         $logger->setEventItem('out_xml', $e->getMessage());
         $logger->log('Wyjątek!!!', Zend_Log::ERR);
         throw $e;
     }
     return $response;
 }
示例#2
0
 public function preDispatch()
 {
     parent::preDispatch();
     $request = $this->getRequest();
     if (isset($_GET['wsdl'])) {
         $webService = new Logic_WebService();
         if (!headers_sent()) {
             header('Content-Type: text/xml');
         }
         echo $webService->autodiscoverWsdlDocument();
     } else {
         $service = new Logic_Soap_Server(($_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1' ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . '?wsdl', array('soap_version' => SOAP_1_2, 'cache_wsdl' => WSDL_CACHE_MEMORY));
         $service->setClass(Logic_WebService::generateWSClassName());
         $service->setClassmap($this->_getWsClassMapping());
         $service->handle();
     }
     exit;
 }
示例#3
0
文件: Server.php 项目: knatorski/SMS
 public function handle($request = null)
 {
     $startTime = $this->_getCurrentTimestamp();
     try {
         $logger = Zend_Registry::get('mail_soap_logger');
     } catch (Exception $e) {
         $this->_getSoap()->fault('043', 'The logger "mail_soap_logger" is not set!');
     }
     if (null === $request) {
         $request = file_get_contents('php://input');
     }
     $functions = $this->getFunctions();
     $dom = new DOMDocument();
     $dom->loadXML($request);
     foreach ($functions as $function) {
         if ($dom->getElementsByTagName($function)->item(0)) {
             $method = $function;
             break;
         }
     }
     try {
         $preparedRequest = $this->_prepareSoapEnvelope($request);
     } catch (Exception $exc) {
         $this->_getSoap()->fault('043', "Error creating logs: " . $exc->getMessage());
     }
     $clientHash = $dom->getElementsByTagName('clientHash')->item(0)->nodeValue;
     $serviceHash = $dom->getElementsByTagName('serviceHash')->item(0)->nodeValue;
     $logger->setEventItem('in_user_ip', $_SERVER['REMOTE_ADDR']);
     $logger->setEventItem('in_client_hash', $clientHash);
     $logger->setEventItem('in_service_hash', $serviceHash);
     $logger->setEventItem('in_method', $method);
     $logger->setEventItem('in_xml', json_encode($preparedRequest));
     try {
         parent::handle($request);
         try {
             $preparedResponse = $this->_prepareSoapEnvelope($this->getLastResponse());
         } catch (Exception $exc) {
             $this->_getSoap()->fault('043', "Error creating logs: " . $exc->getMessage());
         }
         $logger->setEventItem('out_xml', json_encode($preparedResponse));
         $logger->setEventItem('created_at', $startTime);
         $logger->setEventItem('out_created_at', $this->_getCurrentTimestamp());
         if (isset($preparedResponse['Fault'])) {
             $logger->warn('Error');
         } else {
             $logger->info('Success');
         }
     } catch (Exception $e) {
         $logger->setEventItem('created_at', $startTime);
         $logger->setEventItem('in_xml', json_encode($preparedRequest));
         $logger->setEventItem('out_xml', json_encode(serialize($e->getTrace())));
         $logger->setEventItem('out_created_at', $this->_getCurrentTimestamp());
         $logger->emerg('Exception');
         $this->_getSoap()->fault($e->getCode(), $e->getMessage());
     }
 }
示例#4
0
文件: Server.php 项目: knatorski/SMS
 public function handle($request = null)
 {
     if (null === $request) {
         $request = file_get_contents('php://input');
     }
     $db = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('multidb')->getDb('log');
     $cm = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('orangesoapserverlogger');
     $write = new Zend_Log_Writer_Db($db, 'log.orange_soap_server', array('created_at' => 'timestamp', 'in_method' => 'in_method', 'in_user_ip' => 'in_user_ip', 'in_msg' => 'in_msg', 'out_created_at' => 'out_created_at', 'out_msg' => 'out_msg'));
     $cm->setWriter($write);
     //
     //$cm = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('orangesoapserverlogger');
     /* $columnMap = array(
               'created_at' => 'timestamp',
               'in_method' => 'in_method',
               'in_user_ip' => 'in_user_ip',
               'in_msg' => 'in_msg',
               'out_created_at' => 'out_created_at',
               'out_msg' => 'out_msg'
               );
     
               $orangesoapserver_writer = new Base_Log_Writer_Extendeddb($db, 'log.orange_soap_server', $columnMap);
     
               $orangesoapserver_log = new Zend_Log($orangesoapserver_writer);
               $cm = new Zend_Log($orangesoapserver_writer);
               //diee($orangesoapserver_log);
               Zend_Registry::set('orangesoapserverlogger', $orangesoapserver_log);
               //$cm = Zend_Registry::get('orangesoapserverlogger');
               //diee($cm);
               $write = new Zend_Log_Writer_Db($db, 'log.orange_soap_server', array(
               'created_at' => 'timestamp',
               'in_method' => 'in_method',
               'in_user_ip' => 'in_user_ip',
               'in_msg' => 'in_msg',
               'out_created_at' => 'out_created_at',
               'out_msg' => 'out_msg'
               ));
               //$orangesoapserver_log->setWriter($write); */
     $cm->setWriter($write);
     $logger = $cm->getLogObject();
     try {
         $functions = $this->getFunctions();
         $dom = new DOMDocument();
         $dom->loadXML($request);
         foreach ($functions as $function) {
             if ($dom->getElementsByTagName($function)->item(0)) {
                 $method = $function;
                 break;
             }
         }
         try {
             $preparedRequest = $this->_prepareSoapEnvelope($request);
         } catch (Exception $exc) {
             $this->_getSoap()->fault('043', "Błąd podczas tworzenia logów." . $exc->getMessage());
         }
         //echo json_encode($preparedRequest);
         //die;
         if ($dom->getElementsByTagName('sms')->item(0) != null) {
             /* $sms['originator'] = $dom->getElementsByTagName('originator')->item(0)->nodeValue;
                 $sms['transactionId'] = $dom->getElementsByTagName('transactionId')->item(0)->nodeValue;
                 $sms['status'] = $dom->getElementsByTagName('status')->item(0)->nodeValue;
                 $sms['content'] = $dom->getElementsByTagName('content')->item(0)->nodeValue;
                 $sms['timestamp'] = $dom->getElementsByTagName('timestamp')->item(0)->nodeValue;
                */
             $transactionId = $dom->getElementsByTagName('transactionId')->item(0)->nodeValue;
             $error = array();
             //validate
             if (empty($transactionId) || !isset($transactionId)) {
                 $error[] = 'Brak identyfikatora transactionId wiadomości przychodzącej';
             }
             //$logger->setEventItem('in_user_ip', $headUserIp);
             //if (empty($headUserIp) || !isset($headUserIp))
             //    $error[] = 'Brak identyfikatora adresu IP wiadomości przychodzącej';
             //$logger->setEventItem('in_user_ip', $headUserIp);
             if (!empty($error)) {
                 $this->_getSoap()->fault('666', implode("\n", $error));
             }
             $logger->setEventItem('in_method', $method);
             $logger->setEventItem('in_msg', json_encode($preparedRequest));
             $response = parent::handle($request);
             try {
                 $preparedResponse = $this->_prepareSoapEnvelope($response);
             } catch (Exception $exc) {
                 $this->_getSoap()->fault('043', "Błąd podczas tworzenia logów." . $exc->getMessage());
             }
             $dom->loadXML($response);
             $sms_response['DeliverNotificationReturn'] = $dom->getElementsByTagName(' DeliverNotificationReturn')->item(0)->nodeValue;
             $logger->setEventItem('out_created_at', date('Y-m-d H:i:sO'));
             $logger->setEventItem('out_msg', json_encode($preparedResponse));
         }
         echo $this->_response;
         $logger->setEventItem('response', json_encode($preparedResponse));
         $logger->log('Wykonano.', Zend_Log::INFO);
     } catch (Exception $e) {
         $logger->setEventItem('in_user_ip', $headUserIp);
         $logger->setEventItem('in_method', $method);
         $logger->setEventItem('created_at', new Zend_Db_Expr("timestamp with time zone '{$startTime}'"));
         $logger->setEventItem('in_msg', json_encode($preparedRequest));
         $logger->setEventItem('out_msg', $e->getMessage());
         $logger->setEventItem('remote_address', $_SERVER['REMOTE_ADDR']);
         $logger->log('Wyjątek!!!', Zend_Log::ERR);
         throw $e;
     }
     return $response;
 }