Search in sources :

Example 31 with RestResponseBuilder

use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.

the class EchoHandler method handleRequest.

@Override
public void handleRequest(RestRequest request, RequestContext requestContext, final Callback<RestResponse> callback) {
    RestResponseBuilder builder = new RestResponseBuilder();
    callback.onSuccess(builder.setEntity(request.getEntity()).build());
}
Also used : RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder)

Example 32 with RestResponseBuilder

use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.

the class RestLiResponseException method createErrorRestResponse.

private static RestResponse createErrorRestResponse(ErrorResponse errorResponse) {
    RestResponseBuilder builder = new RestResponseBuilder().setStatus(errorResponse.getStatus());
    String errorMessage = errorResponse.getMessage();
    if (errorMessage != null) {
        builder.setEntity(errorMessage.getBytes());
    }
    return builder.build();
}
Also used : RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder)

Example 33 with RestResponseBuilder

use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.

the class MultiplexedCallback method buildIndividualRestResponse.

private static RestResponse buildIndividualRestResponse(Response<?> envelopeResponse, IndividualResponse individualResponse) throws IOException, MimeTypeParseException {
    IndividualBody body = individualResponse.getBody(GetMode.NULL);
    ByteString entity = (body != null) ? DataMapConverter.dataMapToByteString(individualResponse.getHeaders(), body.data()) : ByteString.empty();
    return new RestResponseBuilder().setStatus(individualResponse.getStatus()).setHeaders(inheritHeaders(individualResponse, envelopeResponse)).setCookies(CookieUtil.encodeSetCookies(envelopeResponse.getCookies())).setEntity(entity).build();
}
Also used : IndividualBody(com.linkedin.restli.common.multiplexer.IndividualBody) ByteString(com.linkedin.data.ByteString) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder)

Example 34 with RestResponseBuilder

use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.

the class MockRestliResponseExceptionBuilder method build.

public RestLiResponseException build() {
    String errorHeaderName = _version.equals(AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion()) ? RestConstants.HEADER_LINKEDIN_ERROR_RESPONSE : RestConstants.HEADER_RESTLI_ERROR_RESPONSE;
    Map<String, String> headers = new HashMap<String, String>();
    headers.put(errorHeaderName, "true");
    headers.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, _version.toString());
    headers.putAll(_headers);
    RestResponse restResponse = new RestResponseBuilder().setEntity(mapToBytes(_errorResponse.data())).setStatus(_errorResponse.hasStatus() ? _errorResponse.getStatus() : DEFAULT_HTTP_STATUS).setHeaders(Collections.unmodifiableMap(headers)).setCookies(Collections.unmodifiableList(CookieUtil.encodeCookies(_cookies.isEmpty() ? Collections.emptyList() : _cookies))).build();
    return new RestLiResponseException(restResponse, null, _errorResponse);
}
Also used : HashMap(java.util.HashMap) RestResponse(com.linkedin.r2.message.rest.RestResponse) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException)

Example 35 with RestResponseBuilder

use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.

the class TestChannelPoolHandler method testConnectionKeepAlive.

@Test(dataProvider = "connectionKeepAlive")
public void testConnectionKeepAlive(String headerName, String headerValue) {
    EmbeddedChannel ch = new EmbeddedChannel(new ChannelPoolHandler());
    FakePool pool = new FakePool();
    ch.attr(ChannelPoolHandler.CHANNEL_POOL_ATTR_KEY).set(pool);
    RestResponse response = new RestResponseBuilder().setHeader(headerName, headerValue).build();
    ch.writeInbound(response);
    Assert.assertFalse(pool.isDisposeCalled());
    Assert.assertTrue(pool.isPutCalled());
}
Also used : RestResponse(com.linkedin.r2.message.rest.RestResponse) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.testng.annotations.Test)

Aggregations

RestResponseBuilder (com.linkedin.r2.message.rest.RestResponseBuilder)67 Test (org.testng.annotations.Test)45 RestResponse (com.linkedin.r2.message.rest.RestResponse)41 RestException (com.linkedin.r2.message.rest.RestException)23 RequestExecutionReport (com.linkedin.restli.server.RequestExecutionReport)14 RequestExecutionReportBuilder (com.linkedin.restli.server.RequestExecutionReportBuilder)14 RestLiResponseAttachments (com.linkedin.restli.server.RestLiResponseAttachments)14 BeforeTest (org.testng.annotations.BeforeTest)14 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)13 FilterRequestContext (com.linkedin.restli.server.filter.FilterRequestContext)11 RoutingException (com.linkedin.restli.server.RoutingException)10 FilterResponseContext (com.linkedin.restli.server.filter.FilterResponseContext)10 EmptyRecord (com.linkedin.restli.common.EmptyRecord)9 InvocationOnMock (org.mockito.invocation.InvocationOnMock)9 RestRequest (com.linkedin.r2.message.rest.RestRequest)8 HashMap (java.util.HashMap)8 RequestContext (com.linkedin.r2.message.RequestContext)7 ByteString (com.linkedin.data.ByteString)6 RecordTemplate (com.linkedin.data.template.RecordTemplate)6 Map (java.util.Map)6