Search in sources :

Example 41 with TransportCallbackAdapter

use of com.linkedin.r2.transport.common.bridge.client.TransportCallbackAdapter in project rest.li by linkedin.

the class TransportDispatcherImpl method handleRestRequest.

@Override
public void handleRestRequest(RestRequest req, Map<String, String> wireAttrs, RequestContext requestContext, TransportCallback<RestResponse> callback) {
    final URI address = req.getURI();
    RestRequestHandler handler = _restHandlers.get(address);
    if (handler == null) {
        callback.onResponse(TransportResponseImpl.success(RestStatus.responseForStatus(RestStatus.NOT_FOUND, "No resource for URI:" + address)));
        return;
    }
    try {
        handler.handleRequest(req, requestContext, new TransportCallbackAdapter<RestResponse>(callback));
    } catch (Exception e) {
        callback.onResponse(TransportResponseImpl.<RestResponse>error(RestException.forError(RestStatus.INTERNAL_SERVER_ERROR, e)));
    }
}
Also used : RestResponse(com.linkedin.r2.message.rest.RestResponse) URI(java.net.URI) RestRequestHandler(com.linkedin.r2.transport.common.RestRequestHandler) RestException(com.linkedin.r2.message.rest.RestException)

Aggregations

RequestContext (com.linkedin.r2.message.RequestContext)34 FutureCallback (com.linkedin.common.callback.FutureCallback)30 RestRequest (com.linkedin.r2.message.rest.RestRequest)30 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)27 Test (org.testng.annotations.Test)26 RestResponse (com.linkedin.r2.message.rest.RestResponse)23 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)22 TransportCallbackAdapter (com.linkedin.r2.transport.common.bridge.client.TransportCallbackAdapter)22 ExecutionException (java.util.concurrent.ExecutionException)21 RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)15 URI (java.net.URI)15 ByteString (com.linkedin.data.ByteString)14 TimeoutException (java.util.concurrent.TimeoutException)13 AsciiString (io.netty.util.AsciiString)10 None (com.linkedin.common.util.None)8 HashMap (java.util.HashMap)7 RestException (com.linkedin.r2.message.rest.RestException)6 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)6 TransportCallback (com.linkedin.r2.transport.common.bridge.common.TransportCallback)6 Server (org.eclipse.jetty.server.Server)6