/** * @covers WSManager::isMethodAvailable */ public function testIsMethodAvailable() { $this->manager->setPluginsDirectoryPath(dirname(__FILE__) . '/../../testPluginDirectoryStructure/'); $this->assertTrue($this->manager->isMethodAvailable('methodA', 'GET')); $this->assertTrue($this->manager->isMethodAvailable('methodD', 'GET')); $this->assertFalse($this->manager->isMethodAvailable('methodX', 'GET')); }
public function execute($request) { $logger = $this->getWebServiceLogger(); $wsHelper = new WSHelper(); $wsManager = new WSManager(); $result = ''; $status = 'INITIAL'; $contentType = 'text/plain'; $httpStatus = 200; $httpStatusText = null; try { $paramObj = $wsHelper->extractParameters($request); $isMethodAvailable = $wsManager->isMethodAvailable($paramObj->getMethod(), $paramObj->getRequestMethod()); $logger->debug(print_r($paramObj, true)); $logger->debug("MethodAvailable:" . $isMethodAvailable); if ($isMethodAvailable) { $isAuthenticated = $wsManager->isAuthenticated($paramObj); $isAuthorized = $wsManager->isAuthorized($paramObj); if ($isAuthenticated && $isAuthorized) { $result = $wsManager->callMethod($paramObj); $logger->debug(print_r($result, true)); $result = $wsHelper->formatResult($result, WSHelper::FORMAT_JSON); $logger->debug(print_r($result, true)); $status = 'SUCCESS'; $contentType = 'text/json'; } else { $result = 'NOT ALLOWED'; $status = 'ERROR'; $httpStatus = 401; } } else { $result = 'INVALID REQUEST'; $status = 'ERROR'; $httpStatus = 404; $httpStatusText = 'Webservice Method Not Found (' . $paramObj->getMethod() . ')'; } } catch (WebServiceException $e) { $result = $e->getCode() . ': ' . $e->getMessage(); $status = 'ERROR'; $httpStatus = $e->getCode(); $httpStatusText = $e->getMessage(); } catch (Exception $e) { $logger = $this->getWebServiceLogger(); $logger->info('Uncaught Exception: ' . $e->getMessage()); $result = $e->getMessage() . ' ' . $e->getCode(); $status = 'ERROR'; } $response = $this->getResponse(); $response->setContent($result); $response->setHttpHeader('Content-type', $contentType); $response->setHttpHeader('ohrm_ws_call_status', $status); $response->setStatusCode($httpStatus, $httpStatusText); return sfView::NONE; }
public function execute($request) { $wsHelper = new WSHelper(); $wsManager = new WSManager(); $result = ''; $status = 'INITIAL'; $contentType = 'text/plain'; try { $paramObj = $wsHelper->extractParamerts($request); $isMethodAvailable = $wsManager->isMethodAvailable($paramObj->getMethod()); if ($isMethodAvailable) { $isAuthenticated = $wsManager->isAuthenticated($paramObj); $isAuthorized = $wsManager->isAuthorized($paramObj); if ($isAuthenticated && $isAuthorized) { try { $result = $wsManager->callMethod($paramObj); $result = $wsHelper->formatResult($result, WSHelper::FORMAT_JSON); $status = 'SUCCESS'; $contentType = 'text/json'; } catch (Exception $e) { $logger = $this->getWebServiceLogger(); $logger->info('Uncaught Exception: ' . $e->getMessage()); $result = 'INTERNAL ERROR'; $status = 'ERROR'; } } else { $result = 'NOT ALLOWED'; $status = 'ERROR'; } } else { $result = 'INVALID REQUEST'; $status = 'ERROR'; } } catch (WebServiceException $e) { $result = $e->getCode() . ': ' . $e->getMessage(); $status = 'ERROR'; } $this->getResponse()->setContent($result); $this->getResponse()->setHttpHeader('Content-type', $contentType); $this->getResponse()->setHttpHeader('ohrm_ws_call_status', $status); return sfView::NONE; }