AppserverIo\Appserver\ServletEngine\ServletEngine::process PHP Method

process() public method

Process servlet request.
public process ( AppserverIo\Psr\HttpMessage\RequestInterface $request, AppserverIo\Psr\HttpMessage\ResponseInterface $response, AppserverIo\Server\Interfaces\RequestContextInterface $requestContext, integer $hook ) : boolean
$request AppserverIo\Psr\HttpMessage\RequestInterface A request object
$response AppserverIo\Psr\HttpMessage\ResponseInterface A response object
$requestContext AppserverIo\Server\Interfaces\RequestContextInterface A requests context instance
$hook integer The current hook to process logic for
return boolean
    public function process(RequestInterface $request, ResponseInterface $response, RequestContextInterface $requestContext, $hook)
    {
        // if false hook is coming do nothing
        if (ModuleHooks::REQUEST_POST !== $hook) {
            return;
        }
        // check if we are the handler that has to process this request
        if ($requestContext->getServerVar(ServerVars::SERVER_HANDLER) !== $this->getModuleName()) {
            return;
        }
        // load the application associated with this request
        $application = $this->findRequestedApplication($requestContext);
        // check if the application has already been connected
        if ($application->isConnected() === false) {
            throw new \Exception(sprintf('Application %s has not connected yet', $application->getName()), 503);
        }
        // create a copy of the valve instances
        $valves = $this->valves;
        $handlers = $this->handlers;
        // create a new request instance from the HTTP request
        $servletRequest = new Request();
        $servletRequest->injectHandlers($handlers);
        $servletRequest->injectHttpRequest($request);
        $servletRequest->injectServerVars($requestContext->getServerVars());
        $servletRequest->init();
        // initialize servlet response
        $servletResponse = new Response();
        $servletResponse->init();
        // initialize the request handler instance
        $requestHandler = new RequestHandler();
        $requestHandler->injectValves($valves);
        $requestHandler->injectApplication($application);
        $requestHandler->injectRequest($servletRequest);
        $requestHandler->injectResponse($servletResponse);
        $requestHandler->start(PTHREADS_INHERIT_NONE | PTHREADS_INHERIT_CONSTANTS);
        $requestHandler->join();
        // copy values to the HTTP response
        $requestHandler->copyToHttpResponse($response);
        // append the servlet engine's signature
        $response->addHeader(Protocol::HEADER_X_POWERED_BY, get_class($this), true);
        // set response state to be dispatched after this without calling other modules process
        $response->setState(HttpResponseStates::DISPATCH);
    }