コード例 #1
0
 /**
  * Default action to invoke if no action parameter has been found in the request.
  *
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface  $servletRequest  The request instance
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface $servletResponse The response instance
  *
  * @return string|null The action result
  *
  * @Action(name="/index")
  */
 public function indexAction(HttpServletRequestInterface $servletRequest, HttpServletResponseInterface $servletResponse)
 {
     try {
         // append the Rout.Lt 2 version to the request attributes
         $servletRequest->setAttribute(RequestKeys::ROUTLT_VERSION, '~2.0');
         // action invocation has been successfull
         return ActionInterface::INPUT;
     } catch (\Exception $e) {
         // append the exception the response body
         $this->addFieldError('critical', $e->getMessage());
         // action invocation has been successfull
         return ActionInterface::INPUT;
     }
 }
コード例 #2
0
 /**
  * Forward's the request to the configured error page.
  *
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface  $servletRequest  The servlet request instance
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface $servletResponse The servlet response instance
  *
  * @return void
  */
 protected function forwardToErrorPage(HttpServletRequestInterface $servletRequest, HttpServletResponseInterface $servletResponse)
 {
     // query whether or not we've an error page configured
     if ($formLoginConfig = $this->getConfigData()->getFormLoginConfig()) {
         if ($formErrorPage = $formLoginConfig->getFormErrorPage()) {
             // initialize the location to redirect to
             $location = $formErrorPage->__toString();
             if ($baseModifier = $servletRequest->getBaseModifier()) {
                 $location = $baseModifier . $location;
             }
             // redirect to the configured error page
             $servletRequest->setDispatched(true);
             $servletResponse->setStatusCode(307);
             $servletResponse->addHeader(Protocol::HEADER_LOCATION, $location);
             return;
         }
     }
     // redirect to the default error page
     $servletRequest->setAttribute(RequestHandlerKeys::ERROR_MESSAGE, 'Please configure a form-error-page when using auth-method \'Form\' in the login-config of your application\'s web.xml');
     $servletRequest->setDispatched(true);
     $servletResponse->setStatusCode(500);
 }
コード例 #3
0
ファイル: ErrorUtil.php プロジェクト: appserver-io/appserver
 /**
  * This method finally handles all PHP and user errors as well as the exceptions that
  * have been thrown through the servlet processing.
  *
  * @param \AppserverIo\Appserver\ServletEngine\RequestHandler        $requestHandler  The request handler instance
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface  $servletRequest  The actual request instance
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface $servletResponse The actual request instance
  *
  * @return void
  */
 public function handleErrors(RequestHandler $requestHandler, HttpServletRequestInterface $servletRequest, HttpServletResponseInterface $servletResponse)
 {
     // return immediately if we don't have any errors
     if (sizeof($errors = $requestHandler->getErrors()) === 0) {
         return;
     }
     // iterate over the errors to process each of them
     foreach ($errors as $error) {
         // prepare the error message
         $message = $this->prepareMessage($error);
         // query whether or not we have to log the error
         if (Boolean::valueOf(new String(ini_get('log_errors')))->booleanValue()) {
             // create a local copy of the application
             if ($application = $servletRequest->getContext()) {
                 // try to load the system logger from the application
                 if ($systemLogger = $application->getLogger(LoggerUtils::SYSTEM)) {
                     $systemLogger->log($this->mapLogLevel($error), $message);
                 }
             }
         }
         // query whether or not, the error has an status code
         if ($statusCode = $error->getStatusCode()) {
             $servletResponse->setStatusCode($statusCode);
         }
     }
     // we add the error to the servlet request
     $servletRequest->setAttribute(RequestHandlerKeys::ERROR_MESSAGES, $errors);
     // we append the the errors to the body stream if display_errors is on
     if (Boolean::valueOf(new String(ini_get('display_errors')))->booleanValue()) {
         $servletResponse->appendBodyStream(implode('<br/>', $errors));
     }
     // query whether or not we've a client or an server error
     if ($servletResponse->getStatusCode() > 399) {
         try {
             // create a local copy of the application
             $application = $servletRequest->getContext();
             // inject the application and servlet response
             $servletRequest->injectResponse($servletResponse);
             $servletRequest->injectContext($application);
             // load the servlet context instance
             $servletManager = $application->search(ServletContextInterface::IDENTIFIER);
             // initialize the request URI for the error page to be rendered
             $requestUri = null;
             // iterate over the configured error pages to find a matching one
             foreach ($servletManager->getErrorPages() as $errorCodePattern => $errorPage) {
                 // query whether or not we found an error page configured for the actual status code
                 if (fnmatch($errorCodePattern, $servletResponse->getStatusCode())) {
                     $requestUri = $errorPage;
                     break;
                 }
             }
             // query whether or not we've an found a configured error page
             if ($requestUri == null) {
                 throw new ServletException(sprintf('Please configure an error page for status code %s', $servletResponse->getStatusCode()));
             }
             // initialize the request URI
             $servletRequest->setRequestUri($requestUri);
             // prepare the request with the new data
             $servletRequest->prepare();
             // reset the body stream to remove content, that has already been appended
             $servletResponse->resetBodyStream();
             // load the servlet path and session-ID
             $servletPath = $servletRequest->getServletPath();
             $sessionId = $servletRequest->getProposedSessionId();
             // load and process the servlet
             $servlet = $servletManager->lookup($servletPath, $sessionId);
             $servlet->service($servletRequest, $servletResponse);
         } catch (\Exception $e) {
             // finally log the exception
             $application->getInitialContext()->getSystemLogger()->critical($e->__toString());
             // append the exception message to the body stream
             $servletResponse->appendBodyStream($e->__toString());
         }
     }
 }
