Examples of RestResponseBuilder


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

    protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg)
            throws Exception
    {
      HttpResponse nettyResponse = (HttpResponse) msg;

      RestResponseBuilder builder = new RestResponseBuilder();

      HttpResponseStatus status = nettyResponse.getStatus();
      builder.setStatus(status.getCode());

      for (Map.Entry<String, String> e : nettyResponse.getHeaders())
      {
        builder.unsafeAddHeaderValue(e.getKey(), e.getValue());
      }

      ChannelBuffer buf = nettyResponse.getContent();
      byte[] array = new byte[buf.readableBytes()];
      buf.readBytes(array);
      builder.setEntity(array);

      return builder.build();
    }
View Full Code Here

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

{
  @Test
  public void testReplayWithRestException()
  {
    final Request req = request();
    final RestResponse res = new RestResponseBuilder().setStatus(RestStatus.NOT_FOUND).build();

    final CaptureLastCallFilter captureFilter = new CaptureLastCallFilter();
    final FilterChain fc = getFilterChain().addFirst(captureFilter);

    // Record a response for the request we will fire
View Full Code Here

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

  }

  @Test
  public void testSimpleRestRes() throws IOException
  {
    final RestResponse expected = new RestResponseBuilder()
            .build();
    assertMsgEquals(expected, _serializer.readRestResponse(getResource("simple-rest-res.txt")));
  }
View Full Code Here

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

    return new RestRequestBuilder(URI.create("http://linkedin.com")).build();
  }

  private RestResponse createRestResponse()
  {
    return new RestResponseBuilder().build();
  }
View Full Code Here

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

    );
  }

  private void fireRestResponse(FilterChain fc)
  {
    fc.onRestResponse(new RestResponseBuilder().build(),
                      createRequestContext(), createWireAttributes()
    );
  }
View Full Code Here

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

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

    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

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

            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

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

  {
    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

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

  }

  @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
TOP
Copyright © 2018 www.massapi.com. 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.