use of com.linkedin.restli.server.ActionResult in project rest.li by linkedin.
the class ActionResponseBuilder method buildRestLiResponseData.
@Override
public RestLiResponseData buildRestLiResponseData(RestRequest request, RoutingResult routingResult, Object result, Map<String, String> headers, List<HttpCookie> cookies) {
final Object value;
final HttpStatus status;
if (result instanceof ActionResult) {
final ActionResult<?> actionResult = (ActionResult<?>) result;
value = actionResult.getValue();
status = actionResult.getStatus();
if (status == null) {
throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, "Unexpected null encountered. Null HttpStatus inside of an ActionResult returned by the resource method: " + routingResult.getResourceMethod());
}
} else {
value = result;
status = HttpStatus.S_200_OK;
}
RecordDataSchema actionReturnRecordDataSchema = routingResult.getResourceMethod().getActionReturnRecordDataSchema();
@SuppressWarnings("unchecked") FieldDef<Object> actionReturnFieldDef = (FieldDef<Object>) routingResult.getResourceMethod().getActionReturnFieldDef();
final ActionResponse<?> actionResponse = new ActionResponse<Object>(value, actionReturnFieldDef, actionReturnRecordDataSchema);
RestLiResponseDataImpl responseData = new RestLiResponseDataImpl(status, headers, cookies);
responseData.setResponseEnvelope(new ActionResponseEnvelope(actionResponse, responseData));
return responseData;
}
use of com.linkedin.restli.server.ActionResult 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);
}
use of com.linkedin.restli.server.ActionResult in project rest.li by linkedin.
the class ExampleRequestResponseGenerator method buildActionResult.
private ActionResult<?> buildActionResult(ActionSchema actionSchema) {
DynamicRecordMetadata returnsMetadata = _resourceSpec.getActionResponseMetadata(actionSchema.getName());
if (actionSchema.hasReturns()) {
FieldDef<?> fieldDef = returnsMetadata.getFieldDef("value");
Object returnValue = generateFieldDefValue(fieldDef);
return new ActionResult<Object>(returnValue);
} else {
return null;
}
}
Aggregations