コード例 #4
0
 /**
  * Tries to load the requested applications and adds them to the response.
  *
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface  $servletRequest  The request instance
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface $servletResponse The response instance
  *
  * @return void
  * @see \AppserverIo\Psr\Servlet\Http\HttpServlet::doGet()
  *
  * @SWG\Get(
  *   path="/applications.do",
  *   tags={"applications"},
  *   summary="List's all applications",
  *   @SWG\Response(
  *     response=200,
  *     description="A list with the available applications",
  *     @SWG\Schema(
  *       type="array",
  *       @SWG\Items(ref="#/definitions/ApplicationOverviewData")
  *     )
  *   ),
  *   @SWG\Response(
  *     response=500,
  *     description="Internal Server Error"
  *   )
  * )
  *
  * @SWG\Get(
  *   path="/applications.do/{id}",
  *   tags={"applications"},
  *   summary="Load's the application with the passed ID",
  *   @SWG\Parameter(
  *      name="id",
  *      in="path",
  *      description="The name of the application to load",
  *      required=true,
  *      type="string"
  *   ),
  *   @SWG\Response(
  *     response=200,
  *     description="The requested application",
  *     @SWG\Schema(
  *       ref="#/definitions/ApplicationViewData"
  *     )
  *   ),
  *   @SWG\Response(
  *     response=500,
  *     description="Internal Server Error"
  *   )
  * )
  */
 public function doGet(HttpServletRequestInterface $servletRequest, HttpServletResponseInterface $servletResponse)
 {
     // load the requested path info, e. g. /api/applications.do/example/
     $pathInfo = trim($servletRequest->getPathInfo(), '/');
     // extract the entity and the ID, if available
     list($id, ) = explode('/', $pathInfo);
     // query whether we've found an ID or not
     if ($id == null) {
         $content = $this->getApplicationProcessor()->findAll();
     } else {
         $content = $this->getApplicationProcessor()->load($id);
     }
     // add the result to the request
     $servletRequest->setAttribute(RequestKeys::RESULT, $content);
 }
コード例 #5
0
 /**
  * Tries to load the content of the naming directory and adds it to the response.
  *
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface  $servletRequest  The request instance
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface $servletResponse The response instance
  *
  * @return void
  * @see \AppserverIo\Psr\Servlet\Http\HttpServlet::doGet()
  *
  * @SWG\Get(
  *   path="/namingDirectories.do",
  *   tags={"namingDirectories"},
  *   summary="List's the available naming directories",
  *   @SWG\Response(
  *     response=200,
  *     description="A list with the available naming directories",
  *     @SWG\Schema(
  *       type="array",
  *       @SWG\Items(ref="#/definitions/NamingDirectoryOverviewData")
  *     )
  *   ),
  *   @SWG\Response(
  *     response=500,
  *     description="Internal Server Error"
  *   )
  * )
  *
  * @SWG\Get(
  *   path="/namingDirectories.do/{id}",
  *   tags={"namingDirectories"},
  *   summary="Load's the naming directory with the passed ID",
  *   @SWG\Parameter(
  *      name="id",
  *      in="path",
  *      description="The UUID of the naming directory to load",
  *      required=true,
  *      type="string"
  *   ),
  *   @SWG\Response(
  *     response=200,
  *     description="The requested naming directory",
  *     @SWG\Schema(
  *       ref="#/definitions/NamingDirectoryViewData"
  *     )
  *   ),
  *   @SWG\Response(
  *     response=500,
  *     description="Internal Server Error"
  *   )
  * )
  */
 public function doGet(HttpServletRequestInterface $servletRequest, HttpServletResponseInterface $servletResponse)
 {
     // load the requested path info, e. g. /api/namingDirectories.do/5e83e3e6-b1d5-49de-92ae-7fca480593b8
     $pathInfo = trim($servletRequest->getPathInfo(), '/');
     // extract the entity and the ID, if available
     list($id, ) = explode('/', $pathInfo);
     // query whether we've found an ID or not
     if ($id == null) {
         $content = $this->getNamingDirectoryProcessor()->findAll();
     } else {
         $content = $this->getNamingDirectoryProcessor()->load($id);
     }
     // add the result to the request
     $servletRequest->setAttribute(RequestKeys::RESULT, $content);
 }
