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

The following examples show how to use org.springframework.util.ReflectionUtils#declaresException() . 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
Source File: RmiClientInterceptorUtils.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * 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
Source File: PersistenceExceptionTranslationInterceptor.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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
Source File: RmiClientInterceptorUtils.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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
Source File: PersistenceExceptionTranslationInterceptor.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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
Source File: RmiClientInterceptorUtils.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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
Source File: PersistenceExceptionTranslationInterceptor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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
Source File: RmiClientInterceptorUtils.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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
Source File: PersistenceExceptionTranslationInterceptor.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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
Source File: GenericMessageEndpointFactory.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private Exception adaptExceptionIfNecessary(MethodInvocation methodInvocation, ResourceException ex) {
	if (ReflectionUtils.declaresException(methodInvocation.getMethod(), ex.getClass())) {
		return ex;
	}
	else {
		return new InternalResourceException(ex);
	}
}
 
Example 10
Source File: GenericMessageEndpointFactory.java    From java-technology-stack with MIT License 5 votes vote down vote up
private Exception adaptExceptionIfNecessary(MethodInvocation methodInvocation, ResourceException ex) {
	if (ReflectionUtils.declaresException(methodInvocation.getMethod(), ex.getClass())) {
		return ex;
	}
	else {
		return new InternalResourceException(ex);
	}
}
 
Example 11
Source File: JndiRmiClientInterceptor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
Source File: JndiRmiClientInterceptor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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
Source File: RmiClientInterceptorUtils.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * 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
Source File: RmiClientInterceptorUtils.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * 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
Source File: RmiClientInterceptorUtils.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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
Source File: RmiClientInterceptorUtils.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * 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);
	}
}