Java Code Examples for org.springframework.util.ReflectionUtils#declaresException()

The following examples show how to use org.springframework.util.ReflectionUtils#declaresException() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Convert the given RemoteException that happened during remote access
 * to Spring's RemoteAccessException if the method signature does not
 * support RemoteException. Else, return the original RemoteException.
 * @param method the invoked method
 * @param ex the RemoteException that happened
 * @param isConnectFailure whether the given exception should be considered
 * a connect failure
 * @param serviceName the name of the service (for debugging purposes)
 * @return the exception to be thrown to the caller
 */
public static Exception convertRmiAccessException(
		Method method, RemoteException ex, boolean isConnectFailure, String serviceName) {

	if (logger.isDebugEnabled()) {
		logger.debug("Remote service [" + serviceName + "] threw exception", ex);
	}
	if (ReflectionUtils.declaresException(method, ex.getClass())) {
		return ex;
	}
	else {
		if (isConnectFailure) {
			return new RemoteConnectFailureException("Could not connect to remote service [" + serviceName + "]", ex);
		}
		else {
			return new RemoteAccessException("Could not access remote service [" + serviceName + "]", ex);
		}
	}
}
 
Example 2
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
	try {
		return mi.proceed();
	}
	catch (RuntimeException ex) {
		// Let it throw raw if the type of the exception is on the throws clause of the method.
		if (!this.alwaysTranslate && ReflectionUtils.declaresException(mi.getMethod(), ex.getClass())) {
			throw ex;
		}
		else {
			PersistenceExceptionTranslator translator = this.persistenceExceptionTranslator;
			if (translator == null) {
				Assert.state(this.beanFactory != null, "No PersistenceExceptionTranslator set");
				translator = detectPersistenceExceptionTranslators(this.beanFactory);
				this.persistenceExceptionTranslator = translator;
			}
			throw DataAccessUtils.translateIfNecessary(ex, translator);
		}
	}
}
 
Example 3
/**
 * Convert the given RemoteException that happened during remote access
 * to Spring's RemoteAccessException if the method signature does not
 * support RemoteException. Else, return the original RemoteException.
 * @param method the invoked method
 * @param ex the RemoteException that happened
 * @param isConnectFailure whether the given exception should be considered
 * a connect failure
 * @param serviceName the name of the service (for debugging purposes)
 * @return the exception to be thrown to the caller
 */
public static Exception convertRmiAccessException(
		Method method, RemoteException ex, boolean isConnectFailure, String serviceName) {

	if (logger.isDebugEnabled()) {
		logger.debug("Remote service [" + serviceName + "] threw exception", ex);
	}
	if (ReflectionUtils.declaresException(method, ex.getClass())) {
		return ex;
	}
	else {
		if (isConnectFailure) {
			return new RemoteConnectFailureException("Could not connect to remote service [" + serviceName + "]", ex);
		}
		else {
			return new RemoteAccessException("Could not access remote service [" + serviceName + "]", ex);
		}
	}
}
 
Example 4
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
	try {
		return mi.proceed();
	}
	catch (RuntimeException ex) {
		// Let it throw raw if the type of the exception is on the throws clause of the method.
		if (!this.alwaysTranslate && ReflectionUtils.declaresException(mi.getMethod(), ex.getClass())) {
			throw ex;
		}
		else {
			PersistenceExceptionTranslator translator = this.persistenceExceptionTranslator;
			if (translator == null) {
				Assert.state(this.beanFactory != null, "No PersistenceExceptionTranslator set");
				translator = detectPersistenceExceptionTranslators(this.beanFactory);
				this.persistenceExceptionTranslator = translator;
			}
			throw DataAccessUtils.translateIfNecessary(ex, translator);
		}
	}
}
 
Example 5
/**
 * Convert the given RemoteException that happened during remote access
 * to Spring's RemoteAccessException if the method signature does not
 * support RemoteException. Else, return the original RemoteException.
 * @param method the invoked method
 * @param ex the RemoteException that happened
 * @param isConnectFailure whether the given exception should be considered
 * a connect failure
 * @param serviceName the name of the service (for debugging purposes)
 * @return the exception to be thrown to the caller
 */
