Java Code Examples for org.springframework.jms.support.destination.DestinationResolver

The following examples show how to use org.springframework.jms.support.destination.DestinationResolver. These examples are extracted from open source projects. 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
@Test
public void webSphereResourceAdapterSetup() throws Exception {
	Destination destination = new StubQueue();

	DestinationResolver destinationResolver = mock(DestinationResolver.class);
	given(destinationResolver.resolveDestinationName(null, "destinationname", false)).willReturn(destination);

	DefaultJmsActivationSpecFactory activationSpecFactory = new DefaultJmsActivationSpecFactory();
	activationSpecFactory.setDestinationResolver(destinationResolver);

	StubWebSphereActivationSpecImpl spec = (StubWebSphereActivationSpecImpl) activationSpecFactory
			.createActivationSpec(new StubWebSphereResourceAdapterImpl(), activationSpecConfig);

	assertEquals(destination, spec.getDestination());
	assertEquals(5, spec.getMaxConcurrency());
	assertEquals(3, spec.getMaxBatchSize());
}
 
Example 2
@Test
public void webSphereResourceAdapterSetup() throws Exception {
	Destination destination = new StubQueue();

	DestinationResolver destinationResolver = mock(DestinationResolver.class);
	given(destinationResolver.resolveDestinationName(null, "destinationname", false)).willReturn(destination);

	DefaultJmsActivationSpecFactory activationSpecFactory = new DefaultJmsActivationSpecFactory();
	activationSpecFactory.setDestinationResolver(destinationResolver);

	StubWebSphereActivationSpecImpl spec = (StubWebSphereActivationSpecImpl) activationSpecFactory
			.createActivationSpec(new StubWebSphereResourceAdapterImpl(), activationSpecConfig);

	assertEquals(destination, spec.getDestination());
	assertEquals(5, spec.getMaxConcurrency());
	assertEquals(3, spec.getMaxBatchSize());
}
 
Example 3
@Test
public void webSphereResourceAdapterSetup() throws Exception {
	Destination destination = new StubQueue();

	DestinationResolver destinationResolver = mock(DestinationResolver.class);
	given(destinationResolver.resolveDestinationName(null, "destinationname", false)).willReturn(destination);

	DefaultJmsActivationSpecFactory activationSpecFactory = new DefaultJmsActivationSpecFactory();
	activationSpecFactory.setDestinationResolver(destinationResolver);

	StubWebSphereActivationSpecImpl spec = (StubWebSphereActivationSpecImpl) activationSpecFactory
			.createActivationSpec(new StubWebSphereResourceAdapterImpl(), activationSpecConfig);

	assertEquals(destination, spec.getDestination());
	assertEquals(5, spec.getMaxConcurrency());
	assertEquals(3, spec.getMaxBatchSize());
}
 
Example 4
private void processAndReplyWithSendTo(MessagingMessageListenerAdapter listener, boolean pubSubDomain) throws JMSException {
	String body = "echo text";
	String correlationId = "link-1234";
	Destination replyDestination = new Destination() {};

	DestinationResolver destinationResolver = mock(DestinationResolver.class);
	TextMessage reply = mock(TextMessage.class);
	QueueSender queueSender = mock(QueueSender.class);
	Session session = mock(Session.class);

	given(destinationResolver.resolveDestinationName(session, "replyDestination", pubSubDomain))
			.willReturn(replyDestination);
	given(session.createTextMessage(body)).willReturn(reply);
	given(session.createProducer(replyDestination)).willReturn(queueSender);

	listener.setDestinationResolver(destinationResolver);
	StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
	inputMessage.setJMSCorrelationID(correlationId);
	listener.onMessage(inputMessage, session);

	verify(destinationResolver).resolveDestinationName(session, "replyDestination", pubSubDomain);
	verify(reply).setJMSCorrelationID(correlationId);
	verify(queueSender).send(reply);
	verify(queueSender).close();
}
 
Example 5
/**
 * Refresh the JMS destination that this listener container operates on.
 * <p>Called after listener setup failure, assuming that a cached Destination
 * object might have become invalid (a typical case on WebLogic JMS).
 * <p>The default implementation removes the destination from a
 * DestinationResolver's cache, in case of a CachingDestinationResolver.
 * @see #setDestinationName
 * @see org.springframework.jms.support.destination.CachingDestinationResolver
 */
