use of org.springframework.beans.factory.BeanFactory in project spring-integration by spring-projects.
the class OutboundGatewayFunctionTests method testContainerWithTemporaryNoCorrelation.
@Test
public void testContainerWithTemporaryNoCorrelation() throws Exception {
BeanFactory beanFactory = mock(BeanFactory.class);
when(beanFactory.containsBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME)).thenReturn(true);
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.initialize();
when(beanFactory.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class)).thenReturn(scheduler);
final JmsOutboundGateway gateway = new JmsOutboundGateway();
gateway.setBeanFactory(beanFactory);
gateway.setConnectionFactory(getConnectionFactory());
gateway.setRequestDestination(requestQueue6);
gateway.setUseReplyContainer(true);
gateway.afterPropertiesSet();
gateway.start();
final AtomicReference<Object> reply = new AtomicReference<>();
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
ExecutorService exec = Executors.newSingleThreadExecutor();
exec.execute(() -> {
latch1.countDown();
try {
reply.set(gateway.handleRequestMessage(new GenericMessage<>("foo")));
} finally {
latch2.countDown();
}
});
assertTrue(latch1.await(10, TimeUnit.SECONDS));
JmsTemplate template = new JmsTemplate();
template.setConnectionFactory(getConnectionFactory());
template.setReceiveTimeout(10000);
javax.jms.Message request = template.receive(requestQueue6);
assertNotNull(request);
final javax.jms.Message jmsReply = request;
template.send(request.getJMSReplyTo(), session -> {
jmsReply.setJMSCorrelationID(jmsReply.getJMSMessageID());
return jmsReply;
});
assertTrue(latch2.await(10, TimeUnit.SECONDS));
assertNotNull(reply.get());
gateway.stop();
scheduler.destroy();
exec.shutdownNow();
}
use of org.springframework.beans.factory.BeanFactory in project spring-integration by spring-projects.
the class OutboundGatewayFunctionTests method testContainerWithDestNameNoCorrelation.
@Test
public void testContainerWithDestNameNoCorrelation() throws Exception {
BeanFactory beanFactory = mock(BeanFactory.class);
when(beanFactory.containsBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME)).thenReturn(true);
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.initialize();
when(beanFactory.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class)).thenReturn(scheduler);
final JmsOutboundGateway gateway = new JmsOutboundGateway();
gateway.setBeanFactory(beanFactory);
gateway.setConnectionFactory(getConnectionFactory());
gateway.setRequestDestination(requestQueue4);
gateway.setReplyDestinationName("reply4");
gateway.setUseReplyContainer(true);
gateway.afterPropertiesSet();
gateway.start();
final AtomicReference<Object> reply = new AtomicReference<>();
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
ExecutorService exec = Executors.newSingleThreadExecutor();
exec.execute(() -> {
latch1.countDown();
try {
reply.set(gateway.handleRequestMessage(new GenericMessage<>("foo")));
} finally {
latch2.countDown();
}
});
assertTrue(latch1.await(10, TimeUnit.SECONDS));
JmsTemplate template = new JmsTemplate();
template.setConnectionFactory(getConnectionFactory());
template.setReceiveTimeout(10000);
javax.jms.Message request = template.receive(requestQueue4);
assertNotNull(request);
final javax.jms.Message jmsReply = request;
template.send(request.getJMSReplyTo(), session -> {
jmsReply.setJMSCorrelationID(jmsReply.getJMSMessageID());
return jmsReply;
});
assertTrue(latch2.await(10, TimeUnit.SECONDS));
assertNotNull(reply.get());
gateway.stop();
scheduler.destroy();
exec.shutdownNow();
}
use of org.springframework.beans.factory.BeanFactory in project spring-integration by spring-projects.
the class OutboundGatewayFunctionTests method testContainerWithTemporary.
@Test
public void testContainerWithTemporary() throws Exception {
BeanFactory beanFactory = mock(BeanFactory.class);
when(beanFactory.containsBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME)).thenReturn(true);
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.initialize();
when(beanFactory.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class)).thenReturn(scheduler);
final JmsOutboundGateway gateway = new JmsOutboundGateway();
gateway.setBeanFactory(beanFactory);
gateway.setConnectionFactory(getConnectionFactory());
gateway.setRequestDestination(requestQueue5);
gateway.setCorrelationKey("JMSCorrelationID");
gateway.setUseReplyContainer(true);
gateway.setComponentName("testContainerWithTemporary.gateway");
gateway.afterPropertiesSet();
gateway.start();
final AtomicReference<Object> reply = new AtomicReference<>();
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
ExecutorService exec = Executors.newSingleThreadExecutor();
exec.execute(() -> {
latch1.countDown();
try {
reply.set(gateway.handleRequestMessage(new GenericMessage<>("foo")));
} finally {
latch2.countDown();
}
});
assertTrue(latch1.await(10, TimeUnit.SECONDS));
JmsTemplate template = new JmsTemplate();
template.setConnectionFactory(getConnectionFactory());
template.setReceiveTimeout(10000);
javax.jms.Message request = template.receive(requestQueue5);
assertNotNull(request);
final javax.jms.Message jmsReply = request;
template.send(request.getJMSReplyTo(), session -> jmsReply);
assertTrue(latch2.await(10, TimeUnit.SECONDS));
assertNotNull(reply.get());
gateway.stop();
scheduler.destroy();
exec.shutdownNow();
}
use of org.springframework.beans.factory.BeanFactory in project spring-integration by spring-projects.
the class OutboundGatewayConnectionTests method testContainerWithDestBrokenConnection.
// need a more reliable stop/start for AMQ
@Test
// need a more reliable stop/start for AMQ
@Ignore
public void testContainerWithDestBrokenConnection() throws Exception {
BeanFactory beanFactory = mock(BeanFactory.class);
when(beanFactory.containsBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME)).thenReturn(true);
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.initialize();
when(beanFactory.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class)).thenReturn(scheduler);
final JmsOutboundGateway gateway = new JmsOutboundGateway();
gateway.setBeanFactory(beanFactory);
BrokerService broker = new BrokerService();
broker.addConnector("tcp://localhost:61616?broker.persistent=false");
broker.start();
ActiveMQConnectionFactory amqConnectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
ConnectionFactory connectionFactory = new CachingConnectionFactory(amqConnectionFactory);
gateway.setConnectionFactory(connectionFactory);
gateway.setRequestDestination(requestQueue1);
gateway.setReplyDestination(replyQueue1);
gateway.setCorrelationKey("JMSCorrelationID");
gateway.setUseReplyContainer(true);
gateway.afterPropertiesSet();
gateway.start();
final AtomicReference<Object> reply = new AtomicReference<Object>();
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
ExecutorService exec = Executors.newSingleThreadExecutor();
exec.execute(() -> {
latch1.countDown();
try {
reply.set(gateway.handleRequestMessage(new GenericMessage<String>("foo")));
} finally {
latch2.countDown();
}
});
assertTrue(latch1.await(10, TimeUnit.SECONDS));
JmsTemplate template = new JmsTemplate();
template.setConnectionFactory(amqConnectionFactory);
template.setReceiveTimeout(5000);
javax.jms.Message request = template.receive(requestQueue1);
assertNotNull(request);
final javax.jms.Message jmsReply = request;
template.send(request.getJMSReplyTo(), (MessageCreator) session -> jmsReply);
assertTrue(latch2.await(10, TimeUnit.SECONDS));
assertNotNull(reply.get());
broker.stop();
broker = new BrokerService();
broker.addConnector("tcp://localhost:61616?broker.persistent=false");
broker.start();
final CountDownLatch latch3 = new CountDownLatch(1);
final CountDownLatch latch4 = new CountDownLatch(1);
exec.execute(() -> {
latch3.countDown();
try {
reply.set(gateway.handleRequestMessage(new GenericMessage<String>("foo")));
} finally {
latch4.countDown();
}
});
assertTrue(latch3.await(10, TimeUnit.SECONDS));
template = new JmsTemplate();
template.setConnectionFactory(amqConnectionFactory);
template.setReceiveTimeout(5000);
request = template.receive(requestQueue1);
assertNotNull(request);
final javax.jms.Message jmsReply2 = request;
template.send(request.getJMSReplyTo(), (MessageCreator) session -> jmsReply2);
assertTrue(latch4.await(10, TimeUnit.SECONDS));
assertNotNull(reply.get());
gateway.stop();
broker.stop();
scheduler.destroy();
exec.shutdownNow();
}
use of org.springframework.beans.factory.BeanFactory in project spring-integration by spring-projects.
the class AbstractXmppConnectionAwareEndpoint method onInit.
@Override
protected void onInit() {
super.onInit();
BeanFactory beanFactory = this.getBeanFactory();
if (this.xmppConnection == null && beanFactory != null) {
this.xmppConnection = beanFactory.getBean(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, XMPPConnection.class);
}
Assert.notNull(this.xmppConnection, "Failed to resolve XMPPConnection. " + "XMPPConnection must either be set explicitly via constructor argument " + "or implicitly by registering a bean with the name 'xmppConnection' and of type " + "'org.jivesoftware.smack.XMPPConnection' in the Application Context.");
this.initialized = true;
}
Aggregations