use of java.lang.reflect.UndeclaredThrowableException in project hbase by apache.
the class RpcRetryingCallerImpl method translateException.
/**
* Get the good or the remote exception if any, throws the DoNotRetryIOException.
* @param t the throwable to analyze
* @return the translated exception, if it's not a DoNotRetryIOException
* @throws DoNotRetryIOException - if we find it, we throw it instead of translating.
*/
static Throwable translateException(Throwable t) throws DoNotRetryIOException {
if (t instanceof UndeclaredThrowableException) {
if (t.getCause() != null) {
t = t.getCause();
}
}
if (t instanceof RemoteException) {
t = ((RemoteException) t).unwrapRemoteException();
}
if (t instanceof LinkageError) {
throw new DoNotRetryIOException(t);
}
if (t instanceof ServiceException) {
ServiceException se = (ServiceException) t;
Throwable cause = se.getCause();
if (cause != null && cause instanceof DoNotRetryIOException) {
throw (DoNotRetryIOException) cause;
}
// Don't let ServiceException out; its rpc specific.
t = cause;
// t could be a RemoteException so go around again.
translateException(t);
} else if (t instanceof DoNotRetryIOException) {
throw (DoNotRetryIOException) t;
}
return t;
}
use of java.lang.reflect.UndeclaredThrowableException in project hive by apache.
the class UgiMetaStoreClientFactory method createProxy.
private IMetaStoreClient createProxy(final IMetaStoreClient delegate, final String user, final UserGroupInformation authenticatedUser) {
InvocationHandler handler = new AbstractInvocationHandler() {
@Override
protected Object handleInvocation(Object proxy, final Method method, final Object[] args) throws Throwable {
try {
if (!I_META_STORE_CLIENT_METHODS.contains(method) || authenticatedUser == null) {
return method.invoke(delegate, args);
}
try {
return authenticatedUser.doAs(new PrivilegedExceptionAction<Object>() {
@Override
public Object run() throws Exception {
return method.invoke(delegate, args);
}
});
} catch (IOException | InterruptedException e) {
throw new TException("PrivilegedExceptionAction failed as user '" + user + "'.", e);
}
} catch (UndeclaredThrowableException | InvocationTargetException e) {
throw e.getCause();
}
}
};
ClassLoader classLoader = IMetaStoreClient.class.getClassLoader();
Class<?>[] interfaces = new Class<?>[] { IMetaStoreClient.class };
Object proxy = Proxy.newProxyInstance(classLoader, interfaces, handler);
return IMetaStoreClient.class.cast(proxy);
}
use of java.lang.reflect.UndeclaredThrowableException in project hive by apache.
the class RetryingMetaStoreClient method invoke.
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Object ret = null;
int retriesMade = 0;
TException caughtException = null;
boolean allowReconnect = !method.isAnnotationPresent(NoReconnect.class);
boolean allowRetry = true;
Annotation[] directives = method.getDeclaredAnnotations();
if (directives != null) {
for (Annotation a : directives) {
if (a instanceof RetrySemantics.CannotRetry) {
allowRetry = false;
}
}
}
while (true) {
try {
reloginExpiringKeytabUser();
if (allowReconnect) {
if (retriesMade > 0 || hasConnectionLifeTimeReached(method)) {
base.reconnect();
lastConnectionTime = System.currentTimeMillis();
}
}
if (metaCallTimeMap == null) {
ret = method.invoke(base, args);
} else {
// need to capture the timing
long startTime = System.currentTimeMillis();
ret = method.invoke(base, args);
long timeTaken = System.currentTimeMillis() - startTime;
addMethodTime(method, timeTaken);
}
break;
} catch (UndeclaredThrowableException e) {
throw e.getCause();
} catch (InvocationTargetException e) {
Throwable t = e.getCause();
if (t instanceof TApplicationException) {
TApplicationException tae = (TApplicationException) t;
switch(tae.getType()) {
case TApplicationException.UNSUPPORTED_CLIENT_TYPE:
case TApplicationException.UNKNOWN_METHOD:
case TApplicationException.WRONG_METHOD_NAME:
case TApplicationException.INVALID_PROTOCOL:
throw t;
default:
// TODO: most other options are probably unrecoverable... throw?
caughtException = tae;
}
} else if ((t instanceof TProtocolException) || (t instanceof TTransportException)) {
// TODO: most protocol exceptions are probably unrecoverable... throw?
caughtException = (TException) t;
} else if ((t instanceof MetaException) && t.getMessage().matches("(?s).*(JDO[a-zA-Z]*|TProtocol|TTransport)Exception.*") && !t.getMessage().contains("java.sql.SQLIntegrityConstraintViolationException")) {
caughtException = (MetaException) t;
} else {
throw t;
}
} catch (MetaException e) {
if (e.getMessage().matches("(?s).*(IO|TTransport)Exception.*") && !e.getMessage().contains("java.sql.SQLIntegrityConstraintViolationException")) {
caughtException = e;
} else {
throw e;
}
}
if (retriesMade >= retryLimit || base.isLocalMetaStore() || !allowRetry) {
throw caughtException;
}
retriesMade++;
LOG.warn("MetaStoreClient lost connection. Attempting to reconnect (" + retriesMade + " of " + retryLimit + ") after " + retryDelaySeconds + "s. " + method.getName(), caughtException);
Thread.sleep(retryDelaySeconds * 1000);
}
return ret;
}
use of java.lang.reflect.UndeclaredThrowableException in project mybatis-3 by mybatis.
the class ExceptionUtilTest method shouldUnwrapThrowable.
@Test
public void shouldUnwrapThrowable() {
Exception exception = new Exception();
assertEquals(exception, ExceptionUtil.unwrapThrowable(exception));
assertEquals(exception, ExceptionUtil.unwrapThrowable(new InvocationTargetException(exception, "test")));
assertEquals(exception, ExceptionUtil.unwrapThrowable(new UndeclaredThrowableException(exception, "test")));
assertEquals(exception, ExceptionUtil.unwrapThrowable(new InvocationTargetException(new InvocationTargetException(exception, "test"), "test")));
assertEquals(exception, ExceptionUtil.unwrapThrowable(new InvocationTargetException(new UndeclaredThrowableException(exception, "test"), "test")));
}
use of java.lang.reflect.UndeclaredThrowableException in project robovm by robovm.
the class AbstractHttpClient method execute.
// non-javadoc, see interface HttpClient
public <T> T execute(final HttpHost target, final HttpRequest request, final ResponseHandler<? extends T> responseHandler, final HttpContext context) throws IOException, ClientProtocolException {
if (responseHandler == null) {
throw new IllegalArgumentException("Response handler must not be null.");
}
HttpResponse response = execute(target, request, context);
T result;
try {
result = responseHandler.handleResponse(response);
} catch (Throwable t) {
HttpEntity entity = response.getEntity();
if (entity != null) {
try {
entity.consumeContent();
} catch (Throwable t2) {
// Log this exception. The original exception is more
// important and will be thrown to the caller.
this.log.warn("Error consuming content after an exception.", t2);
}
}
if (t instanceof Error) {
throw (Error) t;
}
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
if (t instanceof IOException) {
throw (IOException) t;
}
throw new UndeclaredThrowableException(t);
}
// Handling the response was successful. Ensure that the content has
// been fully consumed.
HttpEntity entity = response.getEntity();
if (entity != null) {
// Let this exception go to the caller.
entity.consumeContent();
}
return result;
}
Aggregations