protected void refreshDestination() {
	String destName = getDestinationName();
	if (destName != null) {
		DestinationResolver destResolver = getDestinationResolver();
		if (destResolver instanceof CachingDestinationResolver) {
			((CachingDestinationResolver) destResolver).removeFromCache(destName);
		}
	}
}
 
Example 6
Source Project: spring-analysis-note   Source File: JmsResponse.java    License: MIT License 5 votes vote down vote up
/**
 * Resolve the {@link Destination} to use for this instance. The {@link DestinationResolver}
 * and {@link Session} can be used to resolve a destination at runtime.
 * @param destinationResolver the destination resolver to use if necessary
 * @param session the session to use, if necessary
 * @return the {@link Destination} to use
 * @throws JMSException if the DestinationResolver failed to resolve the destination
 */
@Nullable
public Destination resolveDestination(DestinationResolver destinationResolver, Session session)
		throws JMSException {

	if (this.destination instanceof Destination) {
		return (Destination) this.destination;
	}
	if (this.destination instanceof DestinationNameHolder) {
		DestinationNameHolder nameHolder = (DestinationNameHolder) this.destination;
		return destinationResolver.resolveDestinationName(session,
				nameHolder.destinationName, nameHolder.pubSubDomain);
	}
	return null;
}
 
Example 7
Source Project: spring-analysis-note   Source File: JmsMessageEndpointManager.java    License: MIT License 5 votes vote down vote up
@Override
@Nullable
public DestinationResolver getDestinationResolver() {
	if (this.activationSpecFactory instanceof StandardJmsActivationSpecFactory) {
		return ((StandardJmsActivationSpecFactory) this.activationSpecFactory).getDestinationResolver();
	}
	return null;
}
 
Example 8
Source Project: spring-analysis-note   Source File: MethodJmsListenerEndpoint.java    License: MIT License 5 votes vote down vote up
@Override
protected MessagingMessageListenerAdapter createMessageListener(MessageListenerContainer container) {
	Assert.state(this.messageHandlerMethodFactory != null,
			"Could not create message listener - MessageHandlerMethodFactory not set");
	MessagingMessageListenerAdapter messageListener = createMessageListenerInstance();
	Object bean = getBean();
	Method method = getMethod();
	Assert.state(bean != null && method != null, "No bean+method set on endpoint");
	InvocableHandlerMethod invocableHandlerMethod =
			this.messageHandlerMethodFactory.createInvocableHandlerMethod(bean, method);
	messageListener.setHandlerMethod(invocableHandlerMethod);
	String responseDestination = getDefaultResponseDestination();
	if (StringUtils.hasText(responseDestination)) {
		if (container.isReplyPubSubDomain()) {
			messageListener.setDefaultResponseTopicName(responseDestination);
		}
		else {
			messageListener.setDefaultResponseQueueName(responseDestination);
		}
	}
	QosSettings responseQosSettings = container.getReplyQosSettings();
	if (responseQosSettings != null) {
		messageListener.setResponseQosSettings(responseQosSettings);
	}
	MessageConverter messageConverter = container.getMessageConverter();
	if (messageConverter != null) {
		messageListener.setMessageConverter(messageConverter);
	}
	DestinationResolver destinationResolver = container.getDestinationResolver();
	if (destinationResolver != null) {
		messageListener.setDestinationResolver(destinationResolver);
	}
	return messageListener;
}
 
Example 9
Source Project: spring-analysis-note   Source File: JmsResponseTests.java    License: MIT License 5 votes vote down vote up
@Test
public void resolveDestinationForQueue() throws JMSException {
	Session session = mock(Session.class);
	DestinationResolver destinationResolver = mock(DestinationResolver.class);
	Destination destination = mock(Destination.class);

	given(destinationResolver.resolveDestinationName(session, "myQueue", false)).willReturn(destination);
	JmsResponse<String> jmsResponse = JmsResponse.forQueue("foo", "myQueue");
	Destination actual = jmsResponse.resolveDestination(destinationResolver, session);
	assertSame(destination, actual);
}
 
Example 10
@Test
public void setExtraCollaborators() {
	MessageConverter messageConverter = mock(MessageConverter.class);
	DestinationResolver destinationResolver = mock(DestinationResolver.class);
	this.container.setMessageConverter(messageConverter);
	this.container.setDestinationResolver(destinationResolver);

	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod("resolveObjectPayload", MyBean.class), this.container);
	DirectFieldAccessor accessor = new DirectFieldAccessor(listener);
	assertSame(messageConverter, accessor.getPropertyValue("messageConverter"));
	assertSame(destinationResolver, accessor.getPropertyValue("destinationResolver"));
}
 
