コード例 #1
0
 /**
  * Execute a request
  *
  * @param  webservices.rest.RestRequest $request
  * @return webservices.rest.RestResponse
  * @throws lang.IllegalStateException if no connection is set
  */
 public function execute(RestRequest $request)
 {
     if (null === $this->connection) {
         throw new IllegalStateException('No connection set');
     }
     $send = $this->connection->create(new HttpRequest());
     $send->addHeaders($request->headerList());
     $send->setMethod($request->getMethod());
     $send->setTarget($request->getTarget($this->connection->getUrl()->getPath('/')));
     // Compose body
     // * Serialize payloads using the serializer for the given mimetype
     // * Use bodies as-is, e.g. file uploads
     // * If no body and no payload is set, use parameters
     if ($request->hasPayload()) {
         $send->setParameters(new RequestData($this->marshalling->marshal($request->getPayload()), $this->serializerFor($request->getContentType())));
     } else {
         if ($request->hasBody()) {
             $send->setParameters($request->getBody());
         } else {
             $send->setParameters($request->getParameters());
         }
     }
     try {
         $this->cat && $this->cat->debug('>>>', $send->getRequestString());
         $response = $this->connection->send($send);
     } catch (\io\IOException $e) {
         throw new RestException('Cannot send request', $e);
     }
     $reader = new ResponseReader($this->deserializerFor($response->header('Content-Type')[0]), $this->marshalling);
     $result = new RestResponse($response, $reader);
     $this->cat && $this->cat->debug('<<<', $response->toString(), $result->contentCopy());
     return $result;
 }
コード例 #2
0
 public function absoluteResource($base)
 {
     $fixture = new RestRequest('/issues');
     $this->assertEquals('/rest/api/v2/issues', $fixture->getTarget($base));
 }