29 private static $_logger = null;
31 private $_serverCli = null;
33 private $_user = null;
41 if (self::$_logger == null) {
44 $this->_serverCli = realpath($serverCli);
45 if (!file_exists($this->_serverCli)) {
46 throw new \RuntimeException(
"Could not setup RPCClient: ".$this->_serverCli.
" not found.");
51 $this->_php = $config->getValue(
'php',
'system');
55 if (!$session->exist(self::SIDS_SESSION_VARNAME)) {
57 $session->set(self::SIDS_SESSION_VARNAME, $var);
81 if (!$isLogin && $sessionId == null) {
92 $serializedRequest = base64_encode(serialize($request));
98 $currentDir = getcwd();
99 chdir(dirname($this->_serverCli));
100 if (self::$_logger->isDebugEnabled()) {
101 self::$_logger->debug(
"Do remote call to: ".$this->_serverCli);
102 self::$_logger->debug(
"Request:\n".$request->toString());
105 session_write_close();
106 exec($this->_php.
' '.$this->_serverCli.
' '.join(
' ', $arguments), $jsonResponse, $returnValue);
108 if (self::$_logger->isDebugEnabled()) {
109 self::$_logger->debug(
"Response [JSON]:\n".$jsonResponse[0]);
113 $responseData = json_decode($jsonResponse[0],
true);
115 $response->setValues($responseData);
116 $response->setFormat(
'json');
118 $formatter->deserialize($response);
119 if (self::$_logger->isDebugEnabled()) {
120 self::$_logger->debug(
"Response:\n".$response->toString());
123 if (!$response->getValue(
'success')) {
125 if (strpos(
'Authorization failed', $response->getValue(
'errorMsg')) === 0 && !$isLogin) {
143 $request->setAction(
'login');
146 'login' => $this->_user[
'login'],
147 'password' => $this->_user[
'password']
151 if ($response->getValue(
'success')) {
158 throw new \RuntimeException(
"Remote user required for remote call.");
168 $sids = $session->get(self::SIDS_SESSION_VARNAME);
169 $sids[$this->_serverCli] = $sessionId;
170 $session->set(self::SIDS_SESSION_VARNAME, $sids);
180 $sids = $session->get(self::SIDS_SESSION_VARNAME);
181 if (isset($sids[$this->_serverCli])) {
182 return $sids[$this->_serverCli];
192 $errorMsg = $response->getValue(
'errorMsg');
193 self::$_logger->error(
"Error in remote call to ".$this->_serverCli.
": ".$errorMsg.
"\n".$response->toString());
194 throw new \RuntimeException(
"Error in remote call to ".$this->_serverCli.
": ".$errorMsg);
setSessionId($sessionId)
Store the session id for our server in the local session.
handleError($response)
Error handling method.
static getLogger($name)
Get the logger with the given name.
setResponseFormat($format)
Set the desired response format.
call(Request $request)
Do a call to the remote server.
__construct($serverCli, $user)
Constructor.
RPCClient is used to do calls to other wCMF instances on the same mashine.
static getInstance($name, $dynamicConfiguration=array())
Request holds the request values that are used as input to Controller instances.
RemotingClient defines the interface for clients to be used with RemotingServer.
const SIDS_SESSION_VARNAME
doLogin()
Do the login request.
doRemoteCall(Request $request, $isLogin)
Do a remote call.
getSessionId()
Get the session id for our server from the local session.