/** * Processes the request by invoking the request handler that attaches the message to the * requested queue 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 * @throws \Exception Is thrown if the requested message queue is not available */ public function invoke(HttpServletRequestInterface $servletRequest, HttpServletResponseInterface $servletResponse) { // load the application context /** @var \AppserverIo\Appserver\Application\Application $application */ $application = $servletRequest->getContext(); // unpack the message $message = MessageQueueProtocol::unpack($servletRequest->getBodyContent()); // load message queue name $queueName = $message->getDestination()->getName(); // lookup the message queue manager and attach the message $queueManager = $application->search('QueueContextInterface'); if ($messageQueue = $queueManager->lookup($queueName)) { $messageQueue->attach($message); } else { throw new \Exception("Can\\'t find queue for message queue {$queueName}"); } // finally dispatch this request, because we have finished processing it $servletRequest->setDispatched(true); }
/** * Parses the request body and tries to unpack the remote method * instance from it. * * @param \AppserverIo\Psr\Socket\SocketInterface $connection The package remote method instance * @param integer $contentLength The content length to read * * @return object The unpacked message object */ public function parseBody(SocketInterface $connection, $contentLength) { $rawResponse = stream_get_contents($connection->getConnectionResource(), $contentLength); return MessageQueueProtocol::unpack($rawResponse); }