Search in sources :

Example 1 with GetResult

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;
}
Also used : ResourceContext(com.linkedin.restli.server.ResourceContext) AnyRecord(com.linkedin.restli.internal.server.methods.AnyRecord) GetResult(com.linkedin.restli.server.GetResult) HttpStatus(com.linkedin.restli.common.HttpStatus) RecordTemplate(com.linkedin.data.template.RecordTemplate) DataMap(com.linkedin.data.DataMap)

Example 2 with GetResult

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);
}
Also used : UpdateStatus(com.linkedin.restli.common.UpdateStatus) CreateStatus(com.linkedin.restli.common.CreateStatus) Status(com.linkedin.restli.server.twitter.TwitterTestDataModels.Status) HttpStatus(com.linkedin.restli.common.HttpStatus) RestRequest(com.linkedin.r2.message.rest.RestRequest) GetResult(com.linkedin.restli.server.GetResult) ActionResult(com.linkedin.restli.server.ActionResult) RestResponse(com.linkedin.r2.message.rest.RestResponse) PartialRestResponse(com.linkedin.restli.internal.server.response.PartialRestResponse) ActionResponse(com.linkedin.restli.common.ActionResponse) Test(org.testng.annotations.Test)

Aggregations

HttpStatus (com.linkedin.restli.common.HttpStatus)2 GetResult (com.linkedin.restli.server.GetResult)2 DataMap (com.linkedin.data.DataMap)1 RecordTemplate (com.linkedin.data.template.RecordTemplate)1 RestRequest (com.linkedin.r2.message.rest.RestRequest)1 RestResponse (com.linkedin.r2.message.rest.RestResponse)1 ActionResponse (com.linkedin.restli.common.ActionResponse)1 CreateStatus (com.linkedin.restli.common.CreateStatus)1 UpdateStatus (com.linkedin.restli.common.UpdateStatus)1 AnyRecord (com.linkedin.restli.internal.server.methods.AnyRecord)1 PartialRestResponse (com.linkedin.restli.internal.server.response.PartialRestResponse)1 ActionResult (com.linkedin.restli.server.ActionResult)1 ResourceContext (com.linkedin.restli.server.ResourceContext)1 Status (com.linkedin.restli.server.twitter.TwitterTestDataModels.Status)1 Test (org.testng.annotations.Test)1