org.springframework.jms.config.MethodJmsListenerEndpoint Java Examples

The following examples show how to use org.springframework.jms.config.MethodJmsListenerEndpoint. 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: AbstractJmsAnnotationDrivenTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Test for {@link JmsListenerRepeatableBean} and {@link JmsListenersBean} that validates that the
 * {@code @JmsListener} annotation is repeatable and generate one specific container per annotation.
 */
public void testJmsListenerRepeatable(ApplicationContext context) {
	JmsListenerContainerTestFactory simpleFactory =
			context.getBean("jmsListenerContainerFactory", JmsListenerContainerTestFactory.class);
	assertEquals(2, simpleFactory.getListenerContainers().size());

	MethodJmsListenerEndpoint first = (MethodJmsListenerEndpoint)
			simpleFactory.getListenerContainer("first").getEndpoint();
	assertEquals("first", first.getId());
	assertEquals("myQueue", first.getDestination());
	assertEquals(null, first.getConcurrency());

	MethodJmsListenerEndpoint second = (MethodJmsListenerEndpoint)
			simpleFactory.getListenerContainer("second").getEndpoint();
	assertEquals("second", second.getId());
	assertEquals("anotherQueue", second.getDestination());
	assertEquals("2-10", second.getConcurrency());
}
 
Example #2
Source File: AbstractJmsAnnotationDrivenTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Test for {@link FullBean} discovery. In this case, no default is set because
 * all endpoints provide a default registry. This shows that the default factory
 * is only retrieved if it needs to be.
 */
public void testFullConfiguration(ApplicationContext context) {
	JmsListenerContainerTestFactory simpleFactory =
			context.getBean("simpleFactory", JmsListenerContainerTestFactory.class);
	assertEquals(1, simpleFactory.getListenerContainers().size());
	MethodJmsListenerEndpoint endpoint = (MethodJmsListenerEndpoint)
			simpleFactory.getListenerContainers().get(0).getEndpoint();
	assertEquals("listener1", endpoint.getId());
	assertEquals("queueIn", endpoint.getDestination());
	assertEquals("mySelector", endpoint.getSelector());
	assertEquals("mySubscription", endpoint.getSubscription());
	assertEquals("1-10", endpoint.getConcurrency());

	Method m = ReflectionUtils.findMethod(endpoint.getClass(), "getDefaultResponseDestination");
	ReflectionUtils.makeAccessible(m);
	Object destination = ReflectionUtils.invokeMethod(m, endpoint);
	assertEquals("queueOut", destination);
}
 
Example #3
Source File: EnableJmsTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void composedJmsListeners() {
	try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
		EnableJmsDefaultContainerFactoryConfig.class, ComposedJmsListenersBean.class)) {
		JmsListenerContainerTestFactory simpleFactory = context.getBean("jmsListenerContainerFactory",
			JmsListenerContainerTestFactory.class);
		assertEquals(2, simpleFactory.getListenerContainers().size());

		MethodJmsListenerEndpoint first = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainer(
			"first").getEndpoint();
		assertEquals("first", first.getId());
		assertEquals("orderQueue", first.getDestination());
		assertNull(first.getConcurrency());

		MethodJmsListenerEndpoint second = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainer(
			"second").getEndpoint();
		assertEquals("second", second.getId());
		assertEquals("billingQueue", second.getDestination());
		assertEquals("2-10", second.getConcurrency());
	}
}
 
Example #4
Source File: AbstractJmsAnnotationDrivenTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Test for {@link JmsListenerRepeatableBean} and {@link JmsListenersBean} that validates that the
 * {@code @JmsListener} annotation is repeatable and generate one specific container per annotation.
 */
public void testJmsListenerRepeatable(ApplicationContext context) {
	JmsListenerContainerTestFactory simpleFactory =
			context.getBean("jmsListenerContainerFactory", JmsListenerContainerTestFactory.class);
	assertEquals(2, simpleFactory.getListenerContainers().size());

	MethodJmsListenerEndpoint first = (MethodJmsListenerEndpoint)
			simpleFactory.getListenerContainer("first").getEndpoint();
	assertEquals("first", first.getId());
	assertEquals("myQueue", first.getDestination());
	assertEquals(null, first.getConcurrency());

	MethodJmsListenerEndpoint second = (MethodJmsListenerEndpoint)
			simpleFactory.getListenerContainer("second").getEndpoint();
	assertEquals("second", second.getId());
	assertEquals("anotherQueue", second.getDestination());
	assertEquals("2-10", second.getConcurrency());
}
 
