Handle receive timeout in JmsInvokerClientInterceptor

JmsInvokerClientInterceptor defines a receiveTimeout field but does not
handle such timeout. This commit adds an additional callback that throws
an RemoteTimeoutException instead.

Sub-classes can override the onReceiveTimeout to throw a different
exception or return a fallback RemoteInvocationResult.

Issue: SPR-12731
This commit is contained in:
Stephane Nicoll
2015-02-19 16:51:41 +01:00
parent 90e6304b49
commit 8fcbdaee24
3 changed files with 96 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,10 +31,13 @@ import javax.jms.QueueSession;
import javax.jms.Session;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.jms.support.converter.MessageConversionException;
import org.springframework.jms.support.converter.SimpleMessageConverter;
import org.springframework.remoting.RemoteTimeoutException;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
@@ -43,9 +46,13 @@ import static org.mockito.BDDMockito.*;
/**
* @author Juergen Hoeller
* @author Stephane Nicoll
*/
public class JmsInvokerTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
private QueueConnectionFactory mockConnectionFactory;
private QueueConnection mockConnection;
@@ -78,6 +85,27 @@ public class JmsInvokerTests {
doTestJmsInvokerProxyFactoryBeanAndServiceExporter(true);
}
@Test
public void receiveTimeoutExpired() {
JmsInvokerProxyFactoryBean pfb = new JmsInvokerProxyFactoryBean() {
@Override
protected Message doExecuteRequest(Session session, Queue queue, Message requestMessage) throws JMSException {
return null; // faking no message received
}
};
pfb.setServiceInterface(ITestBean.class);
pfb.setConnectionFactory(this.mockConnectionFactory);
pfb.setQueue(this.mockQueue);
pfb.setReceiveTimeout(1500);
pfb.afterPropertiesSet();
ITestBean proxy = (ITestBean) pfb.getObject();
thrown.expect(RemoteTimeoutException.class);
thrown.expectMessage("1500 ms");
thrown.expectMessage("getAge");
proxy.getAge();
}
private void doTestJmsInvokerProxyFactoryBeanAndServiceExporter(boolean dynamicQueue) throws Throwable {
TestBean target = new TestBean("myname", 99);