Example 11
private void processAndReplyWithSendTo(MessagingMessageListenerAdapter listener,
		String replyDestinationName, boolean pubSubDomain,
		QosSettings replyQosSettings) throws JMSException {
	String body = "echo text";
	String correlationId = "link-1234";
	Destination replyDestination = new Destination() {};

	DestinationResolver destinationResolver = mock(DestinationResolver.class);
	TextMessage reply = mock(TextMessage.class);
	QueueSender queueSender = mock(QueueSender.class);
	Session session = mock(Session.class);

	given(destinationResolver.resolveDestinationName(session, replyDestinationName, pubSubDomain))
			.willReturn(replyDestination);
	given(session.createTextMessage(body)).willReturn(reply);
	given(session.createProducer(replyDestination)).willReturn(queueSender);

	listener.setDestinationResolver(destinationResolver);
	StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
	inputMessage.setJMSCorrelationID(correlationId);
	listener.onMessage(inputMessage, session);

	verify(destinationResolver).resolveDestinationName(session, replyDestinationName, pubSubDomain);
	verify(reply).setJMSCorrelationID(correlationId);
	if (replyQosSettings != null) {
		verify(queueSender).send(reply, replyQosSettings.getDeliveryMode(),
				replyQosSettings.getPriority(), replyQosSettings.getTimeToLive());
	}
	else {
		verify(queueSender).send(reply);
	}
	verify(queueSender).close();
}
 
Example 12
/**
 * Refresh the JMS destination that this listener container operates on.
 * <p>Called after listener setup failure, assuming that a cached Destination
 * object might have become invalid (a typical case on WebLogic JMS).
 * <p>The default implementation removes the destination from a
 * DestinationResolver's cache, in case of a CachingDestinationResolver.
 * @see #setDestinationName
 * @see org.springframework.jms.support.destination.CachingDestinationResolver
 */
protected void refreshDestination() {
	String destName = getDestinationName();
	if (destName != null) {
		DestinationResolver destResolver = getDestinationResolver();
		if (destResolver instanceof CachingDestinationResolver) {
			((CachingDestinationResolver) destResolver).removeFromCache(destName);
		}
	}
}
 
Example 13
Source Project: java-technology-stack   Source File: JmsResponse.java    License: MIT License 5 votes vote down vote up
/**
 * Resolve the {@link Destination} to use for this instance. The {@link DestinationResolver}
 * and {@link Session} can be used to resolve a destination at runtime.
 * @param destinationResolver the destination resolver to use if necessary
 * @param session the session to use, if necessary
 * @return the {@link Destination} to use
 * @throws JMSException if the DestinationResolver failed to resolve the destination
 */
@Nullable
public Destination resolveDestination(DestinationResolver destinationResolver, Session session)
		throws JMSException {

	if (this.destination instanceof Destination) {
		return (Destination) this.destination;
	}
	if (this.destination instanceof DestinationNameHolder) {
		DestinationNameHolder nameHolder = (DestinationNameHolder) this.destination;
		return destinationResolver.resolveDestinationName(session,
				nameHolder.destinationName, nameHolder.pubSubDomain);
	}
	return null;
}
 
Example 14
Source Project: java-technology-stack   Source File: JmsMessageEndpointManager.java    License: MIT License 5 votes vote down vote up
@Override
@Nullable
public DestinationResolver getDestinationResolver() {
	if (this.activationSpecFactory instanceof StandardJmsActivationSpecFactory) {
		return ((StandardJmsActivationSpecFactory) this.activationSpecFactory).getDestinationResolver();
	}
	return null;
}
 
Example 15
Source Project: java-technology-stack   Source File: MethodJmsListenerEndpoint.java    License: MIT License 5 votes vote down vote up
@Override
protected MessagingMessageListenerAdapter createMessageListener(MessageListenerContainer container) {
	Assert.state(this.messageHandlerMethodFactory != null,
			"Could not create message listener - MessageHandlerMethodFactory not set");
	MessagingMessageListenerAdapter messageListener = createMessageListenerInstance();
	InvocableHandlerMethod invocableHandlerMethod =
			this.messageHandlerMethodFactory.createInvocableHandlerMethod(getBean(), getMethod());
	messageListener.setHandlerMethod(invocableHandlerMethod);
	String responseDestination = getDefaultResponseDestination();
	if (StringUtils.hasText(responseDestination)) {
		if (container.isReplyPubSubDomain()) {
			messageListener.setDefaultResponseTopicName(responseDestination);
		}
		else {
			messageListener.setDefaultResponseQueueName(responseDestination);
		}
	}
	QosSettings responseQosSettings = container.getReplyQosSettings();
	if (responseQosSettings != null) {
		messageListener.setResponseQosSettings(responseQosSettings);
	}
	MessageConverter messageConverter = container.getMessageConverter();
	if (messageConverter != null) {
		messageListener.setMessageConverter(messageConverter);
	}
	DestinationResolver destinationResolver = container.getDestinationResolver();
	if (destinationResolver != null) {
		messageListener.setDestinationResolver(destinationResolver);
	}
	return messageListener;
}
 
