Search in sources :

Example 1 with PartialRestResponse

use of com.linkedin.restli.internal.server.response.PartialRestResponse in project rest.li by linkedin.

the class FilterChainCallbackImpl method onResponseSuccess.

@Override
public void onResponseSuccess(final RestLiResponseData responseData, final RestLiResponseAttachments responseAttachments) {
    final PartialRestResponse response = _responseHandler.buildPartialResponse(_method, responseData);
    _wrappedCallback.onSuccess(_responseHandler.buildResponse(_method, response), getRequestExecutionReport(), responseAttachments);
}
Also used : PartialRestResponse(com.linkedin.restli.internal.server.response.PartialRestResponse)

Example 2 with PartialRestResponse

use of com.linkedin.restli.internal.server.response.PartialRestResponse in project rest.li by linkedin.

the class FilterChainCallbackImpl method onError.

@Override
public void onError(Throwable th, final RestLiResponseData responseData, final RestLiResponseAttachments responseAttachments) {
    RestLiServiceException e = responseData.getServiceException();
    final PartialRestResponse response = _responseHandler.buildPartialResponse(_method, responseData);
    _wrappedCallback.onError(_responseHandler.buildRestException(e, response), getRequestExecutionReport(), _requestAttachmentReader, responseAttachments);
}
Also used : PartialRestResponse(com.linkedin.restli.internal.server.response.PartialRestResponse) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException)

Example 3 with PartialRestResponse

use of com.linkedin.restli.internal.server.response.PartialRestResponse in project rest.li by linkedin.

the class TestRestLiResponseHandler method testPartialRestResponse.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusActionDataPartial")
public void testPartialRestResponse(AcceptTypeData acceptTypeData, String response1, String response2, ProtocolVersion protocolVersion, String errorResponseHeaderName) throws Exception {
    final RestRequest request = buildRequest(acceptTypeData.acceptHeaders, protocolVersion);
    PartialRestResponse response;
    RoutingResult routingResult1 = buildRoutingResultAction(Status.class, request, acceptTypeData.acceptHeaders);
    // #1 simple record template
    response = _responseHandler.buildPartialResponse(routingResult1, _responseHandler.buildRestLiResponseData(request, routingResult1, buildStatusRecord()));
    checkResponse(response, HttpStatus.S_200_OK, 1, false, true, errorResponseHeaderName);
    assertEquals(response.getEntity().toString(), response1);
    // #2 DataTemplate response
    StringMap map = new StringMap();
    map.put("key1", "value1");
    map.put("key2", "value2");
    RoutingResult routingResult2 = buildRoutingResultAction(StringMap.class, request, acceptTypeData.acceptHeaders);
    response = _responseHandler.buildPartialResponse(routingResult2, _responseHandler.buildRestLiResponseData(request, routingResult2, map));
    checkResponse(response, HttpStatus.S_200_OK, 1, false, true, errorResponseHeaderName);
    //Obtain the maps necessary for comparison
    final DataMap actualMap;
    final DataMap expectedMap;
    actualMap = response.getDataMap();
    expectedMap = JACKSON_DATA_CODEC.stringToMap(response2);
    assertEquals(actualMap, expectedMap);
    RoutingResult routingResult3 = buildRoutingResultAction(Void.TYPE, request, acceptTypeData.acceptHeaders);
    // #3 empty response
    response = _responseHandler.buildPartialResponse(routingResult3, _responseHandler.buildRestLiResponseData(request, routingResult3, null));
    checkResponse(response, HttpStatus.S_200_OK, 1, false, false, errorResponseHeaderName);
    assertEquals(response.getEntity(), null);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) PartialRestResponse(com.linkedin.restli.internal.server.response.PartialRestResponse) StringMap(com.linkedin.data.template.StringMap) RestRequest(com.linkedin.r2.message.rest.RestRequest) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Aggregations

PartialRestResponse (com.linkedin.restli.internal.server.response.PartialRestResponse)3 DataMap (com.linkedin.data.DataMap)1 StringMap (com.linkedin.data.template.StringMap)1 RestRequest (com.linkedin.r2.message.rest.RestRequest)1 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)1 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)1 Test (org.testng.annotations.Test)1