20 if (!class_exists(
'Zend_Http_Client')) {
21 throw new ConfigurationException(
22 'wcmf\lib\service\impl\HTTPClient requires '.
23 'Zend_Http_Client. If you are using composer, add zf1/zend-http '.
24 'as dependency to your project');
37 private static $_logger = null;
39 private $_client = null;
40 private $_user = null;
48 if (self::$_logger == null) {
51 $this->_client =
new Zend_Http_Client($serverUrl, array(
56 $this->_client->setMethod(Zend_Http_Client::POST);
57 $this->_client->setCookieJar();
79 $cookyJar = $this->_client->getCookieJar();
80 if (!$isLogin &&
sizeof($cookyJar->getAllCookies()) == 0) {
86 $this->_client->resetParameters();
87 $this->_client->setParameterPost(
'controller', $request->
getSender());
88 $this->_client->setParameterPost(
'context', $request->
getContext());
89 $this->_client->setParameterPost(
'action', $request->
getAction());
90 $this->_client->setParameterPost(
'request_format', $request->
getFormat());
91 $this->_client->setParameterPost(
'response_format', $request->
getResponseFormat());
92 $this->_client->setParameterPost($request->
getValues());
94 $httpResponse = $this->_client->request();
97 self::$_logger->error(
"Error in remote call to ".$url.
":\n".$ex, __FILE__);
98 throw new \RuntimeException(
"Error in remote call to ".$url.
": ".$ex->getMessage());
102 $responseData = json_decode($httpResponse->getBody(),
true);
104 $response->setFormat(
'json');
106 $formatter->deserialize($response);
109 if (!$response->getValue(
'success'))
111 $errorMsg = $response->getValue(
'errorMsg');
113 if (strpos(
'Authorization failed', $errorMsg) === 0 && !$isLogin) {
116 $url = $this->_client->getUri();
117 self::$_logger->error(
"Error in remote call to ".$url.
": ".$errorMsg.
"\n".$response->toString(), __FILE__);
118 throw new \RuntimeException(
"Error in remote call: $errorMsg");
131 $request->setAction(
'login');
134 'login' => $this->_user[
'login'],
135 'password' => $this->_user[
'password']
139 if ($response->getValue(
'success')) {
140 $this->_sessionId = $response->getValue(
'sid');
145 throw new \RuntimeException(
"Remote user required for remote call.");
154 $errorMsg = $response->getValue(
'errorMsg');
155 self::$_logger->error(
"Error in remote call to ".$this->_serverBase.
": ".$errorMsg.
"\n".$response->toString(), __FILE__);
156 throw new \RuntimeException(
"Error in remote call to ".$this->_serverBase.
": ".$errorMsg);
getFormat()
Get the message format.
getContext()
Get the name of the context.
static getLogger($name)
Get the logger with the given name.
setResponseFormat($format)
Set the desired response format.
Messages are sent between Controllers and are used to transfer data between them. ...
static getInstance($name, $dynamicConfiguration=array())
getResponseFormat()
Get the message response format.
getAction()
Get the name of the action.
Request holds the request values that are used as input to Controller instances.
RemotingClient defines the interface for clients to be used with RemotingServer.
getSender()
Get the name of the sending Controller.
call(Request $request)
Do a call to the remote server.
__construct($serverUrl, $user)
Constructor.
HTTPClient is used to do calls to other wCMF instances over HTTP.
doRemoteCall(Request $request, $isLogin)
Do a remote call.
getValues()
Get all key value pairs.
doLogin()
Do the login request.
handleError($response)
Error handling method.