use of com.linkedin.restli.server.GetResult in project rest.li by linkedin.
the class GetResponseBuilder method buildRestLiResponseData.
@Override
public RestLiResponseData buildRestLiResponseData(RestRequest request, RoutingResult routingResult, Object result, Map<String, String> headers, List<HttpCookie> cookies) {
final RecordTemplate record;
final HttpStatus status;
if (result instanceof GetResult) {
final GetResult<?> getResult = (GetResult<?>) result;
record = getResult.getValue();
status = getResult.getStatus();
} else {
record = (RecordTemplate) result;
status = HttpStatus.S_200_OK;
}
final ResourceContext resourceContext = routingResult.getContext();
final DataMap data = RestUtils.projectFields(record.data(), resourceContext.getProjectionMode(), resourceContext.getProjectionMask());
RestLiResponseDataImpl responseData = new RestLiResponseDataImpl(status, headers, cookies);
responseData.setResponseEnvelope(new GetResponseEnvelope(new AnyRecord(data), responseData));
return responseData;
}
use of com.linkedin.restli.server.GetResult in project rest.li by linkedin.
the class TestRestLiResponseHandler method testWrapperResults.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusesData")
public void testWrapperResults(AcceptTypeData acceptTypeData, 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);
}
Aggregations