예제 #1
0
 /**
  * send http request to internal RPC and return response string.
  * 
  * @return string
  */
 public function SendRequestToInternal(Np_Method $request)
 {
     Application_Model_General::virtualSleep();
     // used to write to log to be in order
     $data = $this->createPostData($request);
     $url = Application_Model_General::getSettings('UrlToInternalResponse');
     $auth = Application_Model_General::getSettings('InternalAuth');
     $method = self::getMethodName($this->params['MSG_TYPE']);
     if ($this->protocal == 'http') {
         $client = new Zend_Http_Client();
         $client->setUri($url);
         $client->setParameterGet('method', $method);
         if (is_numeric($timeout = Application_Model_General::getSettings('InternalAuth'))) {
             $client->setConfig(array('timeout' => $timeout));
         }
         $client->setParameterPost($data);
         if (isset($auth['user'])) {
             $user = (string) $auth['user'];
             if (isset($auth['password'])) {
                 $password = (string) $auth['password'];
                 $client->setAuth($user, $password);
             }
             $client->setAuth($user);
         }
         $logContentRequest = "Send to internal " . PHP_EOL . print_R(array_merge(array('method' => $method), $data), 1) . PHP_EOL;
         Application_Model_General::logRequest($logContentRequest, $data['reqId']);
         $client->setMethod(Zend_Http_Client::POST);
         $response = $client->request();
         $ret = $response->getBody();
         $logContentResponse = "Response from internal " . PHP_EOL . $ret . PHP_EOL . PHP_EOL . PHP_EOL;
         Application_Model_General::logRequest($logContentResponse, $data['reqId']);
     } elseif ($this->protocal == 'soap') {
         $client = new Zend_Soap_Client();
         $client->setUri($url);
         $ret = call_user_func_array(array($client, $method), $data);
     }
     return $ret;
 }