public static Exception convertRmiAccessException(
		Method method, RemoteException ex, boolean isConnectFailure, String serviceName) {

	if (logger.isDebugEnabled()) {
		logger.debug("Remote service [" + serviceName + "] threw exception", ex);
	}
	if (ReflectionUtils.declaresException(method, ex.getClass())) {
		return ex;
	}
	else {
		if (isConnectFailure) {
			return new RemoteConnectFailureException("Could not connect to remote service [" + serviceName + "]", ex);
		}
		else {
			return new RemoteAccessException("Could not access remote service [" + serviceName + "]", ex);
		}
	}
}
 
Example 6
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
	try {
		return mi.proceed();
	}
	catch (RuntimeException ex) {
		// Let it throw raw if the type of the exception is on the throws clause of the method.
		if (!this.alwaysTranslate && ReflectionUtils.declaresException(mi.getMethod(), ex.getClass())) {
			throw ex;
		}
		else {
			if (this.persistenceExceptionTranslator == null) {
				this.persistenceExceptionTranslator = detectPersistenceExceptionTranslators(this.beanFactory);
			}
			throw DataAccessUtils.translateIfNecessary(ex, this.persistenceExceptionTranslator);
		}
	}
}
 
Example 7
/**
 * Convert the given RemoteException that happened during remote access
 * to Spring's RemoteAccessException if the method signature does not
 * support RemoteException. Else, return the original RemoteException.
 * @param method the invoked method
 * @param ex the RemoteException that happened
 * @param isConnectFailure whether the given exception should be considered
 * a connect failure
 * @param serviceName the name of the service (for debugging purposes)
 * @return the exception to be thrown to the caller
 */
public static Exception convertRmiAccessException(
		Method method, RemoteException ex, boolean isConnectFailure, String serviceName) {

	if (logger.isDebugEnabled()) {
		logger.debug("Remote service [" + serviceName + "] threw exception", ex);
	}
	if (ReflectionUtils.declaresException(method, ex.getClass())) {
		return ex;
	}
	else {
		if (isConnectFailure) {
			return new RemoteConnectFailureException("Could not connect to remote service [" + serviceName + "]", ex);
		}
		else {
			return new RemoteAccessException("Could not access remote service [" + serviceName + "]", ex);
		}
	}
}
 
Example 8
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
	try {
		return mi.proceed();
	}
	catch (RuntimeException ex) {
		// Let it throw raw if the type of the exception is on the throws clause of the method.
		if (!this.alwaysTranslate && ReflectionUtils.declaresException(mi.getMethod(), ex.getClass())) {
			throw ex;
		}
		else {
			if (this.persistenceExceptionTranslator == null) {
				this.persistenceExceptionTranslator = detectPersistenceExceptionTranslators(this.beanFactory);
			}
			throw DataAccessUtils.translateIfNecessary(ex, this.persistenceExceptionTranslator);
		}
	}
}
 
Example 9
private Exception adaptExceptionIfNecessary(MethodInvocation methodInvocation, ResourceException ex) {
	if (ReflectionUtils.declaresException(methodInvocation.getMethod(), ex.getClass())) {
		return ex;
	}
	else {
		return new InternalResourceException(ex);
	}
}
 
Example 10
private Exception adaptExceptionIfNecessary(MethodInvocation methodInvocation, ResourceException ex) {
	if (ReflectionUtils.declaresException(methodInvocation.getMethod(), ex.getClass())) {
		return ex;
	}
	else {
		return new InternalResourceException(ex);
	}
}
 
Example 11
/**
 * Convert the given CORBA SystemException that happened during remote access
 * to Spring's RemoteAccessException if the method signature does not declare
 * RemoteException. Else, return the SystemException wrapped in a RemoteException.
 * @param method the invoked method
 * @param ex the RemoteException that happened
 * @return the exception to be thrown to the caller
 */
private Exception convertCorbaAccessException(SystemException ex, Method method) {
	if (ReflectionUtils.declaresException(method, RemoteException.class)) {
		// A traditional RMI service: wrap CORBA exceptions in standard RemoteExceptions.
		return new RemoteException("Failed to access CORBA service [" + getJndiName() + "]", ex);
	}
	else {
		if (isConnectFailure(ex)) {
			return new RemoteConnectFailureException("Could not connect to CORBA service [" + getJndiName() + "]", ex);
		}
		else {
			return new RemoteAccessException("Could not access CORBA service [" + getJndiName() + "]", ex);
		}
	}
}
 