Example #5
Source File: JmsListenerAnnotationBeanPostProcessorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void metaAnnotationIsDiscovered() throws Exception {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			Config.class, MetaAnnotationTestBean.class);

	try {
		JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
		assertEquals("one container should have been registered", 1, factory.getListenerContainers().size());

		JmsListenerEndpoint endpoint = factory.getListenerContainers().get(0).getEndpoint();
		assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass());
		MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
		assertEquals(MetaAnnotationTestBean.class, methodEndpoint.getBean().getClass());
		assertEquals(MetaAnnotationTestBean.class.getMethod("handleIt", String.class),
				methodEndpoint.getMethod());
		assertEquals(MetaAnnotationTestBean.class.getMethod("handleIt", String.class),
				methodEndpoint.getMostSpecificMethod());
		assertEquals("metaTestQueue", ((AbstractJmsListenerEndpoint) endpoint).getDestination());
	}
	finally {
		context.close();
	}
}
 
Example #6
Source File: JmsListenerAnnotationBeanPostProcessorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void simpleMessageListener() throws Exception {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			Config.class, SimpleMessageListenerTestBean.class);

	JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
	assertEquals("One container should have been registered", 1, factory.getListenerContainers().size());
	MessageListenerTestContainer container = factory.getListenerContainers().get(0);

	JmsListenerEndpoint endpoint = container.getEndpoint();
	assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass());
	MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
	assertEquals(SimpleMessageListenerTestBean.class, methodEndpoint.getBean().getClass());
	assertEquals(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class),
			methodEndpoint.getMethod());
	assertEquals(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class),
			methodEndpoint.getMostSpecificMethod());

	SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer();
	methodEndpoint.setupListenerContainer(listenerContainer);
	assertNotNull(listenerContainer.getMessageListener());

	assertTrue("Should have been started " + container, container.isStarted());
	context.close(); // Close and stop the listeners
	assertTrue("Should have been stopped " + container, container.isStopped());
}
 
Example #7
Source File: JmsListenerAnnotationBeanPostProcessorTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void simpleMessageListener() throws Exception {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			Config.class, SimpleMessageListenerTestBean.class);

	JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
	assertEquals("One container should have been registered", 1, factory.getListenerContainers().size());
	MessageListenerTestContainer container = factory.getListenerContainers().get(0);

	JmsListenerEndpoint endpoint = container.getEndpoint();
	assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass());
	MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
	assertEquals(SimpleMessageListenerTestBean.class, methodEndpoint.getBean().getClass());
	assertEquals(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMethod());
	assertEquals(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMostSpecificMethod());

	SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer();
	methodEndpoint.setupListenerContainer(listenerContainer);
	assertNotNull(listenerContainer.getMessageListener());

	assertTrue("Should have been started " + container, container.isStarted());
	context.close(); // Close and stop the listeners
	assertTrue("Should have been stopped " + container, container.isStopped());
}
 
Example #8
Source File: JmsListenerAnnotationBeanPostProcessorTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void metaAnnotationIsDiscovered() throws Exception {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			Config.class, MetaAnnotationTestBean.class);

	try {
		JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
		assertEquals("one container should have been registered", 1, factory.getListenerContainers().size());

		JmsListenerEndpoint endpoint = factory.getListenerContainers().get(0).getEndpoint();
		assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass());
		MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
		assertEquals(MetaAnnotationTestBean.class, methodEndpoint.getBean().getClass());
		assertEquals(MetaAnnotationTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMethod());
		assertEquals(MetaAnnotationTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMostSpecificMethod());
		assertEquals("metaTestQueue", ((AbstractJmsListenerEndpoint) endpoint).getDestination());
	}
	finally {
		context.close();
	}
}
 
