org.springframework.remoting.RemoteConnectFailureException Java Examples

The following examples show how to use org.springframework.remoting.RemoteConnectFailureException. 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: HttpInvokerClientInterceptor.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Convert the given HTTP invoker access exception to an appropriate
 * Spring {@link RemoteAccessException}.
 * @param ex the exception to convert
 * @return the RemoteAccessException to throw, or {@code null} to have the
 * original exception propagated to the caller
 */
@Nullable
protected RemoteAccessException convertHttpInvokerAccessException(Throwable ex) {
	if (ex instanceof ConnectException) {
		return new RemoteConnectFailureException(
				"Could not connect to HTTP invoker remote service at [" + getServiceUrl() + "]", ex);
	}

	if (ex instanceof ClassNotFoundException || ex instanceof NoClassDefFoundError ||
			ex instanceof InvalidClassException) {
		return new RemoteAccessException(
				"Could not deserialize result from HTTP invoker remote service [" + getServiceUrl() + "]", ex);
	}

	if (ex instanceof Exception) {
		return new RemoteAccessException(
				"Could not access HTTP invoker remote service at [" + getServiceUrl() + "]", ex);
	}

	// For any other Throwable, e.g. OutOfMemoryError: let it get propagated as-is.
	return null;
}
 
Example #3
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 #4
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 #5
Source File: HttpInvokerClientInterceptor.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Convert the given HTTP invoker access exception to an appropriate
 * Spring {@link RemoteAccessException}.
 * @param ex the exception to convert
 * @return the RemoteAccessException to throw, or {@code null} to have the
 * original exception propagated to the caller
 */
@Nullable
protected RemoteAccessException convertHttpInvokerAccessException(Throwable ex) {
	if (ex instanceof ConnectException) {
		return new RemoteConnectFailureException(
				"Could not connect to HTTP invoker remote service at [" + getServiceUrl() + "]", ex);
	}

	if (ex instanceof ClassNotFoundException || ex instanceof NoClassDefFoundError ||
			ex instanceof InvalidClassException) {
		return new RemoteAccessException(
				"Could not deserialize result from HTTP invoker remote service [" + getServiceUrl() + "]", ex);
	}

	if (ex instanceof Exception) {
		return new RemoteAccessException(
				"Could not access HTTP invoker remote service at [" + getServiceUrl() + "]", ex);
	}

	// For any other Throwable, e.g. OutOfMemoryError: let it get propagated as-is.
	return null;
}
 
Example #6
Source File: HttpInvokerClientInterceptor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Convert the given HTTP invoker access exception to an appropriate
 * Spring {@link RemoteAccessException}.
 * @param ex the exception to convert
 * @return the RemoteAccessException to throw, or {@code null} to have the
 * original exception propagated to the caller
 */
protected RemoteAccessException convertHttpInvokerAccessException(Throwable ex) {
	if (ex instanceof ConnectException) {
		return new RemoteConnectFailureException(
				"Could not connect to HTTP invoker remote service at [" + getServiceUrl() + "]", ex);
	}

	if (ex instanceof ClassNotFoundException || ex instanceof NoClassDefFoundError ||
			ex instanceof InvalidClassException) {
		return new RemoteAccessException(
				"Could not deserialize result from HTTP invoker remote service [" + getServiceUrl() + "]", ex);
	}

	if (ex instanceof Exception) {
		return new RemoteAccessException(
				"Could not access HTTP invoker remote service at [" + getServiceUrl() + "]", ex);
	}

	// For any other Throwable, e.g. OutOfMemoryError: let it get propagated as-is.
	return null;
}
 
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: HttpInvokerClientInterceptor.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the given HTTP invoker access exception to an appropriate
 * Spring RemoteAccessException.
 * @param ex the exception to convert
 * @return the RemoteAccessException to throw
 */
protected RemoteAccessException convertHttpInvokerAccessException(Throwable ex) {
	if (ex instanceof ConnectException) {
		return new RemoteConnectFailureException(
				"Could not connect to HTTP invoker remote service at [" + getServiceUrl() + "]", ex);
	}

	if (ex instanceof ClassNotFoundException || ex instanceof NoClassDefFoundError ||
			ex instanceof InvalidClassException) {
		return new RemoteAccessException(
				"Could not deserialize result from HTTP invoker remote service [" + getServiceUrl() + "]", ex);
	}

	return new RemoteAccessException(
				"Could not access HTTP invoker remote service at [" + getServiceUrl() + "]", ex);
}
 
Example #9
Source File: BurlapClientInterceptor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Convert the given Burlap access exception to an appropriate
 * Spring RemoteAccessException.
 * @param ex the exception to convert
 * @return the RemoteAccessException to throw
 */
protected RemoteAccessException convertBurlapAccessException(Throwable ex) {
	if (ex instanceof ConnectException) {
		return new RemoteConnectFailureException(
				"Cannot connect to Burlap remote service at [" + getServiceUrl() + "]", ex);
	}
	else {
		return new RemoteAccessException(
			"Cannot access Burlap remote service at [" + getServiceUrl() + "]", ex);
	}
}
 
