Package com.linkedin.r2.message.rest

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


  public void restRequest(RestRequest request, RequestContext requestContext,
                          Callback<RestResponse> callback)
  {
    TransportCallback<RestResponse> adapter = HttpBridge.restToHttpCallback(new TransportCallbackAdapter<RestResponse>(callback), request);

    RestResponse response = new RestResponseBuilder()
            .setStatus(status())
            .setHeaders(headers())
            .setEntity(body())
            .build();
View Full Code Here


          callback.onResponse(TransportResponseImpl.<RestResponse> error(response.getError(),
                                                                         response.getWireAttributes()));
          return;
        }

        final RestResponse restResponse = new RestResponseBuilder()
                .setEntity(response.getResponse().getEntity())
                .setStatus(RestStatus.OK)
                .build();
        callback.onResponse(TransportResponseImpl.success(restResponse,
                                                          response.getWireAttributes()));
View Full Code Here

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

    FilterUtil.fireUntypedRequestError(getFilterChain(), req, ex);

    Assert.assertEquals(res, getDb().replay(req));
View Full Code Here

    _server = new RestLiServer(config, _resourceFactory, engine);
  }

  private void handleRequestWithCustomResponse(Callback<RestResponse> callback, String response)
  {
    RestResponseBuilder responseBuilder = new RestResponseBuilder();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    try
    {
      IOUtils.write(response, outputStream);
    }
    catch (IOException exc)
    {
      //Test will fail later.
    }

    responseBuilder.setEntity(outputStream.toByteArray());
    callback.onSuccess(responseBuilder.build());
  }
View Full Code Here

  }

  @Override
  public RestResponse readRestResponse(InputStream in) throws IOException
  {
    final RestResponseBuilder builder = new RestResponseBuilder();
    readResLine(builder, in);
    readHeaders(builder, in);
    readEntity(builder, in);
    return builder.build();
  }
View Full Code Here

  /**
   * @return {@link RestResponse} based on this exception
   */
  public RestResponse buildRestResponse()
  {
    RestResponseBuilder builder = new RestResponseBuilder().setStatus(_status);
    if (getMessage() != null)
    {
      builder.setEntity(ByteString.copyString(getMessage(), Charset.defaultCharset()));
    }

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

  }

  @Test
  public void testEmptyErrorResponse()
  {
    RestResponse response = new RestResponseBuilder().setStatus(200).build();
    RestLiResponseException e = new RestLiResponseException(response, null, new ErrorResponse());

    Assert.assertNull(e.getServiceErrorMessage());
    Assert.assertNull(e.getErrorDetails());
    Assert.assertNull(e.getErrorSource());
View Full Code Here

  private static class FoobarHandler implements RestRequestHandler
  {
    @Override
    public void handleRequest(RestRequest request, RequestContext requestContext, Callback<RestResponse> callback)
    {
      RestResponseBuilder builder = new RestResponseBuilder();
      builder.setStatus(RestStatus.OK);
      builder.setEntity("Hello, world!".getBytes());
      RestResponse response = builder.build();
      callback.onSuccess(response);
    }
View Full Code Here

                        .setMaxR2ConnectionPoolSize(100);
        clientFactory = new HttpClientFactory();
        Map<String, String> properties = new HashMap<String, String>();
        properties.put(HttpClientFactory.HTTP_POOL_SIZE,
                       Integer.toString(restClientConfig.getMaxR2ConnectionPoolSize()));
        TransportClient transportClient = clientFactory.getClient(properties);
        R2Store r2Store = new R2Store(STORE_NAME,
                                      restClientConfig.getHttpBootstrapURL(),
                                      "0",
                                      transportClient,
                                      restClientConfig,
View Full Code Here

                   int zoneId) {
        super(storeName);
        if(transportClient == null) {
            this.client = d2Client;
        } else {
            this.client = new TransportClientAdapter(transportClient);
        }
        this.config = config;
        this.restBootstrapURL = restBootstrapURL;
        this.mapper = new ObjectMapper();
        this.routingTypeCode = routingCodeStr;
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.