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 MultiplexedRequestHandlerImpl method aggregateResponses.
private static RestResponse aggregateResponses(IndividualResponseMap responses, Map<String, HttpCookie> responseCookies) {
MultiplexedResponseContent aggregatedResponseContent = new MultiplexedResponseContent();
aggregatedResponseContent.setResponses(responses);
byte[] aggregatedResponseData = DataMapUtils.mapToBytes(aggregatedResponseContent.data());
return new RestResponseBuilder().setStatus(HttpStatus.S_200_OK.getCode()).setEntity(aggregatedResponseData).setCookies(CookieUtil.encodeSetCookies(new ArrayList(responseCookies.values()))).build();
}
use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.
the class RestLiResponseHandler method buildResponse.
/**
* Build a RestResponse from PartialRestResponse and RoutingResult.
*
* @param routingResult
* {@link RoutingResult}
* @param partialResponse
* {@link PartialRestResponse}
* @return
*/
public RestResponse buildResponse(final RoutingResult routingResult, PartialRestResponse partialResponse) {
List<String> cookies = CookieUtil.encodeSetCookies(partialResponse.getCookies());
RestResponseBuilder builder = new RestResponseBuilder().setHeaders(partialResponse.getHeaders()).setCookies(cookies).setStatus(partialResponse.getStatus().getCode());
if (partialResponse.hasData()) {
DataMap dataMap = partialResponse.getDataMap();
String mimeType = ((ServerResourceContext) routingResult.getContext()).getResponseMimeType();
builder = encodeResult(mimeType, builder, dataMap);
}
return builder.build();
}
use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.
the class TestMultiplexedRequestHandlerImpl method fakeMuxRestResponse.
private static RestResponse fakeMuxRestResponse(Map<Integer, IndividualResponse> responses) throws IOException {
IndividualResponseMap individualResponseMap = new IndividualResponseMap();
for (Map.Entry<Integer, IndividualResponse> responseMapEntry : responses.entrySet()) {
individualResponseMap.put(Integer.toString(responseMapEntry.getKey()), responseMapEntry.getValue());
}
MultiplexedResponseContent content = new MultiplexedResponseContent();
content.setResponses(individualResponseMap);
return new RestResponseBuilder().setStatus(HttpStatus.S_200_OK.getCode()).setEntity(CODEC.mapToBytes(content.data())).build();
}
use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.
the class TestBuilders method testChainBuildRestResponseFromRestResponseBuilder.
@Test
public void testChainBuildRestResponseFromRestResponseBuilder() {
final RestResponse res = new RestResponseBuilder().setEntity(new byte[] { 1, 2, 3, 4 }).setHeader("k1", "v1").setStatus(300).build().builder().setEntity(new byte[] { 5, 6, 7, 8 }).setHeader("k2", "v2").setStatus(400).build();
Assert.assertEquals(new byte[] { 5, 6, 7, 8 }, res.getEntity().copyBytes());
Assert.assertEquals("v1", res.getHeader("k1"));
Assert.assertEquals("v2", res.getHeader("k2"));
Assert.assertEquals(400, res.getStatus());
}
Aggregations