コード例 #6
0
 /**
  * Tries to load the requested vhosts and adds them to the response.
  *
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface  $servletRequest  The request instance
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface $servletResponse The response instance
  *
  * @return void
  * @see \AppserverIo\Psr\Servlet\Http\HttpServlet::doGet()
  *
  * @SWG\Get(
  *   path="/virtualHosts.do",
  *   tags={"virtualHosts"},
  *   summary="List's all virtual hosts",
  *   @SWG\Response(
  *     response=200,
  *     description="A list with the available virtual hosts",
  *     @SWG\Schema(
  *       type="array",
  *       @SWG\Items(ref="#/definitions/VirtualHostOverviewData")
  *     )
  *   ),
  *   @SWG\Response(
  *     response="500",
  *     description="Internal Server Error"
  *   )
  * )
  *
  * @SWG\Get(
  *   path="/virtualHosts.do/{id}",
  *   tags={"virtualHosts"},
  *   summary="Loads the virtual host with the passed ID",
  *   @SWG\Parameter(
  *      name="id",
  *      in="path",
  *      description="The UUID of the virtual host to load",
  *      required=true,
  *      type="string"
  *   ),
  *   @SWG\Response(
  *     response=200,
  *     description="The requested virtual host",
  *     @SWG\Schema(
  *       ref="#/definitions/VirtualHostViewData"
  *     )
  *   ),
  *   @SWG\Response(
  *     response="500",
  *     description="Internal Server Error"
  *   )
  * )
  */
 public function doGet(HttpServletRequestInterface $servletRequest, HttpServletResponseInterface $servletResponse)
 {
     try {
         // load the requested path info, e. g. /api/applications.do/example/
         $pathInfo = trim($servletRequest->getPathInfo(), '/');
         // extract the entity and the ID, if available
         list($id, ) = explode('/', $pathInfo);
         // query whether we've found an ID or not
         if ($id == null) {
             $content = $this->getVirtualHostProcessor()->findAll();
         } else {
             $content = $this->getVirtualHostProcessor()->load($id);
         }
     } catch (\Exception $e) {
         // set error message and status code
         $content = $e->getMessage();
         $servletResponse->setStatusCode(500);
     }
     // add the result to the request
     $servletRequest->setAttribute(RequestKeys::RESULT, $content);
 }
コード例 #7
0
 /**
  * Processes the servlet's errors.
  *
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface  $servletRequest  The request instance
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface $servletResponse The response instance
  *
  * @return void
  */
 public function processErrors(HttpServletRequestInterface $servletRequest, HttpServletResponseInterface $servletResponse)
 {
     $servletRequest->setAttribute(RequestKeys::RESULT, $this->getErrorHandler()->processErrors($this->getErrors()));
 }
コード例 #8
0
 /**
  * Returns a simple welcome page.
  *
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface  $servletRequest  The request instance
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface $servletResponse The response instance
  *
  * @return void
  * @see \AppserverIo\Psr\Servlet\Http\HttpServlet::doGet()
  *
  * @SWG\Get(
  *   path="/index.do",
  *   summary="Welcome Page",
  *   tags={"index"},
  *   @SWG\Response(
  *     response=200,
  *     description="A simple welcome page"
  *   ),
  *   @SWG\Response(
  *     response=500,
  *     description="Internal Server Error"
  *   )
  * )
  */
 public function doGet(HttpServletRequestInterface $servletRequest, HttpServletResponseInterface $servletResponse)
 {
     $servletRequest->setAttribute(RequestKeys::RESULT, array('Welcome to appserver.io API'));
 }