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());
}
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();
}
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();
}
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);
}
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());
}
Aggregations