示例#1
0
 public function testDefaultHeaders()
 {
     $defaultHeaders = new Headers(array('custom-header' => 'custom header value', 'next-custom-header' => 'sum ting wong'));
     $this->object->setDefaultHeaders($defaultHeaders);
     $request = new Request(MessageTypes::PING);
     $this->useRequest($request);
     $response = new Response(MessageTypes::PONG);
     $response->getHeaders()->set('custom-header', 'custom header value')->set('next-custom-header', 'sum ting wong');
     $this->useResponse($request, $response);
     $this->object->handleCall();
 }
示例#2
0
 public function testHeadersForwarding()
 {
     $this->object->setForwardedHeaders(array('custom-header'));
     $request = new Request(MessageTypes::ONE_WAY, 'owc', array('zia'));
     $request->getHeaders()->set('request-id', '1234567890')->set('custom-header', 'some value')->set('next-custom-header', 'next value');
     $this->useRequest($request);
     $this->rpcTarget->expects($this->once())->method('owc')->with('zia')->will($this->returnValue('OK'));
     $response = new Response(MessageTypes::ONE_WAY_ACK);
     $response->getHeaders()->set('request-id', '1234567890')->set('custom-header', 'some value');
     $this->useResponse($request, $response);
     $this->object->handleCall();
 }
示例#3
0
 protected function useResponse(Request $request, Response $response, $filter = null)
 {
     if ($request->isExpectingResult()) {
         $this->serializer->expects($this->once())->method($response->getType() === MessageTypes::ERROR ? 'serializeError' : 'serializeResult')->with($request->getMethodName(), $this->equalTo($response->getResultBody(), 0, 0), $response->getHeaders()->get('content-type'))->will($this->returnValue($response->getResultBody()));
     } else {
         $this->serializer->expects($this->never())->method('serializeResult');
     }
     if (!$filter) {
         $filter = function () {
         };
     }
     $this->transport->expects($this->once())->method('sendResponse')->with($response)->will($this->returnCallback($filter));
 }
示例#4
0
 public function testResultShouldBeSerializedUsingResponseContentType()
 {
     $request = new Request(MessageTypes::REQUEST, 'basic', array('zia'));
     $this->useRequest($request);
     $this->rpcTarget->expects($this->once())->method('basic')->with('zia')->will($this->returnCallback(function ($arg1, $request, Headers $headers) {
         $headers->set('content-type', 'application/wookieb');
         return 'OK';
     }));
     $response = new Response(MessageTypes::RESPONSE, 'OK');
     $response->getHeaders()->set('content-type', 'application/wookieb');
     $this->useResponse($request, $response);
     $this->object->handleCall();
 }
 /**
  * {@inheritDoc}
  */
 public function sendResponse(Response $response)
 {
     $message = array($response->getType(), (string) $response->getHeaders());
     if (MessageTypes::isResponseTypeWithResult($response->getType())) {
         $message[2] = $response->getResultBody();
     }
     try {
         $this->socket->sendMulti($message);
         $this->waitingForResponse = false;
     } catch (\Exception $e) {
         $this->waitingForResponse = false;
         throw new TransportException('Unable to send request', null, $e);
     }
 }
示例#6
0
 private function handleError(Response $response, Request $request)
 {
     $responseData = $this->serializer->unserializeError($request->getMethodName(), $response->getResultBody(), $response->getHeaders()->get('Content-Type'));
     if ($responseData instanceof \Exception) {
         $this->replaceExceptionTrace($responseData);
         throw $responseData;
     }
     if ($request->getType() === MessageTypes::PING) {
         $msg = 'Error caught during ping';
     } else {
         $msg = 'Error caught during execution of method "' . $request->getMethodName() . '"';
     }
     throw new ErrorResponseException($msg, $responseData);
 }
示例#7
0
 private function forwardHeaders(Request $request, Response $response)
 {
     $requestHeaders = $request->getHeaders();
     $responseHeaders = $response->getHeaders();
     foreach ($this->forwardedHeaders as $header) {
         $headerValue = $requestHeaders->get($header);
         if ($headerValue) {
             $responseHeaders->set($header, $headerValue);
         }
     }
     return $response;
 }