Example #9
Source File: JmsListenerAnnotationBeanPostProcessorTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void sendToAnnotationFoundOnProxy() throws Exception {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			Config.class, ProxyConfig.class, ProxyTestBean.class);
	try {
		JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
		assertEquals("one container should have been registered", 1, factory.getListenerContainers().size());

		JmsListenerEndpoint endpoint = factory.getListenerContainers().get(0).getEndpoint();
		assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass());
		MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
		assertTrue(AopUtils.isJdkDynamicProxy(methodEndpoint.getBean()));
		assertTrue(methodEndpoint.getBean() instanceof SimpleService);
		assertEquals(SimpleService.class.getMethod("handleIt", String.class), methodEndpoint.getMethod());
		assertEquals(ProxyTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMostSpecificMethod());

		Method m = ReflectionUtils.findMethod(endpoint.getClass(), "getDefaultResponseDestination");
		ReflectionUtils.makeAccessible(m);
		Object destination = ReflectionUtils.invokeMethod(m, endpoint);
		assertEquals("SendTo annotation not found on proxy", "foobar", destination);
	}
	finally {
		context.close();
	}
}
 
Example #10
Source File: AbstractJmsAnnotationDrivenTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Test for {@link FullBean} discovery. In this case, no default is set because
 * all endpoints provide a default registry. This shows that the default factory
 * is only retrieved if it needs to be.
 */
public void testFullConfiguration(ApplicationContext context) {
	JmsListenerContainerTestFactory simpleFactory =
			context.getBean("simpleFactory", JmsListenerContainerTestFactory.class);
	assertEquals(1, simpleFactory.getListenerContainers().size());
	MethodJmsListenerEndpoint endpoint = (MethodJmsListenerEndpoint)
			simpleFactory.getListenerContainers().get(0).getEndpoint();
	assertEquals("listener1", endpoint.getId());
	assertEquals("queueIn", endpoint.getDestination());
	assertEquals("mySelector", endpoint.getSelector());
	assertEquals("mySubscription", endpoint.getSubscription());
	assertEquals("1-10", endpoint.getConcurrency());

	Method m = ReflectionUtils.findMethod(endpoint.getClass(), "getDefaultResponseDestination");
	ReflectionUtils.makeAccessible(m);
	Object destination = ReflectionUtils.invokeMethod(m, endpoint);
	assertEquals("queueOut", destination);
}
 
Example #11
Source File: EnableJmsTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void composedJmsListeners() {
	try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
		EnableJmsDefaultContainerFactoryConfig.class, ComposedJmsListenersBean.class)) {
		JmsListenerContainerTestFactory simpleFactory = context.getBean("jmsListenerContainerFactory",
			JmsListenerContainerTestFactory.class);
		assertEquals(2, simpleFactory.getListenerContainers().size());

		MethodJmsListenerEndpoint first = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainer(
			"first").getEndpoint();
		assertEquals("first", first.getId());
		assertEquals("orderQueue", first.getDestination());
		assertNull(first.getConcurrency());

		MethodJmsListenerEndpoint second = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainer(
			"second").getEndpoint();
		assertEquals("second", second.getId());
		assertEquals("billingQueue", second.getDestination());
		assertEquals("2-10", second.getConcurrency());
	}
}
 
Example #12
Source File: AbstractJmsAnnotationDrivenTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Test for {@link FullBean} discovery. In this case, no default is set because
 * all endpoints provide a default registry. This shows that the default factory
 * is only retrieved if it needs to be.
 */
public void testFullConfiguration(ApplicationContext context) {
	JmsListenerContainerTestFactory simpleFactory =
			context.getBean("simpleFactory", JmsListenerContainerTestFactory.class);
	assertEquals(1, simpleFactory.getListenerContainers().size());
	MethodJmsListenerEndpoint endpoint = (MethodJmsListenerEndpoint)
			simpleFactory.getListenerContainers().get(0).getEndpoint();
	assertEquals("listener1", endpoint.getId());
	assertEquals("queueIn", endpoint.getDestination());
	assertEquals("mySelector", endpoint.getSelector());
	assertEquals("mySubscription", endpoint.getSubscription());
	assertEquals("1-10", endpoint.getConcurrency());

	Method m = ReflectionUtils.findMethod(endpoint.getClass(), "getDefaultResponseDestination");
	ReflectionUtils.makeAccessible(m);
	Object destination = ReflectionUtils.invokeMethod(m, endpoint);
	assertEquals("queueOut", destination);
}
 