Example 16
Source Project: java-technology-stack   Source File: JmsResponseTests.java    License: MIT License 5 votes vote down vote up
@Test
public void resolveDestinationForQueue() throws JMSException {
	Session session = mock(Session.class);
	DestinationResolver destinationResolver = mock(DestinationResolver.class);
	Destination destination = mock(Destination.class);

	given(destinationResolver.resolveDestinationName(session, "myQueue", false)).willReturn(destination);
	JmsResponse<String> jmsResponse = JmsResponse.forQueue("foo", "myQueue");
	Destination actual = jmsResponse.resolveDestination(destinationResolver, session);
	assertSame(destination, actual);
}
 
Example 17
@Test
public void setExtraCollaborators() {
	MessageConverter messageConverter = mock(MessageConverter.class);
	DestinationResolver destinationResolver = mock(DestinationResolver.class);
	this.container.setMessageConverter(messageConverter);
	this.container.setDestinationResolver(destinationResolver);

	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod("resolveObjectPayload", MyBean.class), this.container);
	DirectFieldAccessor accessor = new DirectFieldAccessor(listener);
	assertSame(messageConverter, accessor.getPropertyValue("messageConverter"));
	assertSame(destinationResolver, accessor.getPropertyValue("destinationResolver"));
}
 
Example 18
private void processAndReplyWithSendTo(MessagingMessageListenerAdapter listener,
		String replyDestinationName, boolean pubSubDomain,
		QosSettings replyQosSettings) throws JMSException {
	String body = "echo text";
	String correlationId = "link-1234";
	Destination replyDestination = new Destination() {};

	DestinationResolver destinationResolver = mock(DestinationResolver.class);
	TextMessage reply = mock(TextMessage.class);
	QueueSender queueSender = mock(QueueSender.class);
	Session session = mock(Session.class);

	given(destinationResolver.resolveDestinationName(session, replyDestinationName, pubSubDomain))
			.willReturn(replyDestination);
	given(session.createTextMessage(body)).willReturn(reply);
	given(session.createProducer(replyDestination)).willReturn(queueSender);

	listener.setDestinationResolver(destinationResolver);
	StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
	inputMessage.setJMSCorrelationID(correlationId);
	listener.onMessage(inputMessage, session);

	verify(destinationResolver).resolveDestinationName(session, replyDestinationName, pubSubDomain);
	verify(reply).setJMSCorrelationID(correlationId);
	if (replyQosSettings != null) {
		verify(queueSender).send(reply, replyQosSettings.getDeliveryMode(),
				replyQosSettings.getPriority(), replyQosSettings.getTimeToLive());
	}
	else {
		verify(queueSender).send(reply);
	}
	verify(queueSender).close();
}
 
Example 19
/**
 * Refresh the JMS destination that this listener container operates on.
 * <p>Called after listener setup failure, assuming that a cached Destination
 * object might have become invalid (a typical case on WebLogic JMS).
 * <p>The default implementation removes the destination from a
 * DestinationResolver's cache, in case of a CachingDestinationResolver.
 * @see #setDestinationName
 * @see org.springframework.jms.support.destination.CachingDestinationResolver
 */
protected void refreshDestination() {
	String destName = getDestinationName();
	if (destName != null) {
		DestinationResolver destResolver = getDestinationResolver();
		if (destResolver instanceof CachingDestinationResolver) {
			((CachingDestinationResolver) destResolver).removeFromCache(destName);
		}
	}
}
 
Example 20
Source Project: spring4-understanding   Source File: JmsResponse.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Resolve the {@link Destination} to use for this instance. The {@link DestinationResolver}
 * and {@link Session} can be used to resolve a destination at runtime.
 * @param destinationResolver the destination resolver to use if necessary
 * @param session the session to use, if necessary
 * @return the {@link Destination} to use
 * @throws JMSException if the DestinationResolver failed to resolve the destination
 */
