Package com.linkedin.r2.message.rest

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


    ResourceContextImpl context = new ResourceContextImpl();
    context.setResponseHeader(testHeaderName, testHeaderValue);
    RestUtils.validateRequestHeadersAndUpdateResourceContext(acceptTypeData.acceptHeaders, context);
    RoutingResult routingResult = new RoutingResult(context, methodDescriptor);

    RestResponse response;
    response = _responseHandler.buildResponse(buildRequest(acceptTypeData.acceptHeaders, protocolVersion),
                                              routingResult,
                                              buildStatusList(3));

    Assert.assertEquals(response.getHeader(testHeaderName), testHeaderValue);
  }
View Full Code Here


                                 String expectedStatus,
                                 String expectedActionStatus,
                                 ProtocolVersion protocolVersion,
                                 String errorResponseHeaderName) throws Exception
  {
    RestResponse response;
    final Status status = buildStatusRecord();

    final GetResult<Status> getResult = new GetResult<Status>(status, HttpStatus.S_500_INTERNAL_SERVER_ERROR);
    response = invokeResponseHandler("/test", getResult, ResourceMethod.GET, acceptTypeData.acceptHeaders, protocolVersion);
    checkResponse(response, HttpStatus.S_500_INTERNAL_SERVER_ERROR.getCode(), 2, acceptTypeData.responseContentType, Status.class.getName(), null, true, errorResponseHeaderName);
    assertEquals(response.getEntity().asAvroString(), expectedStatus);

    final RestRequest request = buildRequest(acceptTypeData.acceptHeaders, protocolVersion);
    final ActionResult<Status> actionResult = new ActionResult<Status>(status, HttpStatus.S_500_INTERNAL_SERVER_ERROR);
    response = _responseHandler.buildResponse(request,
                                              buildRoutingResultAction(Status.class, request, acceptTypeData.acceptHeaders),
                                              actionResult);
    checkResponse(response,
                  HttpStatus.S_500_INTERNAL_SERVER_ERROR.getCode(),
                  2,
                  acceptTypeData.responseContentType,
                  ActionResponse.class.getName(),
                  Status.class.getName(),
                  true,
                  errorResponseHeaderName);
    assertEquals(response.getEntity().asAvroString(), expectedActionStatus);
  }
View Full Code Here

      DataMap dataMap = partialResponse.getDataMap();
      ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
      DataMapUtils.write(dataMap, null, baos, true); // partialResponse.getSchema()
      builder.setEntity(baos.toByteArray());
    }
    RestResponse restResponse = builder.build();
    RestException restException = new RestException(restResponse, e);
    return restException;
  }
View Full Code Here

  // is an upstream-only handler, we don't need to worry about downstream events.

  @Override
  public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception
  {
    RestResponse response = (RestResponse)e.getMessage();

    // In general there should always be a callback to handle a received message,
    // but it could have been removed due to a previous exception or closure on the
    // channel
    TransportCallback<RestResponse> callback = removeAttachment(ctx);
    if (callback != null)
    {
      LOG.debug("{}: handling a response", e.getChannel().getRemoteAddress());
      final Map<String, String> headers = new HashMap<String, String>(response.getHeaders());
      final Map<String, String> wireAttrs =
            new HashMap<String, String>(WireAttributeHelper.removeWireAttributes(headers));

      final RestResponse newResponse = new RestResponseBuilder(response)
              .unsafeSetHeaders(headers)
              .build();

      callback.onResponse(TransportResponseImpl.success(newResponse, wireAttrs));
    }
View Full Code Here

  public String formatResponse(Response response, URI requestUri, String requestMethod)
  {
    StringBuilder builder = new StringBuilder();
    if (response instanceof RestResponse)
    {
      RestResponse restResponse = (RestResponse) response;
      builder.append("\"").append(requestMethod);
      if(requestUri != null)
      {
        builder.append(" ").append(extractURI(requestUri.toString()));
      }
      builder.append(" ").append(restResponse.getStatus()).append("\"");
      builder.append(" headers=[").append(formatHeaders(restResponse.getHeaders())).append("]");
    }
    builder.append(" entityLength=").append(response.getEntity().length());
    return builder.toString();
  }
View Full Code Here

  {
    @Override
    protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg)
            throws Exception
    {
      RestResponse response = (RestResponse) msg;

      HttpResponse nettyResponse =
          new DefaultHttpResponse(HttpVersion.HTTP_1_1,
                                  HttpResponseStatus.valueOf(response.getStatus()));

      for (Map.Entry<String, String> e : response.getHeaders().entrySet())
      {
        nettyResponse.setHeader(e.getKey(), e.getValue());
      }
      final ByteString entity = response.getEntity();
      ChannelBuffer buf = ChannelBuffers.wrappedBuffer(entity.asByteBuffer());
      nettyResponse.setContent(buf);
      nettyResponse.setHeader(HttpHeaders.Names.CONTENT_LENGTH, entity.length());

      return nettyResponse;
View Full Code Here

{
  @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

  }

  @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

  }

  @Test
  public void testRestResponseReversible1() throws IOException
  {
    final RestResponse res = createRestResponse();
    assertMsgEquals(res, readRestRes(writeRes(res)));
  }
View Full Code Here

  }

  @Test
  public void testRestResponseReversible2() throws IOException
  {
    final RestResponse res = createRestResponse().builder()
            .setStatus(RestStatus.INTERNAL_SERVER_ERROR)
            .build();
    assertMsgEquals(res, readRestRes(writeRes(res)));
  }
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.