ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilSoapClient.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
15 {
18 
22  private $log = null;
23 
27  private $client = null;
28 
29  private $uri;
30 
31  private $connect_timeout = 10;
32  private $response_timeout = 10;
33 
34  private $stored_socket_timeout = null;
35 
36 
40  public function __construct($a_uri = '')
41  {
42  global $ilSetting;
43 
44  $this->log = ilLoggerFactory::getLogger('wsrv');
45 
46  $this->uri = $a_uri;
47 
48  $this->use_wsdl = true;
49  $timeout = $ilSetting->get('soap_connect_timeout', self::DEFAULT_CONNECT_TIMEOUT);
50  if (!$timeout) {
51  $timeout = self::DEFAULT_CONNECT_TIMEOUT;
52  }
53  $this->connect_timeout = $timeout;
54 
55  $this->response_timeout = self::DEFAULT_RESPONSE_TIMEOUT;
56  }
57 
62  public function getServer()
63  {
64  return $this->uri;
65  }
66 
71  public function setTimeout($a_timeout)
72  {
73  $this->connect_timeout = $a_timeout;
74  }
75 
80  public function getTimeout()
81  {
83  }
84 
88  public function setResponseTimeout($a_timeout)
89  {
90  $this->response_timeout = (int) $a_timeout;
91  }
92 
96  public function getResponseTimeout()
97  {
99  }
100 
105  public function enableWSDL($a_stat)
106  {
107  $this->use_wsdl = $a_stat;
108  }
109 
114  public function enabledWSDL()
115  {
116  return $this->use_wsdl;
117  }
118 
119 
123  public function init()
124  {
125  global $ilSetting;
126 
127  if (!strlen(trim($this->getServer()))) {
128  if (strlen(trim($ilSetting->get('soap_wsdl_path', '')))) {
129  $this->uri = $ilSetting->get('soap_wsdl_path', '');
130  } else {
131  $this->uri = ilUtil::_getHttpPath() . '/webservice/soap/server.php?wsdl';
132  }
133  }
134  try {
135  $this->log->debug('Using wsdl: ' . $this->getServer());
136  $this->log->debug('Using connection timeout: ' . $this->getTimeout());
137  $this->log->debug('Using response timeout: ' . $this->getResponseTimeout());
138 
139  $this->setSocketTimeout(true);
140  $this->client = new SoapClient(
141  $this->uri,
142  array(
143  'exceptions' => true,
144  'trace' => 1,
145  'connection_timeout' => (int) $this->getTimeout()
146  )
147  );
148  return true;
149  } catch (SoapFault $ex) {
150  $this->log->warning('Soap init failed with message: ' . $ex->getMessage());
151  $this->resetSocketTimeout();
152  return false;
153  } finally {
154  $this->resetSocketTimeout();
155  }
156  }
157 
162  protected function setSocketTimeout($a_wsdl_mode)
163  {
164  $this->stored_socket_timeout = ini_get('default_socket_timeout');
165  $this->log->debug('Default socket timeout is: ' . $this->stored_socket_timeout);
166 
167  if ($a_wsdl_mode) {
168  $this->log->debug('WSDL mode, using socket timeout: ' . $this->getTimeout());
169  ini_set('default_socket_timeout', $this->getTimeout());
170  } else {
171  $this->log->debug('Non WSDL mode, using socket timeout: ' . $this->getResponseTimeout());
172  ini_set('default_socket_timeout', $this->getResponseTimeout());
173  }
174  return true;
175  }
176 
181  protected function resetSocketTimeout()
182  {
183  ini_set('default_socket_timeout', $this->stored_socket_timeout);
184  $this->log->debug('Restoring default socket timeout to: ' . $this->stored_socket_timeout);
185  return true;
186  }
187 
193  public function call($a_operation, $a_params)
194  {
195  $this->log->debug('Calling webservice: ' . $a_operation);
196 
197  $this->setSocketTimeout(false);
198  try {
199  return $this->client->__call($a_operation, $a_params);
200  } catch (SoapFault $exception) {
201  $this->log->error('Calling webservice failed with message: ' . $exception->getMessage());
202  $this->log->debug($this->client->__getLastResponseHeaders());
203  $this->log->debug($this->client->__getLastResponse());
204  return false;
205  } catch (Exception $exception) {
206  $this->log->error('Caught unknown exception with message: ' . $exception->getMessage());
207  $this->log->debug($this->client->__getLastResponseHeaders());
208  $this->log->debug($this->client->__getLastResponse());
209  } finally {
210  $this->resetSocketTimeout();
211  }
212  }
213 }
call($a_operation, $a_params)
Call webservice method.
enableWSDL($a_stat)
enable wsdl mode
resetSocketTimeout()
Reset socket default timeout to defaults.
const DEFAULT_RESPONSE_TIMEOUT
setSocketTimeout($a_wsdl_mode)
Set socket timeout.
const DEFAULT_CONNECT_TIMEOUT
enabledWSDL()
Check if wsdl is enabled.
init()
Init soap client.
setTimeout($a_timeout)
Set connect timeout.
setResponseTimeout($a_timeout)
Create styles array
The data for the language used.
static _getHttpPath()
global $ilSetting
Definition: privfeed.php:17
static getLogger($a_component_id)
Get component logger.
getServer()
Get server uri.
getTimeout()
Get connect timeout.
__construct($a_uri='')