Example #13
Source File: JmsListenerAnnotationBeanPostProcessorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void metaAnnotationIsDiscovered() throws Exception {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			Config.class, MetaAnnotationTestBean.class);

	try {
		JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
		assertEquals("one container should have been registered", 1, factory.getListenerContainers().size());

		JmsListenerEndpoint endpoint = factory.getListenerContainers().get(0).getEndpoint();
		assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass());
		MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
		assertEquals(MetaAnnotationTestBean.class, methodEndpoint.getBean().getClass());
		assertEquals(MetaAnnotationTestBean.class.getMethod("handleIt", String.class),
				methodEndpoint.getMethod());
		assertEquals(MetaAnnotationTestBean.class.getMethod("handleIt", String.class),
				methodEndpoint.getMostSpecificMethod());
		assertEquals("metaTestQueue", ((AbstractJmsListenerEndpoint) endpoint).getDestination());
	}
	finally {
		context.close();
	}
}
 
Example #14
Source File: JmsListenerAnnotationBeanPostProcessorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void simpleMessageListener() throws Exception {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			Config.class, SimpleMessageListenerTestBean.class);

	JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
	assertEquals("One container should have been registered", 1, factory.getListenerContainers().size());
	MessageListenerTestContainer container = factory.getListenerContainers().get(0);

	JmsListenerEndpoint endpoint = container.getEndpoint();
	assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass());
	MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
	assertEquals(SimpleMessageListenerTestBean.class, methodEndpoint.getBean().getClass());
	assertEquals(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class),
			methodEndpoint.getMethod());
	assertEquals(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class),
			methodEndpoint.getMostSpecificMethod());

	SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer();
	methodEndpoint.setupListenerContainer(listenerContainer);
	assertNotNull(listenerContainer.getMessageListener());

	assertTrue("Should have been started " + container, container.isStarted());
	context.close(); // Close and stop the listeners
	assertTrue("Should have been stopped " + container, container.isStopped());
}
 
Example #15
Source File: AbstractJmsAnnotationDrivenTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Test for {@link JmsListenerRepeatableBean} and {@link JmsListenersBean} that validates that the
 * {@code @JmsListener} annotation is repeatable and generate one specific container per annotation.
 */
public void testJmsListenerRepeatable(ApplicationContext context) {
	JmsListenerContainerTestFactory simpleFactory =
			context.getBean("jmsListenerContainerFactory", JmsListenerContainerTestFactory.class);
	assertEquals(2, simpleFactory.getListenerContainers().size());

	MethodJmsListenerEndpoint first = (MethodJmsListenerEndpoint)
			simpleFactory.getListenerContainer("first").getEndpoint();
	assertEquals("first", first.getId());
	assertEquals("myQueue", first.getDestination());
	assertEquals(null, first.getConcurrency());

	MethodJmsListenerEndpoint second = (MethodJmsListenerEndpoint)
			simpleFactory.getListenerContainer("second").getEndpoint();
	assertEquals("second", second.getId());
	assertEquals("anotherQueue", second.getDestination());
	assertEquals("2-10", second.getConcurrency());
}
 
Example #16
Source File: JmsListenerAnnotationBeanPostProcessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void sendToAnnotationFoundOnInterfaceProxy() throws Exception {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			Config.class, ProxyConfig.class, InterfaceProxyTestBean.class);
	try {
		JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
		assertEquals("one container should have been registered", 1, factory.getListenerContainers().size());

		JmsListenerEndpoint endpoint = factory.getListenerContainers().get(0).getEndpoint();
		assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass());
		MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
		assertTrue(AopUtils.isJdkDynamicProxy(methodEndpoint.getBean()));
		assertTrue(methodEndpoint.getBean() instanceof SimpleService);
		assertEquals(SimpleService.class.getMethod("handleIt", String.class, String.class),
				methodEndpoint.getMethod());
		assertEquals(InterfaceProxyTestBean.class.getMethod("handleIt", String.class, String.class),
				methodEndpoint.getMostSpecificMethod());

		Method method = ReflectionUtils.findMethod(endpoint.getClass(), "getDefaultResponseDestination");
		ReflectionUtils.makeAccessible(method);
		Object destination = ReflectionUtils.invokeMethod(method, endpoint);
		assertEquals("SendTo annotation not found on proxy", "foobar", destination);
	}
	finally {
		context.close();
	}
}
 
