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);
}