use of jakarta.jms.Destination in project spring-framework by spring-projects.
the class DefaultMessageListenerContainerTests method createContainer.
private DefaultMessageListenerContainer createContainer(ConnectionFactory connectionFactory) {
Destination destination = new Destination() {
};
DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setCacheLevel(DefaultMessageListenerContainer.CACHE_NONE);
container.setDestination(destination);
return container;
}
use of jakarta.jms.Destination in project spring-framework by spring-projects.
the class JmsResponseTests method destinationDoesNotUseDestinationResolver.
@Test
public void destinationDoesNotUseDestinationResolver() throws JMSException {
Destination destination = mock(Destination.class);
Destination actual = JmsResponse.forDestination("foo", destination).resolveDestination(null, null);
assertThat(actual).isSameAs(destination);
}
use of jakarta.jms.Destination in project spring-framework by spring-projects.
the class JndiDestinationResolver method resolveDestinationName.
@Override
public Destination resolveDestinationName(@Nullable Session session, String destinationName, boolean pubSubDomain) throws JMSException {
Assert.notNull(destinationName, "Destination name must not be null");
Destination dest = this.destinationCache.get(destinationName);
if (dest != null) {
validateDestination(dest, destinationName, pubSubDomain);
} else {
try {
dest = lookup(destinationName, Destination.class);
validateDestination(dest, destinationName, pubSubDomain);
} catch (NamingException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Destination [" + destinationName + "] not found in JNDI", ex);
}
if (this.fallbackToDynamicDestination) {
dest = this.dynamicDestinationResolver.resolveDestinationName(session, destinationName, pubSubDomain);
} else {
throw new DestinationResolutionException("Destination [" + destinationName + "] not found in JNDI", ex);
}
}
if (this.cache) {
this.destinationCache.put(destinationName, dest);
}
}
return dest;
}
use of jakarta.jms.Destination in project spring-framework by spring-projects.
the class SimpleJmsHeaderMapper method fromHeaders.
@Override
public void fromHeaders(MessageHeaders headers, jakarta.jms.Message jmsMessage) {
try {
Object jmsCorrelationId = headers.get(JmsHeaders.CORRELATION_ID);
if (jmsCorrelationId instanceof Number) {
jmsCorrelationId = jmsCorrelationId.toString();
}
if (jmsCorrelationId instanceof String) {
try {
jmsMessage.setJMSCorrelationID((String) jmsCorrelationId);
} catch (Exception ex) {
logger.debug("Failed to set JMSCorrelationID - skipping", ex);
}
}
Destination jmsReplyTo = getHeaderIfAvailable(headers, JmsHeaders.REPLY_TO, Destination.class);
if (jmsReplyTo != null) {
try {
jmsMessage.setJMSReplyTo(jmsReplyTo);
} catch (Exception ex) {
logger.debug("Failed to set JMSReplyTo - skipping", ex);
}
}
String jmsType = getHeaderIfAvailable(headers, JmsHeaders.TYPE, String.class);
if (jmsType != null) {
try {
jmsMessage.setJMSType(jmsType);
} catch (Exception ex) {
logger.debug("Failed to set JMSType - skipping", ex);
}
}
for (Map.Entry<String, Object> entry : headers.entrySet()) {
String headerName = entry.getKey();
if (StringUtils.hasText(headerName) && !headerName.startsWith(JmsHeaders.PREFIX)) {
Object value = entry.getValue();
if (value != null && SUPPORTED_PROPERTY_TYPES.contains(value.getClass())) {
try {
String propertyName = this.fromHeaderName(headerName);
jmsMessage.setObjectProperty(propertyName, value);
} catch (Exception ex) {
if (headerName.startsWith("JMSX")) {
if (logger.isTraceEnabled()) {
logger.trace("Skipping reserved header '" + headerName + "' since it cannot be set by client");
}
} else if (logger.isDebugEnabled()) {
logger.debug("Failed to map message header '" + headerName + "' to JMS property", ex);
}
}
}
}
}
} catch (Exception ex) {
if (logger.isDebugEnabled()) {
logger.debug("Error occurred while mapping from MessageHeaders to JMS properties", ex);
}
}
}
use of jakarta.jms.Destination in project spring-framework by spring-projects.
the class SimpleJmsHeaderMapper method toHeaders.
@Override
public MessageHeaders toHeaders(jakarta.jms.Message jmsMessage) {
Map<String, Object> headers = new HashMap<>();
try {
try {
String correlationId = jmsMessage.getJMSCorrelationID();
if (correlationId != null) {
headers.put(JmsHeaders.CORRELATION_ID, correlationId);
}
} catch (Exception ex) {
logger.debug("Failed to read JMSCorrelationID property - skipping", ex);
}
try {
Destination destination = jmsMessage.getJMSDestination();
if (destination != null) {
headers.put(JmsHeaders.DESTINATION, destination);
}
} catch (Exception ex) {
logger.debug("Failed to read JMSDestination property - skipping", ex);
}
try {
int deliveryMode = jmsMessage.getJMSDeliveryMode();
headers.put(JmsHeaders.DELIVERY_MODE, deliveryMode);
} catch (Exception ex) {
logger.debug("Failed to read JMSDeliveryMode property - skipping", ex);
}
try {
long expiration = jmsMessage.getJMSExpiration();
headers.put(JmsHeaders.EXPIRATION, expiration);
} catch (Exception ex) {
logger.debug("Failed to read JMSExpiration property - skipping", ex);
}
try {
String messageId = jmsMessage.getJMSMessageID();
if (messageId != null) {
headers.put(JmsHeaders.MESSAGE_ID, messageId);
}
} catch (Exception ex) {
logger.debug("Failed to read JMSMessageID property - skipping", ex);
}
try {
headers.put(JmsHeaders.PRIORITY, jmsMessage.getJMSPriority());
} catch (Exception ex) {
logger.debug("Failed to read JMSPriority property - skipping", ex);
}
try {
Destination replyTo = jmsMessage.getJMSReplyTo();
if (replyTo != null) {
headers.put(JmsHeaders.REPLY_TO, replyTo);
}
} catch (Exception ex) {
logger.debug("Failed to read JMSReplyTo property - skipping", ex);
}
try {
headers.put(JmsHeaders.REDELIVERED, jmsMessage.getJMSRedelivered());
} catch (Exception ex) {
logger.debug("Failed to read JMSRedelivered property - skipping", ex);
}
try {
String type = jmsMessage.getJMSType();
if (type != null) {
headers.put(JmsHeaders.TYPE, type);
}
} catch (Exception ex) {
logger.debug("Failed to read JMSType property - skipping", ex);
}
try {
headers.put(JmsHeaders.TIMESTAMP, jmsMessage.getJMSTimestamp());
} catch (Exception ex) {
logger.debug("Failed to read JMSTimestamp property - skipping", ex);
}
Enumeration<?> jmsPropertyNames = jmsMessage.getPropertyNames();
if (jmsPropertyNames != null) {
while (jmsPropertyNames.hasMoreElements()) {
String propertyName = jmsPropertyNames.nextElement().toString();
try {
String headerName = this.toHeaderName(propertyName);
headers.put(headerName, jmsMessage.getObjectProperty(propertyName));
} catch (Exception ex) {
if (logger.isDebugEnabled()) {
logger.debug("Error occurred while mapping JMS property '" + propertyName + "' to Message header", ex);
}
}
}
}
} catch (JMSException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Error occurred while mapping from JMS properties to MessageHeaders", ex);
}
}
return new MessageHeaders(headers);
}
Aggregations