Example #17
Source File: AbstractJmsAnnotationDrivenTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Test for {@link ValidationBean} with a validator ({@link TestValidator}) specified
 * in a custom {@link org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory}.
 *
 * The test should throw a {@link org.springframework.jms.listener.adapter.ListenerExecutionFailedException}
 */
public void testJmsHandlerMethodFactoryConfiguration(ApplicationContext context) throws JMSException {
	JmsListenerContainerTestFactory simpleFactory =
			context.getBean("defaultFactory", JmsListenerContainerTestFactory.class);
	assertEquals(1, simpleFactory.getListenerContainers().size());
	MethodJmsListenerEndpoint endpoint = (MethodJmsListenerEndpoint)
			simpleFactory.getListenerContainers().get(0).getEndpoint();

	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	endpoint.setupListenerContainer(container);
	MessagingMessageListenerAdapter listener = (MessagingMessageListenerAdapter) container.getMessageListener();
	listener.onMessage(new StubTextMessage("failValidation"), mock(Session.class));
}
 
Example #18
Source File: JmsListenerAnnotationBeanPostProcessor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Process the given {@link JmsListener} annotation on the given method,
 * registering a corresponding endpoint for the given bean instance.
 * @param jmsListener the annotation to process
 * @param mostSpecificMethod the annotated method
 * @param bean the instance to invoke the method on
 * @see #createMethodJmsListenerEndpoint()
 * @see JmsListenerEndpointRegistrar#registerEndpoint
 */
protected void processJmsListener(JmsListener jmsListener, Method mostSpecificMethod, Object bean) {
	Method invocableMethod = MethodIntrospector.selectInvocableMethod(mostSpecificMethod, bean.getClass());

	MethodJmsListenerEndpoint endpoint = createMethodJmsListenerEndpoint();
	endpoint.setBean(bean);
	endpoint.setMethod(invocableMethod);
	endpoint.setMostSpecificMethod(mostSpecificMethod);
	endpoint.setMessageHandlerMethodFactory(this.messageHandlerMethodFactory);
	endpoint.setBeanFactory(this.beanFactory);
	endpoint.setId(getEndpointId(jmsListener));
	endpoint.setDestination(resolve(jmsListener.destination()));
	if (StringUtils.hasText(jmsListener.selector())) {
		endpoint.setSelector(resolve(jmsListener.selector()));
	}
	if (StringUtils.hasText(jmsListener.subscription())) {
		endpoint.setSubscription(resolve(jmsListener.subscription()));
	}
	if (StringUtils.hasText(jmsListener.concurrency())) {
		endpoint.setConcurrency(resolve(jmsListener.concurrency()));
	}

	JmsListenerContainerFactory<?> factory = null;
	String containerFactoryBeanName = resolve(jmsListener.containerFactory());
	if (StringUtils.hasText(containerFactoryBeanName)) {
		Assert.state(this.beanFactory != null, "BeanFactory must be set to obtain container factory by bean name");
		try {
			factory = this.beanFactory.getBean(containerFactoryBeanName, JmsListenerContainerFactory.class);
		}
		catch (NoSuchBeanDefinitionException ex) {
			throw new BeanInitializationException("Could not register JMS listener endpoint on [" +
					mostSpecificMethod + "], no " + JmsListenerContainerFactory.class.getSimpleName() +
					" with id '" + containerFactoryBeanName + "' was found in the application context", ex);
		}
	}

	this.registrar.registerEndpoint(endpoint, factory);
}
 
