You are here

class WSClientSOAPEndpoint in Web service client 7

A remote endpoint type for invoking SOAP services.

Hierarchy

Expanded class hierarchy of WSClientSOAPEndpoint

1 string reference to 'WSClientSOAPEndpoint'
wsclient_soap_wsclient_endpoint_types in wsclient_soap/wsclient_soap.module
Implements hook_wsclient_endpoint_types().

File

wsclient_soap/wsclient_soap.module, line 28
Web service client SOAP support.

View source
class WSClientSOAPEndpoint extends WSClientEndpoint {
  public function client() {
    if (!isset($this->client)) {
      $options['exceptions'] = TRUE;
      if ($this->service->type == 'soap 1.2') {
        $options['soap_version'] = SOAP_1_2;
      }

      // Handle Basic HTTP authentication.
      if (!empty($this->service->settings['authentication']['basic'])) {
        $this->service->settings['options']['login'] = $this->service->settings['authentication']['basic']['username'];
        $this->service->settings['options']['password'] = $this->service->settings['authentication']['basic']['password'];
      }
      if (!empty($this->service->settings['options'])) {
        $options += $this->service->settings['options'];
      }
      try {
        $this->client = new SOAPClient($this->url, $options);
      } catch (SoapFault $e) {
        throw new WSClientException('Error initializing SOAP client for service %name', array(
          '%name' => $this->service->name,
        ));
      }

      // Handle WSS style secured webservice.
      // https://www.drupal.org/node/2420779
      if (!empty($this->service->settings['authentication']['wss'])) {
        $this->client
          ->__setSoapHeaders(new WSSESecurityHeader($this->service->settings['authentication']['wss']['username'], $this->service->settings['authentication']['wss']['password']));
      }
      elseif (!empty($this->service->global_header_parameters)) {
        $header_parameters = $this->service->global_header_parameters;
        $data_types = $this->service->datatypes;
        $headers = array();
        foreach ($header_parameters as $type => $parameter) {
          $name_space = $parameter['name space url'];
          $data_type = $data_types[$type];
          $soap_vars = array();
          foreach ($data_type['property info'] as $name => $property) {
            $soap_vars[] = new SoapVar($property['default value'], XSD_STRING, NULL, NULL, $name, $name_space);
          }
          $header_data = new SoapVar($soap_vars, SOAP_ENC_OBJECT, NULL, NULL, $type, $name_space);
          $headers[] = new SoapHeader($name_space, $type, $header_data, FALSE);
        }
        $this->client
          ->__setSoapHeaders($headers);
      }
    }
    return $this->client;
  }

  /**
   * Retrieve metadata from the WSDL about available data types and operations.
   *
   * @param boolean $reset
   *   If TRUE, existing data types and operations will be overwritten.
   */
  public function initializeMetadata($reset = TRUE) {
    $client = $this
      ->client();
    $data_types = wsclient_soap_parse_types($client
      ->__getTypes());
    $operations = wsclient_soap_parse_operations($client
      ->__getFunctions());
    if ($reset) {
      $this->service->datatypes = $data_types;
      $this->service->operations = $operations;
    }
    else {
      $this->service->datatypes += $data_types;
      $this->service->operations += $operations;
    }
    $this->service
      ->clearCache();
  }

  /**
   * Calls the SOAP service.
   *
   * @param string $operation
   *   The name of the operation to execute.
   * @param array $arguments
   *   Arguments to pass to the service with this operation.
   */
  public function call($operation, $arguments) {
    $client = $this
      ->client();

    // Soap endpoints MAY also have 'headers' set on a per-operation basis.
    $operation_settings = $this->service->operations[$operation];
    if (!empty($operation_settings['header'])) {
      $headers = array();
      foreach ($operation_settings['header'] as $header_settings) {
        if (!empty($header_settings['actor'])) {
          $headers[] = new SoapHeader($header_settings['namespace'], $header_settings['name'], $header_settings['data'], $header_settings['mustunderstand'], $header_settings['actor']);
        }
        else {
          $headers[] = new SoapHeader($header_settings['namespace'], $header_settings['name'], $header_settings['data'], $header_settings['mustunderstand']);
        }
      }
      $client
        ->__setSoapHeaders($headers);
    }
    try {
      $response = $client
        ->__soapCall($operation, $arguments);
      return $response;
    } catch (SoapFault $e) {
      throw new WSClientException('Error invoking the SOAP service %name, operation %operation: %error', array(
        '%name' => $this->service->label,
        '%operation' => $operation,
        '%error' => $e
          ->getMessage(),
      ));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
WSClientEndpoint::$client protected property 1
WSClientEndpoint::$service protected property
WSClientEndpoint::$url protected property
WSClientEndpoint::clearCache public function Clear any caches the endpoint maintains. Overrides WSClientEndpointInterface::clearCache
WSClientEndpoint::dataTypes public function An array of info about data types used by the provided events/actions being not entities. Overrides WSClientEndpointInterface::dataTypes
WSClientEndpoint::formAlter public function Allows altering the configuration form of web service definitions, such that the form can include endpoint type specific configuration settings. Overrides WSClientEndpointInterface::formAlter 1
WSClientEndpoint::__construct public function Overrides WSClientEndpointInterface::__construct 1
WSClientSOAPEndpoint::call public function Calls the SOAP service. Overrides WSClientEndpoint::call
WSClientSOAPEndpoint::client public function
WSClientSOAPEndpoint::initializeMetadata public function Retrieve metadata from the WSDL about available data types and operations.