Search in sources :

Example 21 with RemoteInvocationException

use of com.linkedin.r2.RemoteInvocationException in project rest.li by linkedin.

the class TestGeneralEchoServiceTest method testOnExceptionEchoService.

@Test
public void testOnExceptionEchoService() throws Exception {
    final EchoService client = getEchoClient(_client, Bootstrap.getOnExceptionEchoURI());
    final String msg = "This is a simple echo message";
    final FutureCallback<String> callback = new FutureCallback<>();
    client.echo(msg, callback);
    try {
        callback.get();
        Assert.fail("Should have thrown an exception");
    } catch (ExecutionException e) {
        Assert.assertTrue(e.getCause() instanceof RemoteInvocationException);
    }
}
Also used : EchoService(com.linkedin.r2.sample.echo.EchoService) RemoteInvocationException(com.linkedin.r2.RemoteInvocationException) ExecutionException(java.util.concurrent.ExecutionException) FutureCallback(com.linkedin.common.callback.FutureCallback) AbstractEchoServiceTest(test.r2.integ.clientserver.providers.AbstractEchoServiceTest) Test(org.testng.annotations.Test)

Example 22 with RemoteInvocationException

use of com.linkedin.r2.RemoteInvocationException in project rest.li by linkedin.

the class StreamWriter method onError.

/**
 * Notifies the writer that a {@link ChannelPipeline} error is encountered. Only the first invocation
 * is raised and the subsequent invocations are ignored.
 *
 * @param throwable error encountered by the channel pipeline.
 */
public void onError(Throwable throwable) {
    if (_wh == null) {
        _failureBeforeInit = throwable;
    } else {
        if (!_errorRaised) {
            _wh.error(new RemoteInvocationException(throwable));
            _errorRaised = true;
        }
    }
}
Also used : RemoteInvocationException(com.linkedin.r2.RemoteInvocationException)

Example 23 with RemoteInvocationException

use of com.linkedin.r2.RemoteInvocationException in project rest.li by linkedin.

the class RestClientTest method getErrorResponse.

private <T extends RecordTemplate> RestLiResponseException getErrorResponse(GetResponseOption option, ResponseFuture<T> future, TimeoutOption timeoutOption) throws InterruptedException, TimeoutException, RemoteInvocationException {
    Response<T> response = null;
    T entity;
    RestLiResponseException result = null;
    Long l = timeoutOption._l;
    TimeUnit timeUnit = timeoutOption._timeUnit;
    switch(option) {
        case GET:
            try {
                response = l == null ? future.get() : future.get(l, timeUnit);
                Assert.fail("Should have thrown");
            } catch (ExecutionException e) {
                Throwable cause = e.getCause();
                Assert.assertTrue(cause instanceof RestException, "Expected RestLiResponseException not " + cause.getClass().getName());
                result = (RestLiResponseException) cause;
            }
            break;
        case GET_RESPONSE:
        case GET_RESPONSE_EXPLICIT_THROW:
            try {
                response = l == null ? future.getResponse() : future.getResponse(l, timeUnit);
                Assert.fail("Should have thrown");
            } catch (RestLiResponseException e) {
                result = e;
            }
            break;
        case GET_RESPONSE_EXPLICIT_NO_THROW:
            response = l == null ? future.getResponse() : future.getResponse(l, timeUnit);
            result = response.getError();
            break;
        case GET_RESPONSE_ENTITY:
        case GET_RESPONSE_ENTITY_EXPLICIT_THROW:
            try {
                entity = l == null ? future.getResponseEntity() : future.getResponseEntity(l, timeUnit);
                Assert.fail("Should have thrown");
            } catch (RestLiResponseException e) {
                result = e;
            }
            break;
        case GET_RESPONSE_ENTITY_EXPLICIT_NO_THROW:
            entity = l == null ? future.getResponseEntity() : future.getResponseEntity(l, timeUnit);
            break;
        default:
            throw new IllegalStateException();
    }
    return result;
}
Also used : RestException(com.linkedin.r2.message.rest.RestException) TimeUnit(java.util.concurrent.TimeUnit) ExecutionException(java.util.concurrent.ExecutionException)