Example #19
Source File: AbstractJmsAnnotationDrivenTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Test for {@link ValidationBean} with a validator ({@link TestValidator}) specified
 * in a custom {@link org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory}.
 *
 * The test should throw a {@link org.springframework.jms.listener.adapter.ListenerExecutionFailedException}
 */
public void testJmsHandlerMethodFactoryConfiguration(ApplicationContext context) throws JMSException {
	JmsListenerContainerTestFactory simpleFactory =
			context.getBean("defaultFactory", JmsListenerContainerTestFactory.class);
	assertEquals(1, simpleFactory.getListenerContainers().size());
	MethodJmsListenerEndpoint endpoint = (MethodJmsListenerEndpoint)
			simpleFactory.getListenerContainers().get(0).getEndpoint();

	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	endpoint.setupListenerContainer(container);
	MessagingMessageListenerAdapter listener = (MessagingMessageListenerAdapter) container.getMessageListener();
	listener.onMessage(new StubTextMessage("failValidation"), mock(Session.class));
}
 
Example #20
Source File: JmsListenerAnnotationBeanPostProcessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void sendToAnnotationFoundOnCglibProxy() throws Exception {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			Config.class, ProxyConfig.class, ClassProxyTestBean.class);
	try {
		JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
		assertEquals("one container should have been registered", 1, factory.getListenerContainers().size());

		JmsListenerEndpoint endpoint = factory.getListenerContainers().get(0).getEndpoint();
		assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass());
		MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
		assertTrue(AopUtils.isCglibProxy(methodEndpoint.getBean()));
		assertTrue(methodEndpoint.getBean() instanceof ClassProxyTestBean);
		assertEquals(ClassProxyTestBean.class.getMethod("handleIt", String.class, String.class),
				methodEndpoint.getMethod());
		assertEquals(ClassProxyTestBean.class.getMethod("handleIt", String.class, String.class),
				methodEndpoint.getMostSpecificMethod());

		Method method = ReflectionUtils.findMethod(endpoint.getClass(), "getDefaultResponseDestination");
		ReflectionUtils.makeAccessible(method);
		Object destination = ReflectionUtils.invokeMethod(method, endpoint);
		assertEquals("SendTo annotation not found on proxy", "foobar", destination);
	}
	finally {
		context.close();
	}
}
 
Example #21
Source File: JmsListenerAnnotationBeanPostProcessor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Process the given {@link JmsListener} annotation on the given method,
 * registering a corresponding endpoint for the given bean instance.
 * @param jmsListener the annotation to process
 * @param mostSpecificMethod the annotated method
 * @param bean the instance to invoke the method on
 * @see #createMethodJmsListenerEndpoint()
 * @see JmsListenerEndpointRegistrar#registerEndpoint
 */
protected void processJmsListener(JmsListener jmsListener, Method mostSpecificMethod, Object bean) {
	Method invocableMethod = AopUtils.selectInvocableMethod(mostSpecificMethod, bean.getClass());

	MethodJmsListenerEndpoint endpoint = createMethodJmsListenerEndpoint();
	endpoint.setBean(bean);
	endpoint.setMethod(invocableMethod);
	endpoint.setMostSpecificMethod(mostSpecificMethod);
	endpoint.setMessageHandlerMethodFactory(this.messageHandlerMethodFactory);
	endpoint.setEmbeddedValueResolver(this.embeddedValueResolver);
	endpoint.setBeanFactory(this.beanFactory);
	endpoint.setId(getEndpointId(jmsListener));
	endpoint.setDestination(resolve(jmsListener.destination()));
	if (StringUtils.hasText(jmsListener.selector())) {
		endpoint.setSelector(resolve(jmsListener.selector()));
	}
	if (StringUtils.hasText(jmsListener.subscription())) {
		endpoint.setSubscription(resolve(jmsListener.subscription()));
	}
	if (StringUtils.hasText(jmsListener.concurrency())) {
		endpoint.setConcurrency(resolve(jmsListener.concurrency()));
	}

	JmsListenerContainerFactory<?> factory = null;
	String containerFactoryBeanName = resolve(jmsListener.containerFactory());
	if (StringUtils.hasText(containerFactoryBeanName)) {
		Assert.state(this.beanFactory != null, "BeanFactory must be set to obtain container factory by bean name");
		try {
			factory = this.beanFactory.getBean(containerFactoryBeanName, JmsListenerContainerFactory.class);
		}
		catch (NoSuchBeanDefinitionException ex) {
			throw new BeanInitializationException("Could not register JMS listener endpoint on [" +
					mostSpecificMethod + "], no " + JmsListenerContainerFactory.class.getSimpleName() +
					" with id '" + containerFactoryBeanName + "' was found in the application context", ex);
		}
	}

	this.registrar.registerEndpoint(endpoint, factory);
}
 
