Search in sources :

Example 26 with RestLiResponse

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

the class ExampleRequestResponseGenerator method buildResponse.

private RestResponse buildResponse(Object responseEntity, ResourceMethodDescriptor method, RestRequest restRequest) {
    try {
        RequestContext requestContext = new RequestContext();
        ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), restRequest, requestContext);
        RestUtils.validateRequestHeadersAndUpdateResourceContext(restRequest.getHeaders(), Collections.emptySet(), context, requestContext);
        method.setResourceModel(_resourceModel);
        final RoutingResult routingResult = new RoutingResult(context, method);
        RestLiResponseData<?> responseData = _responseHandler.buildRestLiResponseData(restRequest, routingResult, responseEntity);
        RestLiResponse restLiResponse = _responseHandler.buildPartialResponse(routingResult, responseData);
        return ResponseUtils.buildResponse(routingResult, restLiResponse);
    } catch (RestLiSyntaxException e) {
        throw new ExampleGenerationException("Internal error during example generation", e);
    } catch (IOException e) {
        throw new ExampleGenerationException("Unable to build example response", e);
    }
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RestLiSyntaxException(com.linkedin.restli.internal.server.util.RestLiSyntaxException) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) PathKeysImpl(com.linkedin.restli.internal.server.PathKeysImpl) RestLiResponse(com.linkedin.restli.internal.server.response.RestLiResponse) RequestContext(com.linkedin.r2.message.RequestContext) IOException(java.io.IOException) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl)

Example 27 with RestLiResponse

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

the class FilterChainCallbackImpl method onResponseSuccess.

@Override
public void onResponseSuccess(final RestLiResponseData<?> responseData) {
    markOnResponseTimings(_method.getContext().getRawRequestContext());
    RestLiResponse partialResponse;
    try {
        partialResponse = _responseHandler.buildPartialResponse(_method, responseData);
    } catch (Throwable th) {
        LOGGER.error("Unexpected error while building the success response. Converting to error response.", th);
        _wrappedCallback.onError(new RestLiResponseException(th, buildErrorResponse(th, responseData)));
        return;
    }
    _wrappedCallback.onSuccess(partialResponse);
}
Also used : RestLiResponse(com.linkedin.restli.internal.server.response.RestLiResponse) RestLiResponseException(com.linkedin.restli.internal.server.response.RestLiResponseException)

Aggregations

RestLiResponse (com.linkedin.restli.internal.server.response.RestLiResponse)27 Test (org.testng.annotations.Test)21 RestRequest (com.linkedin.r2.message.rest.RestRequest)18 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)14 DataMap (com.linkedin.data.DataMap)9 HttpStatus (com.linkedin.restli.common.HttpStatus)9 Status (com.linkedin.restli.server.twitter.TwitterTestDataModels.Status)9 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)8 ResourceContextImpl (com.linkedin.restli.internal.server.ResourceContextImpl)7 Callback (com.linkedin.common.callback.Callback)5 ByteString (com.linkedin.data.ByteString)5 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)5 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)5 URI (java.net.URI)5 RequestContext (com.linkedin.r2.message.RequestContext)4 RestLiResponseException (com.linkedin.restli.internal.server.response.RestLiResponseException)4 RestLiSyntaxException (com.linkedin.restli.internal.server.util.RestLiSyntaxException)4 AfterTest (org.testng.annotations.AfterTest)4 BeforeTest (org.testng.annotations.BeforeTest)4 RestResponse (com.linkedin.r2.message.rest.RestResponse)3