Exemple #1
0
 /**
  * send the SOAP message
  *
  * Note: if the operation has multiple return values
  * the return value of this method will be an array
  * of those values.
  *
  * @param    string $msg a SOAPx4 soapmsg object
  * @param    string $soapaction SOAPAction value
  * @param    integer $timeout set connection timeout in seconds
  * @param	integer $response_timeout set response timeout in seconds
  * @return	mixed native PHP types.
  * @access   private
  */
 function send($msg, $soapaction = '', $timeout = 0, $response_timeout = 30)
 {
     $this->checkCookies();
     // detect transport
     switch (true) {
         // http(s)
         case ereg('^http', $this->endpoint):
             $this->debug('transporting via HTTP');
             if ($this->persistentConnection == true && is_object($this->persistentConnection)) {
                 $http =& $this->persistentConnection;
             } else {
                 $http = new nusoap_transport_http($this->endpoint);
                 if ($this->persistentConnection) {
                     $http->usePersistentConnection();
                 }
             }
             $http->setContentType($this->getHTTPContentType(), $this->getHTTPContentTypeCharset());
             $http->setSOAPAction($soapaction);
             if ($this->proxyhost && $this->proxyport) {
                 $http->setProxy($this->proxyhost, $this->proxyport, $this->proxyusername, $this->proxypassword);
             }
             if ($this->authtype != '') {
                 $http->setCredentials($this->username, $this->password, $this->authtype, array(), $this->certRequest);
             }
             if ($this->http_encoding != '') {
                 $http->setEncoding($this->http_encoding);
             }
             $this->debug('sending message, length=' . strlen($msg));
             if (ereg('^http:', $this->endpoint)) {
                 //if(strpos($this->endpoint,'http:')){
                 $this->responseData = $http->send($msg, $timeout, $response_timeout, $this->cookies);
             } elseif (ereg('^https', $this->endpoint)) {
                 //} elseif(strpos($this->endpoint,'https:')){
                 //if(phpversion() == '4.3.0-dev'){
                 //$response = $http->send($msg,$timeout,$response_timeout);
                 //$this->request = $http->outgoing_payload;
                 //$this->response = $http->incoming_payload;
                 //} else
                 $this->responseData = $http->sendHTTPS($msg, $timeout, $response_timeout, $this->cookies);
             } else {
                 $this->setError('no http/s in endpoint url');
             }
             $this->request = $http->outgoing_payload;
             $this->response = $http->incoming_payload;
             $this->appendDebug($http->getDebug());
             $this->UpdateCookies($http->incoming_cookies);
             // save transport object if using persistent connections
             if ($this->persistentConnection) {
                 $http->clearDebug();
                 if (!is_object($this->persistentConnection)) {
                     $this->persistentConnection = $http;
                 }
             }
             if ($err = $http->getError()) {
                 $this->setError('HTTP Error: ' . $err);
                 return false;
             } elseif ($this->getError()) {
                 return false;
             } else {
                 $this->debug('got response, length=' . strlen($this->responseData) . ' type=' . $http->incoming_headers['content-type']);
                 return $this->parseResponse($http->incoming_headers, $this->responseData);
             }
             break;
         default:
             $this->setError('no transport found, or selected transport is not yet supported!');
             return false;
             break;
     }
 }
 /**
  * parses the wsdl document
  * 
  * @param string $wsdl path or URL
  * @access private 
  */
 function parseWSDL($wsdl = '')
 {
     if ($wsdl == '') {
         $this->debug('no wsdl passed to parseWSDL()!!');
         $this->setError('no wsdl passed to parseWSDL()!!');
         return false;
     }
     // parse $wsdl for url format
     $wsdl_props = parse_url($wsdl);
     if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'http' || $wsdl_props['scheme'] == 'https')) {
         $this->debug('getting WSDL http(s) URL ' . $wsdl);
         // get wsdl
         $tr = new nusoap_transport_http($wsdl);
         $tr->request_method = 'GET';
         $tr->useSOAPAction = false;
         if ($this->proxyhost && $this->proxyport) {
             $tr->setProxy($this->proxyhost, $this->proxyport, $this->proxyusername, $this->proxypassword);
         }
         $tr->setEncoding('gzip, deflate');
         $wsdl_string = $tr->send('', $this->timeout, $this->response_timeout);
         //$this->debug("WSDL request\n" . $tr->outgoing_payload);
         //$this->debug("WSDL response\n" . $tr->incoming_payload);
         $this->appendDebug($tr->getDebug());
         // catch errors
         if ($err = $tr->getError()) {
             $errstr = 'HTTP ERROR: ' . $err;
             $this->debug($errstr);
             $this->setError($errstr);
             unset($tr);
             return false;
         }
         unset($tr);
         $this->debug("got WSDL URL");
     } else {
         // $wsdl is not http(s), so treat it as a file URL or plain file path
         if (isset($wsdl_props['scheme']) && $wsdl_props['scheme'] == 'file' && isset($wsdl_props['path'])) {
             $path = isset($wsdl_props['host']) ? $wsdl_props['host'] . ':' . $wsdl_props['path'] : $wsdl_props['path'];
         } else {
             $path = $wsdl;
         }
         $this->debug('getting WSDL file ' . $path);
         if ($fp = @fopen($path, 'r')) {
             $wsdl_string = '';
             while ($data = fread($fp, 32768)) {
                 $wsdl_string .= $data;
             }
             fclose($fp);
         } else {
             $errstr = "Bad path to WSDL file {$path}";
             $this->debug($errstr);
             $this->setError($errstr);
             return false;
         }
     }
     $this->debug('Parse WSDL');
     // end new code added
     // Create an XML parser.
     $this->parser = xml_parser_create();
     // Set the options for parsing the XML data.
     // xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
     xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
     // Set the object for the parser.
     xml_set_object($this->parser, $this);
     // Set the element handlers for the parser.
     xml_set_element_handler($this->parser, 'start_element', 'end_element');
     xml_set_character_data_handler($this->parser, 'character_data');
     // Parse the XML file.
     if (!xml_parse($this->parser, $wsdl_string, true)) {
         // Display an error message.
         $errstr = sprintf('XML error parsing WSDL from %s on line %d: %s', $wsdl, xml_get_current_line_number($this->parser), xml_error_string(xml_get_error_code($this->parser)));
         $this->debug($errstr);
         $this->debug("XML payload:\n" . $wsdl_string);
         $this->setError($errstr);
         return false;
     }
     // free the parser
     xml_parser_free($this->parser);
     $this->debug('Parsing WSDL done');
     // catch wsdl parse errors
     if ($this->getError()) {
         return false;
     }
     return true;
 }