/** * Test if the WSDL is reachable, and create the object SOAPClient * * @param string $rooturl The url of the WSDL * @param string $login The login * @param string $password The password * @param string $type Exchange type * @param array $options The options * @param boolean $loggable Log the exchanges * @param string $stream_context HTTP method (GET, POST, HEAD, PUT, ...) * @param string $local_cert Path of the certifacte * @param string $passphrase Pass phrase for the certificate * @param boolean $safe_mode Safe mode * @param boolean $verify_peer Require verification of SSL certificate used * @param string $cafile Location of Certificate Authority file on local filesystem * @param String $wsdl_external Location of external wsdl * @param int $socket_timeout Default timeout (in seconds) for socket based streams * * @throws CMbException * * @return CMbSOAPClient | CNuSOAPClient */ public function make($rooturl, $login = null, $password = null, $type = null, $options = array(), $loggable = null, $stream_context = null, $local_cert = null, $passphrase = null, $safe_mode = false, $verify_peer = false, $cafile = null, $wsdl_external = null, $socket_timeout = null) { if ($login && $password || array_key_exists('login', $options) && array_key_exists('password', $options)) { $login = $login ? $login : $options['login']; if (preg_match('#\\%u#', $rooturl)) { $rooturl = str_replace('%u', $login, $rooturl); } else { $options['login'] = $login; } $password = $password ? $password : $options['password']; if (preg_match('#\\%p#', $rooturl)) { $rooturl = str_replace('%p', $password, $rooturl); } else { $options['password'] = $password; } } $check_option["local_cert"] = $local_cert; $check_option["ca_cert"] = $cafile; $check_option["passphrase"] = $passphrase; $check_option["username"] = $login; $check_option["password"] = $password; if (!$safe_mode) { if (!CHTTPClient::checkUrl($rooturl, $check_option)) { throw new CMbException("CSourceSOAP-unreachable-source", $rooturl); } } switch ($this->type_client) { case 'CNuSOAPClient': $this->client = new CNuSOAPClient($rooturl, $type, $options, $loggable, $local_cert, $passphrase, $safe_mode, $verify_peer, $cafile); break; default: $this->client = new CMbSOAPClient($rooturl, $type, $options, $loggable, $local_cert, $passphrase, $safe_mode, $verify_peer, $cafile, $wsdl_external, $socket_timeout); break; } if (!$this->client) { throw new CMbException("CSourceSOAP-soapclient-impossible"); } return $this->client; }
/** * Check service availability * * @throws CMbException * * @return void */ public function checkServiceAvailability() { $url = $this->wsdl_url; if ($this->wsdl_original) { $url = $this->wsdl_original; } $xml = file_get_contents($url); $dom = new CMbXMLDocument(); $dom->loadXML($xml); $xpath = new CMbXPath($dom); $xpath->registerNamespace("wsdl", "http://schemas.xmlsoap.org/wsdl/"); $xpath->registerNamespace("soap", "http://schemas.xmlsoap.org/wsdl/soap/"); $xpath->registerNamespace("soap12", "http://schemas.xmlsoap.org/wsdl/soap12"); $login = CMbArray::get($this->options, "login"); $password = CMbArray::get($this->options, "password"); $service_nodes = $xpath->query("//wsdl:service"); foreach ($service_nodes as $_service_node) { $service_name = $_service_node->getAttribute("name"); $port_nodes = $xpath->query("wsdl:port", $_service_node); foreach ($port_nodes as $_port_node) { $address = $xpath->queryAttributNode("soap:address|soap12:address", $_port_node, "location"); if (!$address) { continue; } if ($login && $password) { $address = str_replace("://", "://{$login}:{$password}@", $address); } // Url exist $url_exist = CHTTPClient::checkUrl($address, $this->check_option); if (!$url_exist) { throw new CMbException("Service '{$service_name}' injoignable à l'adresse : <em>{$address}</em>"); } } } }
/** * If source is reachable * * @return bool|void */ function isReachableSource() { $check_option["local_cert"] = $this->local_cert; $check_option["ca_cert"] = $this->cafile; $check_option["passphrase"] = $this->getPassword($this->passphrase, "iv_passphrase"); $check_option["username"] = $this->user; $check_option["password"] = $this->getPassword(); if (!$this->safe_mode) { if (!CHTTPClient::checkUrl($this->host, $check_option)) { $this->_reachable = 0; $this->_message = CAppUI::tr("CSourceSOAP-unreachable-source", $this->host); return false; } } return true; }