Package com.linkedin.r2.message.rest

Examples of com.linkedin.r2.message.rest.RestResponse


                RestRequest request = rb.build();
                Future<RestResponse> f = client.restRequest(request);

                // This will block
                RestResponse response = f.get();

                // Parse the response
                final ByteString entity = response.getEntity();

                String contentType = response.getHeader(CONTENT_TYPE);
                if(entity != null) {
                    if(contentType.equalsIgnoreCase(MULTIPART_CONTENT_TYPE)) {

                        resultMap = parseGetAllResults(entity);
                    } else {
View Full Code Here


            String timeoutStr = Long.toString(this.config.getTimeoutConfig()
                                                         .getOperationTimeout(VoldemortOpCode.GET_VERSION_OP_CODE));

            rb.setHeader(RestMessageHeaders.X_VOLD_GET_VERSION, "true");

            RestResponse response = fetchGetResponse(rb, timeoutStr);
            final ByteString entity = response.getEntity();
            if(entity != null) {
                resultList = parseGetVersionResponse(entity);
            } else {
                if(logger.isDebugEnabled()) {
                    logger.debug("Did not get any response!");
View Full Code Here

            requestBuilder.setHeader(RestMessageHeaders.X_VOLD_REQUEST_TIMEOUT_MS, timeoutStr);
            requestBuilder = setCommonRequestHeader(requestBuilder);
            RestRequest request = requestBuilder.build();
            Future<RestResponse> future = client.restRequest(request);
            // This will block
            RestResponse response = future.get();
            ByteString entity = response.getEntity();
            return entity.asString("UTF-8");
        } catch(Exception e) {
            if(e.getCause() instanceof RestException) {
                return ((RestException) e.getCause()).getResponse().getEntity().asString("UTF-8");
            }
View Full Code Here

            RestRequest request = requestBuilder.build();
            Future<RestResponse> future = client.restRequest(request);

            // This will block
            RestResponse response = future.get();
            final ByteString entity = response.getEntity();
            if(entity == null) {
                if(logger.isDebugEnabled()) {
                    logger.debug("Empty response !");
                }
                responseMessage = "Received empty response from " + coordinatorUrl;
View Full Code Here

            requestBuilder = setCommonRequestHeader(requestBuilder);

            RestRequest request = requestBuilder.build();
            Future<RestResponse> future = client.restRequest(request);
            // This will block
            RestResponse response = future.get();
            final ByteString entity = response.getEntity();
            if(entity == null) {
                if(logger.isDebugEnabled()) {
                    logger.debug("Empty response !");
                }
                responseMessage = "Received empty response from " + coordinatorUrl;
View Full Code Here

      headers.putAll(getHeaders());
    }
    headers.put(errorHeaderName, "true");
    headers.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion.toString());

    RestResponse restResponse = new RestResponseBuilder()
        .setEntity(entity)
        .setStatus(status)
        .setHeaders(Collections.unmodifiableMap(headers))
        .build();
View Full Code Here

        .setStatus(status)
        .setHeaders(getHeaders())
        .setProtocolVersion(getProtocolVersion())
        .build();

    RestResponse restResponse = new RestResponseBuilder()
        .setEntity(entity)
        .setStatus(status)
        .setHeaders(decodedResponse.getHeaders())
        .build();
View Full Code Here

                                    @Override
                                    public void handleRequest(RestRequest request,
                                                               RequestContext requestContext,
                                                               RequestExecutionCallback<RestResponse> callback)
                                    {
                                      RestResponse response = EasyMock.createMock(RestResponse.class);
                                      RequestExecutionReportBuilder executionReportBuilder =
                                         new RequestExecutionReportBuilder();
                                      JsonTraceCodec jsonTraceCodec = new JsonTraceCodec();
                                      Trace t = null;
View Full Code Here

  private void sendByteArrayAsResponse(Callback<RestResponse> callback,
                                    byte[] responseBytes,
                                    String mediaType)
  {
    RestResponse staticContentResponse = new RestResponseBuilder().
                                          setStatus(HttpStatus.S_200_OK.getCode()).
                                          setHeader(RestConstants.HEADER_CONTENT_TYPE, mediaType).
                                          setEntity(responseBytes).
                                          build();
    callback.onSuccess(staticContentResponse);
View Full Code Here

                                 String expectedStatus,
                                 ProtocolVersion protocolVersion,
                                 String errorResponseHeaderName,
                                 String idHeaderName) throws Exception
  {
    RestResponse response;
    // #1 simple record template
    response = invokeResponseHandler("/test", buildStatusRecord(), ResourceMethod.GET, acceptTypeData.acceptHeaders, protocolVersion);

    checkResponse(response, 200, 2, acceptTypeData.responseContentType, Status.class.getName(), null, true, errorResponseHeaderName);
    assertEquals(response.getEntity().asAvroString(), expectedStatus);

    // #2 create (with id)
    response = invokeResponseHandler("/test", new CreateResponse(1), ResourceMethod.CREATE, acceptTypeData.acceptHeaders, protocolVersion);
    checkResponse(response, 201, 3, null, null, null, false, errorResponseHeaderName);
    assertEquals(response.getHeader(RestConstants.HEADER_LOCATION), "/test/1");
    assertEquals(response.getHeader(idHeaderName), "1");

    // #2.1 create (without id)
    response = invokeResponseHandler("/test", new CreateResponse(HttpStatus.S_201_CREATED),
                                     ResourceMethod.CREATE, acceptTypeData.acceptHeaders,
                                     protocolVersion);
    checkResponse(response, 201, 1, null, null, null, false, errorResponseHeaderName);

    // #2.2 create (with id and slash at the end of uri)
    response = invokeResponseHandler("/test/", new CreateResponse(1), ResourceMethod.CREATE, acceptTypeData.acceptHeaders, protocolVersion);
    checkResponse(response, 201, 3, null, null, null, false, errorResponseHeaderName);
    assertEquals(response.getHeader(RestConstants.HEADER_LOCATION), "/test/1");
    assertEquals(response.getHeader(idHeaderName), "1");

    // #2.3 create (without id and slash at the end of uri)
    response = invokeResponseHandler("/test/", new CreateResponse(HttpStatus.S_201_CREATED),
                                     ResourceMethod.CREATE, acceptTypeData.acceptHeaders,
                                     protocolVersion);
View Full Code Here

TOP

Related Classes of com.linkedin.r2.message.rest.RestResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.