ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  {
52  $timeout = self::DEFAULT_CONNECT_TIMEOUT;
53  }
54  $this->connect_timeout = $timeout;
55 
56  $this->response_timeout = self::DEFAULT_RESPONSE_TIMEOUT;
57  }
58 
63  public function getServer()
64  {
65  return $this->uri;
66  }
67 
72  public function setTimeout($a_timeout)
73  {
74  $this->connect_timeout = $a_timeout;
75  }
76 
81  public function getTimeout()
82  {
84  }
85 
90  public function setResponseTimeout($a_timeout)
91  {
92  $this->response_timeout = $a_timeout;
93  }
94 
98  public function getResponseTimeout()
99  {
101  }
102 
107  public function enableWSDL($a_stat)
108  {
109  $this->use_wsdl = $a_stat;
110  }
111 
116  public function enabledWSDL()
117  {
118  return $this->use_wsdl;
119  }
120 
121 
125  public function init()
126  {
127  global $ilSetting;
128 
129  if(!strlen(trim($this->getServer())))
130  {
131  if(strlen(trim($ilSetting->get('soap_wsdl_path',''))))
132  {
133  $this->uri = $ilSetting->get('soap_wsdl_path','');
134  }
135  else
136  {
137  $this->uri = ilUtil::_getHttpPath().'/webservice/soap/server.php?wsdl';
138  }
139  }
140  try {
141 
142  $this->log->debug('Using wsdl: ' . $this->getServer());
143  $this->log->debug('Using connection timeout: ' . $this->getTimeout());
144  $this->log->debug('Using response timeout: ' . $this->getResponseTimeout());
145 
146  $this->setSocketTimeout(true);
147  $this->client = new SoapClient(
148  $this->uri,
149  array(
150  'exceptions' => true,
151  'trace' => 1,
152  'connection_timeout' => (int) $this->getTimeout()
153  )
154  );
155  return true;
156  }
157  catch (SoapFault $ex) {
158 
159  $this->log->warning('Soap init failed with message: ' . $ex->getMessage());
160  $this->resetSocketTimeout();
161  return false;
162  }
163  finally {
164  $this->resetSocketTimeout();
165  }
166  }
167 
172  protected function setSocketTimeout($a_wsdl_mode)
173  {
174  $this->stored_socket_timeout = ini_get('default_socket_timeout');
175  $this->log->debug('Default socket timeout is: ' . $this->stored_socket_timeout);
176 
177  if($a_wsdl_mode)
178  {
179  $this->log->debug('WSDL mode, using socket timeout: ' . $this->getTimeout());
180  ini_set('default_socket_timeout', $this->getTimeout());
181  }
182  else
183  {
184  $this->log->debug('Non WSDL mode, using socket timeout: ' . $this->getResponseTimeout());
185  ini_set('default_socket_timeout', $this->getResponseTimeout());
186  }
187  return true;
188  }
189 
194  protected function resetSocketTimeout()
195  {
196  ini_set('default_socket_timeout', $this->stored_socket_timeout);
197  $this->log->debug('Restoring default socket timeout to: ' . $this->stored_socket_timeout);
198  return true;
199  }
200 
206  public function call($a_operation, $a_params)
207  {
208  $this->log->debug('Calling webseervice: ' . $a_operations);
209 
210  $this->setSocketTimeout(false);
211  try {
212  return $this->client->__call($a_operation, $a_params);
213  }
214  catch(SoapFault $exception) {
215  $this->log->error('Calling webservice failed with message: ' . $exception->getMessage());
216  $this->log->debug($this->client->__getLastResponseHeaders());
217  $this->log->debug($this->client->__getLastResponse());
218  return false;
219  }
220  catch(Exception $exception)
221  {
222  $this->log->error('Caught unknown exception with message: '. $exception->getMessage());
223  $this->log->debug($this->client->__getLastResponseHeaders());
224  $this->log->debug($this->client->__getLastResponse());
225  }
226  finally {
227  $this->resetSocketTimeout();
228  }
229  }
230 }
231 ?>
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.
getResponseTimeout()
Get response timeout.
const DEFAULT_CONNECT_TIMEOUT
enabledWSDL()
Check if wsdl is enabled.
init()
Init soap client.
setTimeout($a_timeout)
Set connect timeout.
setResponseTimeout($a_timeout)
Set response 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='')