/** * Processes the request by invoking the request handler that executes the servlet * in a protected context. * * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface $servletRequest The request instance * @param \AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface $servletResponse The response instance * * @return void */ public function invoke(HttpServletRequestInterface $servletRequest, HttpServletResponseInterface $servletResponse) { try { // unpack the remote method call $remoteMethod = RemoteMethodProtocol::unpack($servletRequest->getBodyContent()); // load the application context /** @var \AppserverIo\Appserver\Application\Application $application */ $application = $servletRequest->getContext(); // prepare method name and parameters and invoke method $className = $remoteMethod->getClassName(); $methodName = $remoteMethod->getMethodName(); $parameters = $remoteMethod->getParameters(); $sessionId = $remoteMethod->getSessionId(); // load the bean manager and the bean instance $instance = $application->search($className, array($sessionId, array($application))); // invoke the remote method call on the local instance $response = call_user_func_array(array($instance, $methodName), $parameters); // serialize the remote method and write it to the socket $servletResponse->appendBodyStream(RemoteMethodProtocol::pack($response)); // re-attach the bean instance in the container and unlock it $application->search('BeanContextInterface')->attach($instance, $sessionId); } catch (\Exception $e) { // catch the exception and append it to the body stream $servletResponse->appendBodyStream(RemoteMethodProtocol::pack(RemoteExceptionWrapper::factory($e))); } // finally dispatch this request, because we have finished processing it $servletRequest->setDispatched(true); }
/** * Processes the request by invoking the request handler that executes the servlet * in a protected context. * * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface $servletRequest The request instance * @param \AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface $servletResponse The response instance * * @return void */ public function invoke(HttpServletRequestInterface $servletRequest, HttpServletResponseInterface $servletResponse) { try { // unpack the remote method call $remoteMethod = RemoteMethodProtocol::unpack($servletRequest->getBodyContent()); // load the application context /** @var \AppserverIo\Appserver\Application\Application $application */ $application = $servletRequest->getContext(); // invoke the remote method and re-attach the bean instance to the container $response = $application->search(BeanContextInterface::IDENTIFIER)->invoke($remoteMethod, new ArrayList()); // serialize the remote method and write it to the socket $servletResponse->appendBodyStream(RemoteMethodProtocol::pack($response)); } catch (\Exception $e) { // catch the exception and append it to the body stream $servletResponse->appendBodyStream(RemoteMethodProtocol::pack(RemoteExceptionWrapper::factory($e))); } // finally dispatch this request, because we have finished processing it $servletRequest->setDispatched(true); }