public Destination resolveDestination(DestinationResolver destinationResolver, Session session)
		throws JMSException {

	if (this.destination instanceof Destination) {
		return (Destination) this.destination;
	}
	if (this.destination instanceof DestinationNameHolder) {
		DestinationNameHolder nameHolder = (DestinationNameHolder) this.destination;
		return destinationResolver.resolveDestinationName(session,
				nameHolder.destinationName, nameHolder.pubSubDomain);
	}
	return null;
}
 
Example 21
@Override
public DestinationResolver getDestinationResolver() {
	if (this.activationSpecFactory instanceof StandardJmsActivationSpecFactory) {
		return ((StandardJmsActivationSpecFactory) this.activationSpecFactory).getDestinationResolver();
	}
	return null;
}
 
Example 22
@Override
protected MessagingMessageListenerAdapter createMessageListener(MessageListenerContainer container) {
	Assert.state(this.messageHandlerMethodFactory != null,
			"Could not create message listener - MessageHandlerMethodFactory not set");
	MessagingMessageListenerAdapter messageListener = createMessageListenerInstance();
	InvocableHandlerMethod invocableHandlerMethod =
			this.messageHandlerMethodFactory.createInvocableHandlerMethod(getBean(), getMethod());
	messageListener.setHandlerMethod(invocableHandlerMethod);
	String responseDestination = getDefaultResponseDestination();
	if (StringUtils.hasText(responseDestination)) {
		if (container.isReplyPubSubDomain()) {
			messageListener.setDefaultResponseTopicName(responseDestination);
		}
		else {
			messageListener.setDefaultResponseQueueName(responseDestination);
		}
	}
	MessageConverter messageConverter = container.getMessageConverter();
	if (messageConverter != null) {
		messageListener.setMessageConverter(messageConverter);
	}
	DestinationResolver destinationResolver = container.getDestinationResolver();
	if (destinationResolver != null) {
		messageListener.setDestinationResolver(destinationResolver);
	}
	return messageListener;
}
 
Example 23
Source Project: spring4-understanding   Source File: JmsResponseTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void resolveDestinationForQueue() throws JMSException {
	Session session = mock(Session.class);
	DestinationResolver destinationResolver = mock(DestinationResolver.class);
	Destination destination = mock(Destination.class);

	given(destinationResolver.resolveDestinationName(session, "myQueue", false)).willReturn(destination);
	JmsResponse<String> jmsResponse = JmsResponse.forQueue("foo", "myQueue");
	Destination actual = jmsResponse.resolveDestination(destinationResolver, session);
	assertSame(destination, actual);
}
 
Example 24
@Test
public void setExtraCollaborators() {
	MessageConverter messageConverter = mock(MessageConverter.class);
	DestinationResolver destinationResolver = mock(DestinationResolver.class);
	this.container.setMessageConverter(messageConverter);
	this.container.setDestinationResolver(destinationResolver);

	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod("resolveObjectPayload", MyBean.class), container);
	DirectFieldAccessor accessor = new DirectFieldAccessor(listener);
	assertSame(messageConverter, accessor.getPropertyValue("messageConverter"));
	assertSame(destinationResolver, accessor.getPropertyValue("destinationResolver"));
}
 
Example 25
/**
 * Return the DestinationResolver for this adapter.
 */
protected DestinationResolver getDestinationResolver() {
	return this.destinationResolver;
}
 
Example 26
/**
 * Return the {@link DestinationResolver} to use for resolving destinations names.
 */
@Nullable
public DestinationResolver getDestinationResolver() {
	return this.destinationResolver;
}
 
Example 27
/**
 * @see JmsMessageEndpointManager#setDestinationResolver(DestinationResolver)
 */
public void setDestinationResolver(DestinationResolver destinationResolver) {
	this.destinationResolver = destinationResolver;
}
 
Example 28
/**
 * @see AbstractMessageListenerContainer#setDestinationResolver(DestinationResolver)
 */
public void setDestinationResolver(DestinationResolver destinationResolver) {
	this.destinationResolver = destinationResolver;
}
 
Example 29
@Override
public DestinationResolver getDestinationResolver() {
	return null;
}
 
Example 30
/**
 * Return the DestinationResolver for this adapter.
 */
protected DestinationResolver getDestinationResolver() {
	return this.destinationResolver;
}