Example 24 with RemoteInvocationException

use of com.linkedin.r2.RemoteInvocationException in project rest.li by linkedin.

the class ExceptionUtil method exceptionForThrowable.

public static RemoteInvocationException exceptionForThrowable(Throwable e, RestResponseDecoder<?> responseDecoder) {
    if (e instanceof RestException) {
        final RestException re = (RestException) e;
        final RestResponse response = re.getResponse();
        final ErrorResponse errorResponse;
        // decode the response body when HEADER_RESTLI_ERROR_RESPONSE header is set.
        try {
            errorResponse = getErrorResponse(response);
        } catch (RestLiDecodingException decodingException) {
            return new RemoteInvocationException(e.getMessage(), decodingException);
        }
        Response<?> decodedResponse = null;
        final String header = HeaderUtil.getErrorResponseHeaderValue(response.getHeaders());
        if (header == null) {
            // This is purely to handle case #2 commented above.
            try {
                decodedResponse = responseDecoder.decodeResponse(response);
            } catch (RestLiDecodingException decodingException) {
                return new RemoteInvocationException(e.getMessage(), e);
            }
        }
        return new RestLiResponseException(response, decodedResponse, errorResponse, e);
    }
    if (e instanceof RemoteInvocationException) {
        return (RemoteInvocationException) e;
    }
    return new RemoteInvocationException(e);
}
Also used : RestResponse(com.linkedin.r2.message.rest.RestResponse) RestException(com.linkedin.r2.message.rest.RestException) RestLiDecodingException(com.linkedin.restli.client.RestLiDecodingException) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) RemoteInvocationException(com.linkedin.r2.RemoteInvocationException) ErrorResponse(com.linkedin.restli.common.ErrorResponse)

Example 25 with RemoteInvocationException

use of com.linkedin.r2.RemoteInvocationException in project rest.li by linkedin.

the class ExceptionUtil method wrapThrowable.

static RemoteInvocationException wrapThrowable(Throwable e) {
    if (e instanceof RestLiResponseException) {
        final RestLiResponseException restliException = (RestLiResponseException) e;
        final ErrorResponse errorResponse;
        try {
            errorResponse = getErrorResponse(restliException.getResponse());
        } catch (RestLiDecodingException decodingException) {
            return new RemoteInvocationException(decodingException);
        }
        return new RestLiResponseException(restliException.getResponse(), restliException.getDecodedResponse(), errorResponse, restliException);
    }
    return new RemoteInvocationException(e);
}
Also used : RestLiDecodingException(com.linkedin.restli.client.RestLiDecodingException) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) RemoteInvocationException(com.linkedin.r2.RemoteInvocationException) ErrorResponse(com.linkedin.restli.common.ErrorResponse)

Aggregations

Test (org.testng.annotations.Test)32 RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)29 RestRequest (com.linkedin.r2.message.rest.RestRequest)13 RequestContext (com.linkedin.r2.message.RequestContext)10 HashMap (java.util.HashMap)10 ErrorResponse (com.linkedin.restli.common.ErrorResponse)8 URI (java.net.URI)8 FutureCallback (com.linkedin.common.callback.FutureCallback)7 EmptyRecord (com.linkedin.restli.common.EmptyRecord)7 Map (java.util.Map)7 ExecutionException (java.util.concurrent.ExecutionException)7 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)6 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)6 Callback (com.linkedin.common.callback.Callback)5 ByteString (com.linkedin.data.ByteString)5 RestException (com.linkedin.r2.message.rest.RestException)5 TransportClient (com.linkedin.r2.transport.common.bridge.client.TransportClient)5 TimeoutException (java.util.concurrent.TimeoutException)5 RestResponse (com.linkedin.r2.message.rest.RestResponse)4 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)4