Package com.linkedin.r2.message.rest

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


  public static RemoteInvocationException exceptionForThrowable(Throwable e, RestResponseDecoder<?> responseDecoder)
  {
    if (e instanceof RestException)
    {
      final RestException re = (RestException) e;
      final RestResponse response = re.getResponse();
      final ErrorResponse errorResponse;

      try
      {
        errorResponse = getErrorResponse(response);
      }
      catch (RestLiDecodingException decodingException)
      {
        return new RemoteInvocationException(decodingException);
      }

      Response<?> decodedResponse = null;
      final String header = HeaderUtil.getErrorResponseHeaderValue(response.getHeaders());

      if (header == null)
      {
        try
        {
View Full Code Here


    final URI address = req.getURI();
    final RestRequestHandler handler = _restHandlers.get(address);

    if (handler == null)
    {
      final RestResponse response =
              RestStatus.responseForStatus(RestStatus.NOT_FOUND, "No resource for URI: " + address);
      callback.onResponse(TransportResponseImpl.success(response));
      return;
    }
View Full Code Here

  private void sendRequestAndVerifyParseqTraceRaw(RestRequest request)
      throws InterruptedException, ExecutionException
  {
    Future<RestResponse> restResponseFuture = CLIENT.restRequest(request);

    RestResponse restResponse = restResponseFuture.get();
    Assert.assertEquals(restResponse.getStatus(), 200);
    List<String> contentTypeValues = restResponse.getHeaderValues(RestConstants.HEADER_CONTENT_TYPE);
    Assert.assertTrue(contentTypeValues.size() == 1);
    Assert.assertEquals(contentTypeValues.get(0), HEADER_VALUE_APPLICATION_JSON);
    InputStream traceRawStream = restResponse.getEntity().asInputStream();

    JsonTraceCodec codec = new JsonTraceCodec();

    try
    {
View Full Code Here

  private void sendRequestAndVerifyParseqTracevisResponse(RestRequest request)
      throws InterruptedException, ExecutionException
  {
    Future<RestResponse> restResponseFuture = CLIENT.restRequest(request);

    RestResponse restResponse = restResponseFuture.get();
    Assert.assertEquals(restResponse.getStatus(), 200);
    List<String> contentTypeValues = restResponse.getHeaderValues(RestConstants.HEADER_CONTENT_TYPE);
    Assert.assertTrue(contentTypeValues.size() == 1);
    Assert.assertEquals(contentTypeValues.get(0), HEADER_VALUE_TEXT_HTML);
  }
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

        .entrySet())
    {
      resp.setHeader(e.getKey(), e.getValue());
    }

    RestResponse restResponse = null;
    if (response.hasError())
    {
      Throwable e = response.getError();
      if (e instanceof RestException)
      {
        restResponse = ((RestException) e).getResponse();
      }
      if (restResponse == null)
      {
        restResponse = RestStatus.responseForError(RestStatus.INTERNAL_SERVER_ERROR, e);
      }
    }
    else
    {
      restResponse = response.getResponse();
    }

    resp.setStatus(restResponse.getStatus());
    Map<String, String> headers = restResponse.getHeaders();
    for (Map.Entry<String, String> e : headers.entrySet())
    {
      // TODO multi-valued headers
      resp.setHeader(e.getKey(), e.getValue());
    }
    final ByteString entity = restResponse.getEntity();
    entity.write(resp.getOutputStream());

    resp.getOutputStream().close();
  }
View Full Code Here

    resp.getOutputStream().close();
  }

  protected void writeToServletError(HttpServletResponse resp, int statusCode, String message) throws IOException
  {
    RestResponse restResponse =
        RestStatus.responseForStatus(statusCode, message);
    writeToServletResponse(TransportResponseImpl.success(restResponse), resp);
  }
View Full Code Here

      @Override
      public void onError(Throwable e)
      {
        assertTrue(e instanceof RestException);
        RestException restException = (RestException)e;
        RestResponse restResponse = restException.getResponse();

        assertEquals(restResponse.getStatus(), 400);
        assertTrue(restResponse.getEntity().length() > 0);
        assertEquals(restResponse.getHeader(errorResponseHeaderName), RestConstants.HEADER_VALUE_ERROR);

        EasyMock.verify(statusResource);
        EasyMock.reset(statusResource);
      }
    };
View Full Code Here

      @Override
      public void onError(Throwable e)
      {
        assertTrue(e instanceof RestException);
        RestException restException = (RestException)e;
        RestResponse restResponse = restException.getResponse();

        try
        {
          assertEquals(restResponse.getStatus(), 500);
          assertTrue(restResponse.getEntity().length() > 0);
          assertEquals(restResponse.getHeader(errorResponseHeaderName), RestConstants.HEADER_VALUE_ERROR);
          ErrorResponse responseBody = DataMapUtils.read(restResponse.getEntity().asInputStream(), ErrorResponse.class);
          assertEquals(responseBody.getMessage(), "Mock Exception");
          assertEquals(responseBody.getExceptionClass(), "com.linkedin.restli.server.RestLiServiceException");
          assertTrue(responseBody.getStackTrace().startsWith(
              "com.linkedin.restli.server.RestLiServiceException [HTTP Status:500]: Mock Exception"));
          assertEquals(responseBody.getStatus().intValue(), 500);
View Full Code Here

      @Override
      public void onError(Throwable e)
      {
        assertTrue(e instanceof RestException);
        RestException restException = (RestException)e;
        RestResponse restResponse = restException.getResponse();

        try
        {
          ErrorResponse responseBody = DataMapUtils.read(restResponse.getEntity().asInputStream(), ErrorResponse.class);
          assertEquals(responseBody.getMessage(), ErrorResponseBuilder.DEFAULT_INTERNAL_ERROR_MESSAGE);

          EasyMock.verify(statusResource);
          EasyMock.reset(statusResource);
        }
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.