use of org.springframework.integration.handler.support.CollectionArgumentResolver in project spring-integration by spring-projects.
the class MessageHandlerMethodFactoryCreatingFactoryBean method buildArgumentResolvers.
private List<HandlerMethodArgumentResolver> buildArgumentResolvers(boolean listCapable) {
List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>();
resolvers.add(new PayloadExpressionArgumentResolver());
resolvers.add(new NullAwarePayloadArgumentResolver(this.argumentResolverMessageConverter));
resolvers.add(new PayloadsArgumentResolver());
if (listCapable) {
resolvers.add(new CollectionArgumentResolver(true));
}
resolvers.add(new MapArgumentResolver());
for (HandlerMethodArgumentResolver resolver : resolvers) {
if (resolver instanceof BeanFactoryAware) {
((BeanFactoryAware) resolver).setBeanFactory(this.beanFactory);
}
if (resolver instanceof InitializingBean) {
try {
((InitializingBean) resolver).afterPropertiesSet();
} catch (Exception ex) {
throw new BeanInitializationException("Cannot initialize 'HandlerMethodArgumentResolver'", ex);
}
}
}
return resolvers;
}
use of org.springframework.integration.handler.support.CollectionArgumentResolver in project spring-integration by spring-projects.
the class JdbcMessageStoreTests method testMessageGroupStreamNoConnectionPoolLeak.
@Test
@Transactional(propagation = Propagation.NEVER)
public void testMessageGroupStreamNoConnectionPoolLeak() throws NoSuchMethodException {
DataSourceConnectionFactory connFactory = new DataSourceConnectionFactory(this.dataSource);
PoolableConnectionFactory poolFactory = new PoolableConnectionFactory(connFactory, null);
GenericObjectPoolConfig<PoolableConnection> config = new GenericObjectPoolConfig<>();
config.setMaxTotal(2);
config.setMaxWaitMillis(500);
ObjectPool<PoolableConnection> connPool = new GenericObjectPool<>(poolFactory, config);
poolFactory.setPool(connPool);
PoolingDataSource<PoolableConnection> poolingDataSource = new PoolingDataSource<>(connPool);
JdbcMessageStore pooledMessageStore = new JdbcMessageStore(poolingDataSource);
CollectionArgumentResolver collectionArgumentResolver = new CollectionArgumentResolver(true);
collectionArgumentResolver.setBeanFactory(new DefaultListableBeanFactory());
Method methodForCollectionOfPayloads = getClass().getMethod("methodForCollectionOfPayloads", Collection.class);
MethodParameter methodParameter = SynthesizingMethodParameter.forExecutable(methodForCollectionOfPayloads, 0);
String groupId = "X";
Message<String> message = MessageBuilder.withPayload("test data").build();
pooledMessageStore.addMessagesToGroup(groupId, message);
// it failed with "Cannot get a connection, pool error Timeout waiting for idle object"
for (int i = 0; i < 3; i++) {
Object result = collectionArgumentResolver.resolveArgument(methodParameter, new GenericMessage<>(pooledMessageStore.getMessageGroup(groupId).getMessages()));
assertThat(result).isInstanceOf(Collection.class).asList().hasSize(1).contains("test data");
}
pooledMessageStore.removeMessageGroup(groupId);
}
Aggregations