Example #10
Source File: HessianClientInterceptor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Convert the given Hessian access exception to an appropriate
 * Spring RemoteAccessException.
 * @param ex the exception to convert
 * @return the RemoteAccessException to throw
 */
protected RemoteAccessException convertHessianAccessException(Throwable ex) {
	if (ex instanceof HessianConnectionException || ex instanceof ConnectException) {
		return new RemoteConnectFailureException(
				"Cannot connect to Hessian remote service at [" + getServiceUrl() + "]", ex);
	}
	else {
		return new RemoteAccessException(
			"Cannot access Hessian remote service at [" + getServiceUrl() + "]", ex);
	}
}
 
Example #11
Source File: RmiSupportTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
		Class<?> rmiExceptionClass, Class<?> springExceptionClass) throws Exception {

	CountingRmiProxyFactoryBean factory = new CountingRmiProxyFactoryBean();
	factory.setServiceInterface(IBusinessBean.class);
	factory.setServiceUrl("rmi://localhost:1090/test");
	factory.setRefreshStubOnConnectFailure(true);
	factory.afterPropertiesSet();
	assertTrue(factory.getObject() instanceof IBusinessBean);
	IBusinessBean proxy = (IBusinessBean) factory.getObject();
	assertFalse(proxy instanceof IRemoteBean);
	try {
		proxy.setName(rmiExceptionClass.getName());
		fail("Should have thrown " + rmiExceptionClass.getName());
	}
	catch (Exception ex) {
		if (springExceptionClass.isInstance(ex)) {
			// expected
		}
		else {
			throw ex;
		}
	}
	if (RemoteConnectFailureException.class.isAssignableFrom(springExceptionClass)) {
		assertEquals(2, factory.counter);
	}
	else {
		assertEquals(1, factory.counter);
	}
}
 
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: FactoryTimeoutConfigurationTest.java    From Ratel with Apache License 2.0 5 votes vote down vote up
@Test(expected = RemoteConnectFailureException.class)
public void shouldTimeoutBefore5sWithStandaloneClient() throws Exception {

    // given
    TimeoutService timeoutClient = getStandaloneTimeoutClient();

    // when
    timeoutClient.helloAfter5s();

    // then
    fail("Timeout should have caused exception");
}
 
Example #14
Source File: PropertiesTimeoutConfigurationTest.java    From Ratel with Apache License 2.0 5 votes vote down vote up
@Test(expected = RemoteConnectFailureException.class)
public void shouldTimeoutBefore5sWithInjectedClient() throws Exception {
    // when
    timeoutService.helloAfter5s();

    // then
    fail("Timeout should have caused exception");
}
 
Example #15
Source File: PropertiesTimeoutConfigurationTest.java    From Ratel with Apache License 2.0 5 votes vote down vote up
@Test(expected = RemoteConnectFailureException.class)
public void shouldTimeoutBefore5sWithStandaloneClient() throws Exception {

    // given
    TimeoutService timeoutClient = getStandaloneTimeoutClient();

    // when
    timeoutClient.helloAfter5s();

    // then
    fail("Timeout should have caused exception");
}
 
Example #16
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 #17
Source File: AnnotatedTimeoutConfigurationTest.java    From Ratel with Apache License 2.0 5 votes vote down vote up
@Test(expected = RemoteConnectFailureException.class)
public void shouldTimeoutBefore5sWithInjectedClient() throws Exception {
    // when
    timeoutService.helloAfter5s();

    // then
    fail("Timeout should have caused exception");
}
 
Example #18
Source File: BurlapClientInterceptor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Convert the given Burlap access exception to an appropriate
 * Spring RemoteAccessException.
 * @param ex the exception to convert
 * @return the RemoteAccessException to throw
 */
protected RemoteAccessException convertBurlapAccessException(Throwable ex) {
	if (ex instanceof ConnectException) {
		return new RemoteConnectFailureException(
				"Cannot connect to Burlap remote service at [" + getServiceUrl() + "]", ex);
	}
	else {
		return new RemoteAccessException(
			"Cannot access Burlap remote service at [" + getServiceUrl() + "]", ex);
	}
}
 
Example #19
Source File: HessianClientInterceptor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Convert the given Hessian access exception to an appropriate
 * Spring RemoteAccessException.
 * @param ex the exception to convert
 * @return the RemoteAccessException to throw
 */
protected RemoteAccessException convertHessianAccessException(Throwable ex) {
	if (ex instanceof HessianConnectionException || ex instanceof ConnectException) {
		return new RemoteConnectFailureException(
				"Cannot connect to Hessian remote service at [" + getServiceUrl() + "]", ex);
	}
	else {
		return new RemoteAccessException(
			"Cannot access Hessian remote service at [" + getServiceUrl() + "]", ex);
	}
}
 
Example #20
Source File: AbstractEntityService.java    From OpERP with MIT License 5 votes vote down vote up
@Override
public void notifyClientsForUpdate() {
	for (EM entityModel : entityModels) {
		try {
			entityModel.update();
		} catch (RemoteConnectFailureException e) {
			entityModels.remove(entityModel);
		}
	}
}
 