Example #22
Source File: JmsListenerAnnotationBeanPostProcessor.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Process the given {@link JmsListener} annotation on the given method,
 * registering a corresponding endpoint for the given bean instance.
 * @param jmsListener the annotation to process
 * @param mostSpecificMethod the annotated method
 * @param bean the instance to invoke the method on
 * @see #createMethodJmsListenerEndpoint()
 * @see JmsListenerEndpointRegistrar#registerEndpoint
 */
protected void processJmsListener(JmsListener jmsListener, Method mostSpecificMethod, Object bean) {
	Method invocableMethod = AopUtils.selectInvocableMethod(mostSpecificMethod, bean.getClass());

	MethodJmsListenerEndpoint endpoint = createMethodJmsListenerEndpoint();
	endpoint.setBean(bean);
	endpoint.setMethod(invocableMethod);
	endpoint.setMostSpecificMethod(mostSpecificMethod);
	endpoint.setMessageHandlerMethodFactory(this.messageHandlerMethodFactory);
	endpoint.setEmbeddedValueResolver(this.embeddedValueResolver);
	endpoint.setBeanFactory(this.beanFactory);
	endpoint.setId(getEndpointId(jmsListener));
	endpoint.setDestination(resolve(jmsListener.destination()));
	if (StringUtils.hasText(jmsListener.selector())) {
		endpoint.setSelector(resolve(jmsListener.selector()));
	}
	if (StringUtils.hasText(jmsListener.subscription())) {
		endpoint.setSubscription(resolve(jmsListener.subscription()));
	}
	if (StringUtils.hasText(jmsListener.concurrency())) {
		endpoint.setConcurrency(resolve(jmsListener.concurrency()));
	}

	JmsListenerContainerFactory<?> factory = null;
	String containerFactoryBeanName = resolve(jmsListener.containerFactory());
	if (StringUtils.hasText(containerFactoryBeanName)) {
		Assert.state(this.beanFactory != null, "BeanFactory must be set to obtain container factory by bean name");
		try {
			factory = this.beanFactory.getBean(containerFactoryBeanName, JmsListenerContainerFactory.class);
		}
		catch (NoSuchBeanDefinitionException ex) {
			throw new BeanInitializationException("Could not register JMS listener endpoint on [" +
					mostSpecificMethod + "], no " + JmsListenerContainerFactory.class.getSimpleName() +
					" with id '" + containerFactoryBeanName + "' was found in the application context", ex);
		}
	}

	this.registrar.registerEndpoint(endpoint, factory);
}
 
Example #23
Source File: AbstractJmsAnnotationDrivenTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Test for {@link ValidationBean} with a validator ({@link TestValidator}) specified
 * in a custom {@link org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory}.
 *
 * The test should throw a {@link org.springframework.jms.listener.adapter.ListenerExecutionFailedException}
 */
public void testJmsHandlerMethodFactoryConfiguration(ApplicationContext context) throws JMSException {
	JmsListenerContainerTestFactory simpleFactory =
			context.getBean("defaultFactory", JmsListenerContainerTestFactory.class);
	assertEquals(1, simpleFactory.getListenerContainers().size());
	MethodJmsListenerEndpoint endpoint = (MethodJmsListenerEndpoint)
			simpleFactory.getListenerContainers().get(0).getEndpoint();

	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	endpoint.setupListenerContainer(container);
	MessagingMessageListenerAdapter listener = (MessagingMessageListenerAdapter) container.getMessageListener();
	listener.onMessage(new StubTextMessage("failValidation"), mock(Session.class));
}
 
