/**
  * Execute a given HTTP request.
  *
  * @param ehough_shortstop_api_HttpRequest $request The HTTP request.
  *
  * @throws ehough_shortstop_api_exception_RuntimeException If something goes wrong.
  *
  * @return ehough_shortstop_api_HttpResponse The HTTP response.
  */
 public final function execute(ehough_shortstop_api_HttpRequest $request)
 {
     /**
      * Fire request event.
      */
     $requestEvent = new ehough_tickertape_GenericEvent($request);
     $this->_eventDispatcher->dispatch(ehough_shortstop_api_Events::REQUEST, $requestEvent);
     /**
      * Execute the chain.
      */
     $chainContext = new ehough_chaingang_impl_StandardContext();
     $chainContext->put('request', $request);
     $result = $this->_executionChain->execute($chainContext);
     if (!$result || !$chainContext->containsKey('response') || !$chainContext->get('response') instanceof ehough_shortstop_api_HttpResponse) {
         throw new ehough_shortstop_api_exception_RuntimeException(sprintf('No HTTP transports could execute %s', $request));
     }
     /**
      * Fire response event.
      */
     $response = $chainContext->get('response');
     $responseEvent = new ehough_tickertape_GenericEvent($response, array('request' => $requestEvent->getSubject()));
     $this->_eventDispatcher->dispatch(ehough_shortstop_api_Events::RESPONSE, $responseEvent);
     /**
      * All done. Return the response.
      */
     return $response;
 }
 /**
  * Decodes an HTTP response.
  *
  * @param ehough_shortstop_api_HttpResponse $response The HTTP response.
  *
  * @return void
  */
 public final function decode(ehough_shortstop_api_HttpResponse $response)
 {
     $context = new ehough_chaingang_impl_StandardContext();
     $context->put('response', $response);
     $status = $this->_chain->execute($context);
     if ($status === false) {
         return;
     }
     $entity = $response->getEntity();
     $decoded = $context->get('response');
     $entity->setContent($decoded);
     $entity->setContentLength(strlen($decoded));
     $contentType = $response->getHeaderValue(ehough_shortstop_api_HttpMessage::HTTP_HEADER_CONTENT_TYPE);
     if ($contentType !== null) {
         $entity->setContentType($contentType);
     }
     $response->setEntity($entity);
 }