Package com.linkedin.r2.message.rest

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


      TransportCallback<RestResponse> writeResponseCallback = new TransportCallback<RestResponse>()
      {
        @Override
        public void onResponse(TransportResponse<RestResponse> response)
        {
          final RestResponseBuilder responseBuilder;
          if (response.hasError())
          {
            // This onError is only getting called in cases where:
            // (1) the exception was thrown by the handleRequest() method, and the upper layer
            // dispatcher did not catch the exception or caught it and passed it here without
            // turning it into a Response, or
            // (2) the HttpBridge-installed callback's onError declined to convert the exception to a
            // response and passed it along to here.
            responseBuilder =
                    new RestResponseBuilder(RestStatus.responseForError(RestStatus.INTERNAL_SERVER_ERROR, response.getError()));
          }
          else
          {
            responseBuilder = new RestResponseBuilder(response.getResponse());
          }

          responseBuilder
            .unsafeOverwriteHeaders(WireAttributeHelper.toWireAttributes(response.getWireAttributes()))
            .build();

          ch.write(responseBuilder.build());
        }
      };
      RestRequest request = (RestRequest) e.getMessage();
      try
      {
View Full Code Here


    FutureCallback<RestResponse> futureCallback = new FutureCallback<RestResponse>();
    TransportCallback<RestResponse> callback =
        new TransportCallbackAdapter<RestResponse>(futureCallback);
    TransportCallback<RestResponse> bridgeCallback = HttpBridge.httpToRestCallback(callback);

    RestResponse restResponse = new RestResponseBuilder().build();

    // Note: FutureCallback will fail if called twice. An exception would be raised on the current
    // thread because we begin the callback sequence here in onResponse.
    // (test originally added due to bug with double callback invocation)
    bridgeCallback.onResponse(TransportResponseImpl.<RestResponse> error(new RestException(restResponse)));
View Full Code Here

            Compressor compressor = selectedEncoding.getCompressor();
            byte[] compressed = compressor.deflate(res.getEntity().asInputStream());

            if (compressed.length < res.getEntity().length())
            {
              RestResponseBuilder resCompress = res.builder();
              resCompress.addHeaderValue(HttpConstants.CONTENT_ENCODING, compressor.getContentEncodingName());
              resCompress.setEntity(compressed);
              res = resCompress.build();
            }
          }
        }
        else
        {
View Full Code Here

  {
    String result = "foo";
    RequestExecutionReport executionReport = new RequestExecutionReportBuilder().build();
    AugmentedRestLiResponseData responseData = new AugmentedRestLiResponseData.Builder(ResourceMethod.GET).build();
    PartialRestResponse partialResponse = new PartialRestResponse.Builder().build();
    RestResponse restResponse = new RestResponseBuilder().build();
    // Set up.
    when(_responseHandler.buildRestLiResponseData(_restRequest, _routingResult, result)).thenReturn(responseData);
    when(_responseHandler.buildPartialResponse(_routingResult, responseData)).thenReturn(partialResponse);
    when(_responseHandler.buildResponse(_routingResult, partialResponse)).thenReturn(restResponse);
View Full Code Here

  }

  @Test
  public void testOnErrorRestExceptionNoFilters() throws Exception
  {
    RestException ex = new RestException(new RestResponseBuilder().build());
    RequestExecutionReport executionReport = new RequestExecutionReportBuilder().build();
    // Invoke.
    _noFilterRestLiCallback.onError(ex, executionReport);
    // Verify.
    verify(_callback).onError(ex, executionReport);
View Full Code Here

    @SuppressWarnings("rawtypes")
    ArgumentCaptor<Map> augErrorHeadersCapture = ArgumentCaptor.forClass(Map.class);
    AugmentedRestLiResponseData responseData =
        new AugmentedRestLiResponseData.Builder(ResourceMethod.GET).status(ex.getStatus()).headers(restExceptionHeaders).build();
    PartialRestResponse partialResponse = new PartialRestResponse.Builder().build();
    RestException restException = new RestException(new RestResponseBuilder().build());
    // Set up.
    when(_restRequest.getHeaders()).thenReturn(inputHeaders);
    when(
         _responseHandler.buildErrorResponseData(eq(_restRequest), eq(_routingResult), eq(ex),
                                                 augErrorHeadersCapture.capture())).thenReturn(responseData);
View Full Code Here

  public void testSetValidHeader()
  {
    final String headerName = "testName";
    final String headerValue = "testValue";

    final RestResponse res = new RestResponseBuilder()
            .setHeader(headerName, headerValue)
            .build();

    Assert.assertEquals(headerValue, res.getHeader(headerName));
  }
View Full Code Here

  {
    ArgumentCaptor<RestLiServiceException> exCapture = ArgumentCaptor.forClass(RestLiServiceException.class);
    RequestExecutionReport executionReport = new RequestExecutionReportBuilder().build();
    PartialRestResponse partialResponse = new PartialRestResponse.Builder().build();
    AugmentedRestLiResponseData responseData = new AugmentedRestLiResponseData.Builder(ResourceMethod.GET).build();
    RestException restException = new RestException(new RestResponseBuilder().build());
    Map<String, String> inputHeaders = Maps.newHashMap();
    inputHeaders.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, "2.0.0");

    // Set up.
    when(_restRequest.getHeaders()).thenReturn(inputHeaders);
View Full Code Here

        context.getResponseHeaders().putAll(headersFromFilters);
        return null;
      }
    }).when(_filter).onResponse(eq(_filterRequestContext), any(FilterResponseContext.class));

    RestResponse restResponse = new RestResponseBuilder().build();
    when(_responseHandler.buildResponse(_routingResult, partialResponse)).thenReturn(restResponse);

    // Invoke.
    _twoFilterRestLiCallback.onSuccess(result, executionReport);
View Full Code Here

            '{', '}', ' ', 9 /* HT */
    };

    for (char separator : separators)
    {
      final RestResponseBuilder builder = new RestResponseBuilder();
      try
      {
        builder.setHeader(headerBaseName + separator, headerValue);
        Assert.fail("Should have thrown exception for invalid char (separator): " + separator);
      }
      catch (IllegalArgumentException e)
      {
        // expected
View Full Code Here

TOP

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

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.