Example #24
Source File: JmsListenerAnnotationBeanPostProcessorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void sendToAnnotationFoundOnCglibProxy() throws Exception {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			Config.class, ProxyConfig.class, ClassProxyTestBean.class);
	try {
		JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
		assertEquals("one container should have been registered", 1, factory.getListenerContainers().size());

		JmsListenerEndpoint endpoint = factory.getListenerContainers().get(0).getEndpoint();
		assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass());
		MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
		assertTrue(AopUtils.isCglibProxy(methodEndpoint.getBean()));
		assertTrue(methodEndpoint.getBean() instanceof ClassProxyTestBean);
		assertEquals(ClassProxyTestBean.class.getMethod("handleIt", String.class, String.class),
				methodEndpoint.getMethod());
		assertEquals(ClassProxyTestBean.class.getMethod("handleIt", String.class, String.class),
				methodEndpoint.getMostSpecificMethod());

		Method method = ReflectionUtils.findMethod(endpoint.getClass(), "getDefaultResponseDestination");
		ReflectionUtils.makeAccessible(method);
		Object destination = ReflectionUtils.invokeMethod(method, endpoint);
		assertEquals("SendTo annotation not found on proxy", "foobar", destination);
	}
	finally {
		context.close();
	}
}
 
Example #25
Source File: JmsListenerAnnotationBeanPostProcessorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void sendToAnnotationFoundOnInterfaceProxy() throws Exception {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			Config.class, ProxyConfig.class, InterfaceProxyTestBean.class);
	try {
		JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
		assertEquals("one container should have been registered", 1, factory.getListenerContainers().size());

		JmsListenerEndpoint endpoint = factory.getListenerContainers().get(0).getEndpoint();
		assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass());
		MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
		assertTrue(AopUtils.isJdkDynamicProxy(methodEndpoint.getBean()));
		assertTrue(methodEndpoint.getBean() instanceof SimpleService);
		assertEquals(SimpleService.class.getMethod("handleIt", String.class, String.class),
				methodEndpoint.getMethod());
		assertEquals(InterfaceProxyTestBean.class.getMethod("handleIt", String.class, String.class),
				methodEndpoint.getMostSpecificMethod());

		Method method = ReflectionUtils.findMethod(endpoint.getClass(), "getDefaultResponseDestination");
		ReflectionUtils.makeAccessible(method);
		Object destination = ReflectionUtils.invokeMethod(method, endpoint);
		assertEquals("SendTo annotation not found on proxy", "foobar", destination);
	}
	finally {
		context.close();
	}
}
 
Example #26
Source File: JmsListenerAnnotationBeanPostProcessor.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Instantiate an empty {@link MethodJmsListenerEndpoint} for further
 * configuration with provided parameters in {@link #processJmsListener}.
 * @return a new {@code MethodJmsListenerEndpoint} or subclass thereof
 * @since 4.1.9
 * @see MethodJmsListenerEndpoint#createMessageListenerInstance()
 */
protected MethodJmsListenerEndpoint createMethodJmsListenerEndpoint() {
	return new MethodJmsListenerEndpoint();
}
 
Example #27
Source File: JmsListenerAnnotationBeanPostProcessor.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Instantiate an empty {@link MethodJmsListenerEndpoint} for further
 * configuration with provided parameters in {@link #processJmsListener}.
 * @return a new {@code MethodJmsListenerEndpoint} or subclass thereof
 * @since 4.1.9
 * @see MethodJmsListenerEndpoint#createMessageListenerInstance()
 */
protected MethodJmsListenerEndpoint createMethodJmsListenerEndpoint() {
	return new MethodJmsListenerEndpoint();
}
 
Example #28
Source File: JmsListenerAnnotationBeanPostProcessor.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Instantiate an empty {@link MethodJmsListenerEndpoint} for further
 * configuration with provided parameters in {@link #processJmsListener}.
 * @return a new {@code MethodJmsListenerEndpoint} or subclass thereof
 * @since 4.1.9
 * @see MethodJmsListenerEndpoint#createMessageListenerInstance()
 */
protected MethodJmsListenerEndpoint createMethodJmsListenerEndpoint() {
	return new MethodJmsListenerEndpoint();
}