Example 12
/**
 * Convert the given CORBA SystemException that happened during remote access
 * to Spring's RemoteAccessException if the method signature does not declare
 * RemoteException. Else, return the SystemException wrapped in a RemoteException.
 * @param method the invoked method
 * @param ex the RemoteException that happened
 * @return the exception to be thrown to the caller
 */
private Exception convertCorbaAccessException(SystemException ex, Method method) {
	if (ReflectionUtils.declaresException(method, RemoteException.class)) {
		// A traditional RMI service: wrap CORBA exceptions in standard RemoteExceptions.
		return new RemoteException("Failed to access CORBA service [" + getJndiName() + "]", ex);
	}
	else {
		if (isConnectFailure(ex)) {
			return new RemoteConnectFailureException("Could not connect to CORBA service [" + getJndiName() + "]", ex);
		}
		else {
			return new RemoteAccessException("Could not access CORBA service [" + getJndiName() + "]", ex);
		}
	}
}
 
Example 13
/**
 * Wrap the given arbitrary exception that happened during remote access
 * in either a RemoteException or a Spring RemoteAccessException (if the
 * method signature does not support RemoteException).
 * <p>Only call this for remote access exceptions, not for exceptions
 * thrown by the target service itself!
 * @param method the invoked method
 * @param ex the exception that happened, to be used as cause for the
 * RemoteAccessException or RemoteException
 * @param message the message for the RemoteAccessException respectively
 * RemoteException
 * @return the exception to be thrown to the caller
 */
public static Exception convertRmiAccessException(Method method, Throwable ex, String message) {
	if (logger.isDebugEnabled()) {
		logger.debug(message, ex);
	}
	if (ReflectionUtils.declaresException(method, RemoteException.class)) {
		return new RemoteException(message, ex);
	}
	else {
		return new RemoteAccessException(message, ex);
	}
}
 
Example 14
/**
 * Wrap the given arbitrary exception that happened during remote access
 * in either a RemoteException or a Spring RemoteAccessException (if the
 * method signature does not support RemoteException).
 * <p>Only call this for remote access exceptions, not for exceptions
 * thrown by the target service itself!
 * @param method the invoked method
 * @param ex the exception that happened, to be used as cause for the
 * RemoteAccessException or RemoteException
 * @param message the message for the RemoteAccessException respectively
 * RemoteException
 * @return the exception to be thrown to the caller
 */
public static Exception convertRmiAccessException(Method method, Throwable ex, String message) {
	if (logger.isDebugEnabled()) {
		logger.debug(message, ex);
	}
	if (ReflectionUtils.declaresException(method, RemoteException.class)) {
		return new RemoteException(message, ex);
	}
	else {
		return new RemoteAccessException(message, ex);
	}
}
 
Example 15
/**
 * Wrap the given arbitrary exception that happened during remote access
 * in either a RemoteException or a Spring RemoteAccessException (if the
 * method signature does not support RemoteException).
 * <p>Only call this for remote access exceptions, not for exceptions
 * thrown by the target service itself!
 * @param method the invoked method
 * @param ex the exception that happened, to be used as cause for the
 * RemoteAccessException or RemoteException
 * @param message the message for the RemoteAccessException respectively
 * RemoteException
 * @return the exception to be thrown to the caller
 */
public static Exception convertRmiAccessException(Method method, Throwable ex, String message) {
	if (logger.isDebugEnabled()) {
		logger.debug(message, ex);
	}
	if (ReflectionUtils.declaresException(method, RemoteException.class)) {
		return new RemoteException(message, ex);
	}
	else {
		return new RemoteAccessException(message, ex);
	}
}
 
Example 16
/**
 * Wrap the given arbitrary exception that happened during remote access
 * in either a RemoteException or a Spring RemoteAccessException (if the
 * method signature does not support RemoteException).
 * <p>Only call this for remote access exceptions, not for exceptions
 * thrown by the target service itself!
 * @param method the invoked method
 * @param ex the exception that happened, to be used as cause for the
 * RemoteAccessException or RemoteException
 * @param message the message for the RemoteAccessException respectively
 * RemoteException
 * @return the exception to be thrown to the caller
 */
public static Exception convertRmiAccessException(Method method, Throwable ex, String message) {
	if (logger.isDebugEnabled()) {
		logger.debug(message, ex);
	}
	if (ReflectionUtils.declaresException(method, RemoteException.class)) {
		return new RemoteException(message, ex);
	}
	else {
		return new RemoteAccessException(message, ex);
	}
}