Search in sources :

Example 86 with RestResponseBuilder

use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.

the class PipelineStreamHandler method writeResponse.

private void writeResponse(Channel ch, TransportResponse<StreamResponse> response, RestResponse restResponse) {
    RestResponseBuilder responseBuilder = restResponse.builder().unsafeOverwriteHeaders(WireAttributeHelper.toWireAttributes(response.getWireAttributes()));
    ch.writeAndFlush(responseBuilder.build());
}
Also used : RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder)

Example 87 with RestResponseBuilder

use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.

the class PipelineRestHandler method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext ctx, RestRequest request) throws Exception {
    final Channel ch = ctx.channel();
    TransportCallback<RestResponse> writeResponseCallback = new TransportCallback<RestResponse>() {

        @Override
        public void onResponse(TransportResponse<RestResponse> response) {
            final RestResponseBuilder responseBuilder;
            if (response.hasError()) {
                // This onError is only getting called in cases where:
                // (1) the exception was thrown by the handleRequest() method, and the upper layer
                // dispatcher did not catch the exception or caught it and passed it here without
                // turning it into a Response, or
                // (2) the HttpBridge-installed callback's onError declined to convert the exception to a
                // response and passed it along to here.
                responseBuilder = new RestResponseBuilder(RestStatus.responseForError(RestStatus.INTERNAL_SERVER_ERROR, response.getError()));
            } else {
                responseBuilder = new RestResponseBuilder(response.getResponse());
            }
            responseBuilder.unsafeOverwriteHeaders(WireAttributeHelper.toWireAttributes(response.getWireAttributes())).build();
            ch.writeAndFlush(responseBuilder.build());
        }
    };
    try {
        _dispatcher.handleRequest(request, writeResponseCallback);
    } catch (Exception ex) {
        writeResponseCallback.onResponse(TransportResponseImpl.<RestResponse>error(ex, Collections.<String, String>emptyMap()));
    }
}
Also used : TransportCallback(com.linkedin.r2.transport.common.bridge.common.TransportCallback) RestResponse(com.linkedin.r2.message.rest.RestResponse) Channel(io.netty.channel.Channel) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) TransportResponse(com.linkedin.r2.transport.common.bridge.common.TransportResponse)

Aggregations

RestResponseBuilder (com.linkedin.r2.message.rest.RestResponseBuilder)87 RestResponse (com.linkedin.r2.message.rest.RestResponse)55 Test (org.testng.annotations.Test)53 RestRequest (com.linkedin.r2.message.rest.RestRequest)22 RestException (com.linkedin.r2.message.rest.RestException)18 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)17 RequestContext (com.linkedin.r2.message.RequestContext)15 ByteString (com.linkedin.data.ByteString)13 Map (java.util.Map)10 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)8 HashMap (java.util.HashMap)8 TransportCallback (com.linkedin.r2.transport.common.bridge.common.TransportCallback)6 RoutingException (com.linkedin.restli.server.RoutingException)6 DataMap (com.linkedin.data.DataMap)5 FilterChain (com.linkedin.r2.filter.FilterChain)5 CaptureLastCallFilter (com.linkedin.r2.testutils.filter.CaptureLastCallFilter)5 FilterRequestContext (com.linkedin.restli.server.filter.FilterRequestContext)5 FilterResponseContext (com.linkedin.restli.server.filter.FilterResponseContext)5 IOException (java.io.IOException)5 URI (java.net.URI)5