Example #21
Source File: HessianClientInterceptor.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Convert the given Hessian access exception to an appropriate
 * Spring RemoteAccessException.
 * @param ex the exception to convert
 * @return the RemoteAccessException to throw
 */
protected RemoteAccessException convertHessianAccessException(Throwable ex) {
	if (ex instanceof HessianConnectionException || ex instanceof ConnectException) {
		return new RemoteConnectFailureException(
				"Cannot connect to Hessian remote service at [" + getServiceUrl() + "]", ex);
	}
	else {
		return new RemoteAccessException(
			"Cannot access Hessian remote service at [" + getServiceUrl() + "]", ex);
	}
}
 
Example #22
Source File: RmiSupportTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
		Class<?> rmiExceptionClass, Class<?> springExceptionClass) throws Exception {

	CountingRmiProxyFactoryBean factory = new CountingRmiProxyFactoryBean();
	factory.setServiceInterface(IBusinessBean.class);
	factory.setServiceUrl("rmi://localhost:1090/test");
	factory.setRefreshStubOnConnectFailure(true);
	factory.afterPropertiesSet();
	assertTrue(factory.getObject() instanceof IBusinessBean);
	IBusinessBean proxy = (IBusinessBean) factory.getObject();
	assertFalse(proxy instanceof IRemoteBean);
	try {
		proxy.setName(rmiExceptionClass.getName());
		fail("Should have thrown " + rmiExceptionClass.getName());
	}
	catch (Exception ex) {
		if (springExceptionClass.isInstance(ex)) {
			// expected
		}
		else {
			throw ex;
		}
	}
	if (RemoteConnectFailureException.class.isAssignableFrom(springExceptionClass)) {
		assertEquals(2, factory.counter);
	}
	else {
		assertEquals(1, factory.counter);
	}
}
 
Example #23
Source File: RmiSupportTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
		Class<?> rmiExceptionClass, Class<?> springExceptionClass) throws Exception {

	CountingRmiProxyFactoryBean factory = new CountingRmiProxyFactoryBean();
	factory.setServiceInterface(IBusinessBean.class);
	factory.setServiceUrl("rmi://localhost:1090/test");
	factory.setRefreshStubOnConnectFailure(true);
	factory.afterPropertiesSet();
	assertTrue(factory.getObject() instanceof IBusinessBean);
	IBusinessBean proxy = (IBusinessBean) factory.getObject();
	assertFalse(proxy instanceof IRemoteBean);
	try {
		proxy.setName(rmiExceptionClass.getName());
		fail("Should have thrown " + rmiExceptionClass.getName());
	}
	catch (Exception ex) {
		if (springExceptionClass.isInstance(ex)) {
			// expected
		}
		else {
			throw ex;
		}
	}
	if (RemoteConnectFailureException.class.isAssignableFrom(springExceptionClass)) {
		assertEquals(2, factory.counter);
	}
	else {
		assertEquals(1, factory.counter);
	}
}
 
Example #24
Source File: HessianClientInterceptor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Convert the given Hessian access exception to an appropriate
 * Spring RemoteAccessException.
 * @param ex the exception to convert
 * @return the RemoteAccessException to throw
 */
protected RemoteAccessException convertHessianAccessException(Throwable ex) {
	if (ex instanceof HessianConnectionException || ex instanceof ConnectException) {
		return new RemoteConnectFailureException(
				"Cannot connect to Hessian remote service at [" + getServiceUrl() + "]", ex);
	}
	else {
		return new RemoteAccessException(
			"Cannot access Hessian remote service at [" + getServiceUrl() + "]", ex);
	}
}
 
Example #25
Source File: RmiSupportTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void rmiProxyFactoryBeanWithBusinessInterfaceAndUnknownHostExceptionAndRefresh() throws Exception {
	doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
			UnknownHostException.class, RemoteConnectFailureException.class);
}
 
Example #26
Source File: RmiSupportTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
public void rmiProxyFactoryBeanWithBusinessInterfaceAndConnectExceptionAndRefresh() throws Exception {
	doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
			ConnectException.class, RemoteConnectFailureException.class);
}
 
Example #27
Source File: RmiSupportTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
public void rmiProxyFactoryBeanWithBusinessInterfaceAndConnectIOExceptionAndRefresh() throws Exception {
	doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
			ConnectIOException.class, RemoteConnectFailureException.class);
}
 
Example #28
Source File: RmiSupportTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
public void rmiProxyFactoryBeanWithBusinessInterfaceAndUnknownHostExceptionAndRefresh() throws Exception {
	doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
			UnknownHostException.class, RemoteConnectFailureException.class);
}
 
Example #29
Source File: RmiSupportTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
public void rmiProxyFactoryBeanWithBusinessInterfaceAndNoSuchObjectExceptionAndRefresh() throws Exception {
	doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
			NoSuchObjectException.class, RemoteConnectFailureException.class);
}
 
Example #30
Source File: RmiSupportTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
public void rmiProxyFactoryBeanWithBusinessInterfaceAndStubNotFoundExceptionAndRefresh() throws Exception {
	doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
			StubNotFoundException.class, RemoteConnectFailureException.class);
}