Apply "instanceof pattern matching" in spring-jms
This commit is contained in:
@@ -71,8 +71,8 @@ public abstract class JmsException extends NestedRuntimeException {
|
|||||||
@Nullable
|
@Nullable
|
||||||
public String getErrorCode() {
|
public String getErrorCode() {
|
||||||
Throwable cause = getCause();
|
Throwable cause = getCause();
|
||||||
if (cause instanceof JMSException) {
|
if (cause instanceof JMSException jmsException) {
|
||||||
return ((JMSException) cause).getErrorCode();
|
return jmsException.getErrorCode();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -87,8 +87,8 @@ public abstract class JmsException extends NestedRuntimeException {
|
|||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
String message = super.getMessage();
|
String message = super.getMessage();
|
||||||
Throwable cause = getCause();
|
Throwable cause = getCause();
|
||||||
if (cause instanceof JMSException) {
|
if (cause instanceof JMSException jmsException) {
|
||||||
Exception linkedEx = ((JMSException) cause).getLinkedException();
|
Exception linkedEx = jmsException.getLinkedException();
|
||||||
if (linkedEx != null) {
|
if (linkedEx != null) {
|
||||||
String linkedMessage = linkedEx.getMessage();
|
String linkedMessage = linkedEx.getMessage();
|
||||||
String causeMessage = cause.getMessage();
|
String causeMessage = cause.getMessage();
|
||||||
|
|||||||
@@ -162,8 +162,8 @@ public class JmsListenerAnnotationBeanPostProcessor
|
|||||||
@Override
|
@Override
|
||||||
public void setBeanFactory(BeanFactory beanFactory) {
|
public void setBeanFactory(BeanFactory beanFactory) {
|
||||||
this.beanFactory = beanFactory;
|
this.beanFactory = beanFactory;
|
||||||
if (beanFactory instanceof ConfigurableBeanFactory) {
|
if (beanFactory instanceof ConfigurableBeanFactory cbf) {
|
||||||
this.embeddedValueResolver = new EmbeddedValueResolver((ConfigurableBeanFactory) beanFactory);
|
this.embeddedValueResolver = new EmbeddedValueResolver(cbf);
|
||||||
}
|
}
|
||||||
this.registrar.setBeanFactory(beanFactory);
|
this.registrar.setBeanFactory(beanFactory);
|
||||||
}
|
}
|
||||||
@@ -174,10 +174,9 @@ public class JmsListenerAnnotationBeanPostProcessor
|
|||||||
// Remove resolved singleton classes from cache
|
// Remove resolved singleton classes from cache
|
||||||
this.nonAnnotatedClasses.clear();
|
this.nonAnnotatedClasses.clear();
|
||||||
|
|
||||||
if (this.beanFactory instanceof ListableBeanFactory) {
|
if (this.beanFactory instanceof ListableBeanFactory lbf) {
|
||||||
// Apply JmsListenerConfigurer beans from the BeanFactory, if any
|
// Apply JmsListenerConfigurer beans from the BeanFactory, if any
|
||||||
Map<String, JmsListenerConfigurer> beans =
|
Map<String, JmsListenerConfigurer> beans = lbf.getBeansOfType(JmsListenerConfigurer.class);
|
||||||
((ListableBeanFactory) this.beanFactory).getBeansOfType(JmsListenerConfigurer.class);
|
|
||||||
List<JmsListenerConfigurer> configurers = new ArrayList<>(beans.values());
|
List<JmsListenerConfigurer> configurers = new ArrayList<>(beans.values());
|
||||||
AnnotationAwareOrderComparator.sort(configurers);
|
AnnotationAwareOrderComparator.sort(configurers);
|
||||||
for (JmsListenerConfigurer configurer : configurers) {
|
for (JmsListenerConfigurer configurer : configurers) {
|
||||||
|
|||||||
@@ -134,8 +134,8 @@ public abstract class AbstractJmsListenerEndpoint implements JmsListenerEndpoint
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setupListenerContainer(MessageListenerContainer listenerContainer) {
|
public void setupListenerContainer(MessageListenerContainer listenerContainer) {
|
||||||
if (listenerContainer instanceof AbstractMessageListenerContainer) {
|
if (listenerContainer instanceof AbstractMessageListenerContainer abstractContainer) {
|
||||||
setupJmsListenerContainer((AbstractMessageListenerContainer) listenerContainer);
|
setupJmsListenerContainer(abstractContainer);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
new JcaEndpointConfigurer().configureEndpoint(listenerContainer);
|
new JcaEndpointConfigurer().configureEndpoint(listenerContainer);
|
||||||
@@ -194,8 +194,8 @@ public abstract class AbstractJmsListenerEndpoint implements JmsListenerEndpoint
|
|||||||
private class JcaEndpointConfigurer {
|
private class JcaEndpointConfigurer {
|
||||||
|
|
||||||
public void configureEndpoint(Object listenerContainer) {
|
public void configureEndpoint(Object listenerContainer) {
|
||||||
if (listenerContainer instanceof JmsMessageEndpointManager) {
|
if (listenerContainer instanceof JmsMessageEndpointManager endpointManager) {
|
||||||
setupJcaMessageContainer((JmsMessageEndpointManager) listenerContainer);
|
setupJcaMessageContainer(endpointManager);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new IllegalArgumentException("Could not configure endpoint with the specified container '" +
|
throw new IllegalArgumentException("Could not configure endpoint with the specified container '" +
|
||||||
|
|||||||
@@ -124,8 +124,8 @@ public class JmsListenerEndpointRegistrar implements BeanFactoryAware, Initializ
|
|||||||
@Override
|
@Override
|
||||||
public void setBeanFactory(BeanFactory beanFactory) {
|
public void setBeanFactory(BeanFactory beanFactory) {
|
||||||
this.beanFactory = beanFactory;
|
this.beanFactory = beanFactory;
|
||||||
if (beanFactory instanceof ConfigurableBeanFactory) {
|
if (beanFactory instanceof ConfigurableBeanFactory cbf) {
|
||||||
this.mutex = ((ConfigurableBeanFactory) beanFactory).getSingletonMutex();
|
this.mutex = cbf.getSingletonMutex();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -170,9 +170,9 @@ public class JmsListenerEndpointRegistry implements DisposableBean, SmartLifecyc
|
|||||||
|
|
||||||
MessageListenerContainer listenerContainer = factory.createListenerContainer(endpoint);
|
MessageListenerContainer listenerContainer = factory.createListenerContainer(endpoint);
|
||||||
|
|
||||||
if (listenerContainer instanceof InitializingBean) {
|
if (listenerContainer instanceof InitializingBean initializingBean) {
|
||||||
try {
|
try {
|
||||||
((InitializingBean) listenerContainer).afterPropertiesSet();
|
initializingBean.afterPropertiesSet();
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
throw new BeanInitializationException("Failed to initialize message listener container", ex);
|
throw new BeanInitializationException("Failed to initialize message listener container", ex);
|
||||||
@@ -246,9 +246,9 @@ public class JmsListenerEndpointRegistry implements DisposableBean, SmartLifecyc
|
|||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
for (MessageListenerContainer listenerContainer : getListenerContainers()) {
|
for (MessageListenerContainer listenerContainer : getListenerContainers()) {
|
||||||
if (listenerContainer instanceof DisposableBean) {
|
if (listenerContainer instanceof DisposableBean disposableBean) {
|
||||||
try {
|
try {
|
||||||
((DisposableBean) listenerContainer).destroy();
|
disposableBean.destroy();
|
||||||
}
|
}
|
||||||
catch (Throwable ex) {
|
catch (Throwable ex) {
|
||||||
logger.warn("Failed to destroy message listener container", ex);
|
logger.warn("Failed to destroy message listener container", ex);
|
||||||
|
|||||||
@@ -136,8 +136,8 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint imple
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setBeanFactory(@Nullable BeanFactory beanFactory) {
|
public void setBeanFactory(@Nullable BeanFactory beanFactory) {
|
||||||
if (this.embeddedValueResolver == null && beanFactory instanceof ConfigurableBeanFactory) {
|
if (this.embeddedValueResolver == null && beanFactory instanceof ConfigurableBeanFactory cbf) {
|
||||||
this.embeddedValueResolver = new EmbeddedValueResolver((ConfigurableBeanFactory) beanFactory);
|
this.embeddedValueResolver = new EmbeddedValueResolver(cbf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,18 +52,18 @@ class CachedMessageConsumer implements MessageConsumer, QueueReceiver, TopicSubs
|
|||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public Queue getQueue() throws JMSException {
|
public Queue getQueue() throws JMSException {
|
||||||
return (this.target instanceof QueueReceiver ? ((QueueReceiver) this.target).getQueue() : null);
|
return (this.target instanceof QueueReceiver receiver ? receiver.getQueue() : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public Topic getTopic() throws JMSException {
|
public Topic getTopic() throws JMSException {
|
||||||
return (this.target instanceof TopicSubscriber ? ((TopicSubscriber) this.target).getTopic() : null);
|
return (this.target instanceof TopicSubscriber subscriber ? subscriber.getTopic() : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getNoLocal() throws JMSException {
|
public boolean getNoLocal() throws JMSException {
|
||||||
return (this.target instanceof TopicSubscriber && ((TopicSubscriber) this.target).getNoLocal());
|
return (this.target instanceof TopicSubscriber subscriber && subscriber.getNoLocal());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
|
|||||||
if (session != null) {
|
if (session != null) {
|
||||||
if (logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
logger.trace("Found cached JMS Session for mode " + mode + ": " +
|
logger.trace("Found cached JMS Session for mode " + mode + ": " +
|
||||||
(session instanceof SessionProxy ? ((SessionProxy) session).getTargetSession() : session));
|
(session instanceof SessionProxy sessionProxy ? sessionProxy.getTargetSession() : session));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -455,15 +455,15 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (dest instanceof Topic) {
|
if (dest instanceof Topic topic) {
|
||||||
if (noLocal == null) {
|
if (noLocal == null) {
|
||||||
consumer = (durable ?
|
consumer = (durable ?
|
||||||
this.target.createSharedDurableConsumer((Topic) dest, subscription, selector) :
|
this.target.createSharedDurableConsumer(topic, subscription, selector) :
|
||||||
this.target.createSharedConsumer((Topic) dest, subscription, selector));
|
this.target.createSharedConsumer(topic, subscription, selector));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
consumer = (durable ?
|
consumer = (durable ?
|
||||||
this.target.createDurableSubscriber((Topic) dest, subscription, selector, noLocal) :
|
this.target.createDurableSubscriber(topic, subscription, selector, noLocal) :
|
||||||
this.target.createConsumer(dest, selector, noLocal));
|
this.target.createConsumer(dest, selector, noLocal));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -559,11 +559,11 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object other) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
// Effectively checking object equality as well as toString equality.
|
// Effectively checking object equality as well as toString equality.
|
||||||
// On WebSphere MQ, Destination objects do not implement equals...
|
// On WebSphere MQ, Destination objects do not implement equals...
|
||||||
return (this == other || (other instanceof DestinationCacheKey &&
|
return (this == obj || (obj instanceof DestinationCacheKey otherKey &&
|
||||||
destinationEquals((DestinationCacheKey) other)));
|
destinationEquals(otherKey)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public abstract class ConnectionFactoryUtils {
|
|||||||
if (con == null) {
|
if (con == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (started && cf instanceof SmartConnectionFactory && ((SmartConnectionFactory) cf).shouldStop(con)) {
|
if (started && cf instanceof SmartConnectionFactory smartFactory && smartFactory.shouldStop(con)) {
|
||||||
try {
|
try {
|
||||||
con.stop();
|
con.stop();
|
||||||
}
|
}
|
||||||
@@ -94,8 +94,8 @@ public abstract class ConnectionFactoryUtils {
|
|||||||
*/
|
*/
|
||||||
public static Session getTargetSession(Session session) {
|
public static Session getTargetSession(Session session) {
|
||||||
Session sessionToUse = session;
|
Session sessionToUse = session;
|
||||||
while (sessionToUse instanceof SessionProxy) {
|
while (sessionToUse instanceof SessionProxy sessionProxy) {
|
||||||
sessionToUse = ((SessionProxy) sessionToUse).getTargetSession();
|
sessionToUse = sessionProxy.getTargetSession();
|
||||||
}
|
}
|
||||||
return sessionToUse;
|
return sessionToUse;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,60 +120,60 @@ public class DelegatingConnectionFactory
|
|||||||
@Override
|
@Override
|
||||||
public QueueConnection createQueueConnection() throws JMSException {
|
public QueueConnection createQueueConnection() throws JMSException {
|
||||||
ConnectionFactory target = obtainTargetConnectionFactory();
|
ConnectionFactory target = obtainTargetConnectionFactory();
|
||||||
if (target instanceof QueueConnectionFactory) {
|
if (target instanceof QueueConnectionFactory queueFactory) {
|
||||||
return ((QueueConnectionFactory) target).createQueueConnection();
|
return queueFactory.createQueueConnection();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Connection con = target.createConnection();
|
Connection con = target.createConnection();
|
||||||
if (!(con instanceof QueueConnection)) {
|
if (!(con instanceof QueueConnection queueConnection)) {
|
||||||
throw new jakarta.jms.IllegalStateException("'targetConnectionFactory' is not a QueueConnectionFactory");
|
throw new jakarta.jms.IllegalStateException("'targetConnectionFactory' is not a QueueConnectionFactory");
|
||||||
}
|
}
|
||||||
return (QueueConnection) con;
|
return queueConnection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueueConnection createQueueConnection(String username, String password) throws JMSException {
|
public QueueConnection createQueueConnection(String username, String password) throws JMSException {
|
||||||
ConnectionFactory target = obtainTargetConnectionFactory();
|
ConnectionFactory target = obtainTargetConnectionFactory();
|
||||||
if (target instanceof QueueConnectionFactory) {
|
if (target instanceof QueueConnectionFactory queueFactory) {
|
||||||
return ((QueueConnectionFactory) target).createQueueConnection(username, password);
|
return queueFactory.createQueueConnection(username, password);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Connection con = target.createConnection(username, password);
|
Connection con = target.createConnection(username, password);
|
||||||
if (!(con instanceof QueueConnection)) {
|
if (!(con instanceof QueueConnection queueConnection)) {
|
||||||
throw new jakarta.jms.IllegalStateException("'targetConnectionFactory' is not a QueueConnectionFactory");
|
throw new jakarta.jms.IllegalStateException("'targetConnectionFactory' is not a QueueConnectionFactory");
|
||||||
}
|
}
|
||||||
return (QueueConnection) con;
|
return queueConnection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TopicConnection createTopicConnection() throws JMSException {
|
public TopicConnection createTopicConnection() throws JMSException {
|
||||||
ConnectionFactory target = obtainTargetConnectionFactory();
|
ConnectionFactory target = obtainTargetConnectionFactory();
|
||||||
if (target instanceof TopicConnectionFactory) {
|
if (target instanceof TopicConnectionFactory topicFactory) {
|
||||||
return ((TopicConnectionFactory) target).createTopicConnection();
|
return topicFactory.createTopicConnection();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Connection con = target.createConnection();
|
Connection con = target.createConnection();
|
||||||
if (!(con instanceof TopicConnection)) {
|
if (!(con instanceof TopicConnection topicConnection)) {
|
||||||
throw new jakarta.jms.IllegalStateException("'targetConnectionFactory' is not a TopicConnectionFactory");
|
throw new jakarta.jms.IllegalStateException("'targetConnectionFactory' is not a TopicConnectionFactory");
|
||||||
}
|
}
|
||||||
return (TopicConnection) con;
|
return topicConnection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TopicConnection createTopicConnection(String username, String password) throws JMSException {
|
public TopicConnection createTopicConnection(String username, String password) throws JMSException {
|
||||||
ConnectionFactory target = obtainTargetConnectionFactory();
|
ConnectionFactory target = obtainTargetConnectionFactory();
|
||||||
if (target instanceof TopicConnectionFactory) {
|
if (target instanceof TopicConnectionFactory topicFactory) {
|
||||||
return ((TopicConnectionFactory) target).createTopicConnection(username, password);
|
return topicFactory.createTopicConnection(username, password);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Connection con = target.createConnection(username, password);
|
Connection con = target.createConnection(username, password);
|
||||||
if (!(con instanceof TopicConnection)) {
|
if (!(con instanceof TopicConnection topicConnection)) {
|
||||||
throw new jakarta.jms.IllegalStateException("'targetConnectionFactory' is not a TopicConnectionFactory");
|
throw new jakarta.jms.IllegalStateException("'targetConnectionFactory' is not a TopicConnectionFactory");
|
||||||
}
|
}
|
||||||
return (TopicConnection) con;
|
return topicConnection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -130,11 +130,11 @@ public class JmsTransactionManager extends AbstractPlatformTransactionManager
|
|||||||
* Set the JMS ConnectionFactory that this instance should manage transactions for.
|
* Set the JMS ConnectionFactory that this instance should manage transactions for.
|
||||||
*/
|
*/
|
||||||
public void setConnectionFactory(@Nullable ConnectionFactory cf) {
|
public void setConnectionFactory(@Nullable ConnectionFactory cf) {
|
||||||
if (cf instanceof TransactionAwareConnectionFactoryProxy) {
|
if (cf instanceof TransactionAwareConnectionFactoryProxy txAwareCFP) {
|
||||||
// If we got a TransactionAwareConnectionFactoryProxy, we need to perform transactions
|
// If we got a TransactionAwareConnectionFactoryProxy, we need to perform transactions
|
||||||
// for its underlying target ConnectionFactory, else JMS access code won't see
|
// for its underlying target ConnectionFactory, else JMS access code won't see
|
||||||
// properly exposed transactions (i.e. transactions for the target ConnectionFactory).
|
// properly exposed transactions (i.e. transactions for the target ConnectionFactory).
|
||||||
this.connectionFactory = ((TransactionAwareConnectionFactoryProxy) cf).getTargetConnectionFactory();
|
this.connectionFactory = txAwareCFP.getTargetConnectionFactory();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.connectionFactory = cf;
|
this.connectionFactory = cf;
|
||||||
|
|||||||
@@ -255,11 +255,11 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti
|
|||||||
this.pubSubMode = Boolean.FALSE;
|
this.pubSubMode = Boolean.FALSE;
|
||||||
con = createConnection();
|
con = createConnection();
|
||||||
}
|
}
|
||||||
if (!(con instanceof QueueConnection)) {
|
if (!(con instanceof QueueConnection queueConnection)) {
|
||||||
throw new jakarta.jms.IllegalStateException(
|
throw new jakarta.jms.IllegalStateException(
|
||||||
"This SingleConnectionFactory does not hold a QueueConnection but rather: " + con);
|
"This SingleConnectionFactory does not hold a QueueConnection but rather: " + con);
|
||||||
}
|
}
|
||||||
return ((QueueConnection) con);
|
return queueConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -275,11 +275,11 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti
|
|||||||
this.pubSubMode = Boolean.TRUE;
|
this.pubSubMode = Boolean.TRUE;
|
||||||
con = createConnection();
|
con = createConnection();
|
||||||
}
|
}
|
||||||
if (!(con instanceof TopicConnection)) {
|
if (!(con instanceof TopicConnection topicConnection)) {
|
||||||
throw new jakarta.jms.IllegalStateException(
|
throw new jakarta.jms.IllegalStateException(
|
||||||
"This SingleConnectionFactory does not hold a TopicConnection but rather: " + con);
|
"This SingleConnectionFactory does not hold a TopicConnection but rather: " + con);
|
||||||
}
|
}
|
||||||
return ((TopicConnection) con);
|
return topicConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -399,11 +399,11 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti
|
|||||||
*/
|
*/
|
||||||
protected Connection doCreateConnection() throws JMSException {
|
protected Connection doCreateConnection() throws JMSException {
|
||||||
ConnectionFactory cf = getTargetConnectionFactory();
|
ConnectionFactory cf = getTargetConnectionFactory();
|
||||||
if (Boolean.FALSE.equals(this.pubSubMode) && cf instanceof QueueConnectionFactory) {
|
if (Boolean.FALSE.equals(this.pubSubMode) && cf instanceof QueueConnectionFactory queueFactory) {
|
||||||
return ((QueueConnectionFactory) cf).createQueueConnection();
|
return queueFactory.createQueueConnection();
|
||||||
}
|
}
|
||||||
else if (Boolean.TRUE.equals(this.pubSubMode) && cf instanceof TopicConnectionFactory) {
|
else if (Boolean.TRUE.equals(this.pubSubMode) && cf instanceof TopicConnectionFactory topicFactory) {
|
||||||
return ((TopicConnectionFactory) cf).createTopicConnection();
|
return topicFactory.createTopicConnection();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return obtainTargetConnectionFactory().createConnection();
|
return obtainTargetConnectionFactory().createConnection();
|
||||||
@@ -472,11 +472,11 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti
|
|||||||
boolean transacted = (mode == Session.SESSION_TRANSACTED);
|
boolean transacted = (mode == Session.SESSION_TRANSACTED);
|
||||||
int ackMode = (transacted ? Session.AUTO_ACKNOWLEDGE : mode);
|
int ackMode = (transacted ? Session.AUTO_ACKNOWLEDGE : mode);
|
||||||
// Now actually call the appropriate JMS factory method...
|
// Now actually call the appropriate JMS factory method...
|
||||||
if (Boolean.FALSE.equals(this.pubSubMode) && con instanceof QueueConnection) {
|
if (Boolean.FALSE.equals(this.pubSubMode) && con instanceof QueueConnection queueConnection) {
|
||||||
return ((QueueConnection) con).createQueueSession(transacted, ackMode);
|
return queueConnection.createQueueSession(transacted, ackMode);
|
||||||
}
|
}
|
||||||
else if (Boolean.TRUE.equals(this.pubSubMode) && con instanceof TopicConnection) {
|
else if (Boolean.TRUE.equals(this.pubSubMode) && con instanceof TopicConnection topicConnection) {
|
||||||
return ((TopicConnection) con).createTopicSession(transacted, ackMode);
|
return topicConnection.createTopicSession(transacted, ackMode);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return con.createSession(transacted, ackMode);
|
return con.createSession(transacted, ackMode);
|
||||||
@@ -554,8 +554,8 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
InvocationHandler otherHandler = Proxy.getInvocationHandler(other);
|
InvocationHandler otherHandler = Proxy.getInvocationHandler(other);
|
||||||
return (otherHandler instanceof SharedConnectionInvocationHandler &&
|
return (otherHandler instanceof SharedConnectionInvocationHandler sharedHandler &&
|
||||||
factory() == ((SharedConnectionInvocationHandler) otherHandler).factory());
|
factory() == sharedHandler.factory());
|
||||||
case "hashCode":
|
case "hashCode":
|
||||||
// Use hashCode of containing SingleConnectionFactory.
|
// Use hashCode of containing SingleConnectionFactory.
|
||||||
return System.identityHashCode(factory());
|
return System.identityHashCode(factory());
|
||||||
|
|||||||
@@ -163,40 +163,40 @@ public class TransactionAwareConnectionFactoryProxy
|
|||||||
@Override
|
@Override
|
||||||
public QueueConnection createQueueConnection() throws JMSException {
|
public QueueConnection createQueueConnection() throws JMSException {
|
||||||
ConnectionFactory target = getTargetConnectionFactory();
|
ConnectionFactory target = getTargetConnectionFactory();
|
||||||
if (!(target instanceof QueueConnectionFactory)) {
|
if (!(target instanceof QueueConnectionFactory queueFactory)) {
|
||||||
throw new jakarta.jms.IllegalStateException("'targetConnectionFactory' is no QueueConnectionFactory");
|
throw new jakarta.jms.IllegalStateException("'targetConnectionFactory' is no QueueConnectionFactory");
|
||||||
}
|
}
|
||||||
QueueConnection targetConnection = ((QueueConnectionFactory) target).createQueueConnection();
|
QueueConnection targetConnection = queueFactory.createQueueConnection();
|
||||||
return (QueueConnection) getTransactionAwareConnectionProxy(targetConnection);
|
return (QueueConnection) getTransactionAwareConnectionProxy(targetConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueueConnection createQueueConnection(String username, String password) throws JMSException {
|
public QueueConnection createQueueConnection(String username, String password) throws JMSException {
|
||||||
ConnectionFactory target = getTargetConnectionFactory();
|
ConnectionFactory target = getTargetConnectionFactory();
|
||||||
if (!(target instanceof QueueConnectionFactory)) {
|
if (!(target instanceof QueueConnectionFactory queueFactory)) {
|
||||||
throw new jakarta.jms.IllegalStateException("'targetConnectionFactory' is no QueueConnectionFactory");
|
throw new jakarta.jms.IllegalStateException("'targetConnectionFactory' is no QueueConnectionFactory");
|
||||||
}
|
}
|
||||||
QueueConnection targetConnection = ((QueueConnectionFactory) target).createQueueConnection(username, password);
|
QueueConnection targetConnection = queueFactory.createQueueConnection(username, password);
|
||||||
return (QueueConnection) getTransactionAwareConnectionProxy(targetConnection);
|
return (QueueConnection) getTransactionAwareConnectionProxy(targetConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TopicConnection createTopicConnection() throws JMSException {
|
public TopicConnection createTopicConnection() throws JMSException {
|
||||||
ConnectionFactory target = getTargetConnectionFactory();
|
ConnectionFactory target = getTargetConnectionFactory();
|
||||||
if (!(target instanceof TopicConnectionFactory)) {
|
if (!(target instanceof TopicConnectionFactory topicFactory)) {
|
||||||
throw new jakarta.jms.IllegalStateException("'targetConnectionFactory' is no TopicConnectionFactory");
|
throw new jakarta.jms.IllegalStateException("'targetConnectionFactory' is no TopicConnectionFactory");
|
||||||
}
|
}
|
||||||
TopicConnection targetConnection = ((TopicConnectionFactory) target).createTopicConnection();
|
TopicConnection targetConnection = topicFactory.createTopicConnection();
|
||||||
return (TopicConnection) getTransactionAwareConnectionProxy(targetConnection);
|
return (TopicConnection) getTransactionAwareConnectionProxy(targetConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TopicConnection createTopicConnection(String username, String password) throws JMSException {
|
public TopicConnection createTopicConnection(String username, String password) throws JMSException {
|
||||||
ConnectionFactory target = getTargetConnectionFactory();
|
ConnectionFactory target = getTargetConnectionFactory();
|
||||||
if (!(target instanceof TopicConnectionFactory)) {
|
if (!(target instanceof TopicConnectionFactory topicFactory)) {
|
||||||
throw new jakarta.jms.IllegalStateException("'targetConnectionFactory' is no TopicConnectionFactory");
|
throw new jakarta.jms.IllegalStateException("'targetConnectionFactory' is no TopicConnectionFactory");
|
||||||
}
|
}
|
||||||
TopicConnection targetConnection = ((TopicConnectionFactory) target).createTopicConnection(username, password);
|
TopicConnection targetConnection = topicFactory.createTopicConnection(username, password);
|
||||||
return (TopicConnection) getTransactionAwareConnectionProxy(targetConnection);
|
return (TopicConnection) getTransactionAwareConnectionProxy(targetConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -283,14 +283,14 @@ public class UserCredentialsConnectionFactoryAdapter
|
|||||||
@Nullable String username, @Nullable String password) throws JMSException {
|
@Nullable String username, @Nullable String password) throws JMSException {
|
||||||
|
|
||||||
ConnectionFactory target = obtainTargetConnectionFactory();
|
ConnectionFactory target = obtainTargetConnectionFactory();
|
||||||
if (!(target instanceof TopicConnectionFactory queueFactory)) {
|
if (!(target instanceof TopicConnectionFactory topicFactory)) {
|
||||||
throw new jakarta.jms.IllegalStateException("'targetConnectionFactory' is not a TopicConnectionFactory");
|
throw new jakarta.jms.IllegalStateException("'targetConnectionFactory' is not a TopicConnectionFactory");
|
||||||
}
|
}
|
||||||
if (StringUtils.hasLength(username)) {
|
if (StringUtils.hasLength(username)) {
|
||||||
return queueFactory.createTopicConnection(username, password);
|
return topicFactory.createTopicConnection(username, password);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return queueFactory.createTopicConnection();
|
return topicFactory.createTopicConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public Destination getDefaultDestination() {
|
public Destination getDefaultDestination() {
|
||||||
return (this.defaultDestination instanceof Destination ? (Destination) this.defaultDestination : null);
|
return (this.defaultDestination instanceof Destination dest ? dest : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -207,7 +207,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getDefaultDestinationName() {
|
public String getDefaultDestinationName() {
|
||||||
return (this.defaultDestination instanceof String ? (String) this.defaultDestination : null);
|
return (this.defaultDestination instanceof String name ? name : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getRequiredDefaultDestinationName() throws IllegalStateException {
|
private String getRequiredDefaultDestinationName() throws IllegalStateException {
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public Destination getDestination() {
|
public Destination getDestination() {
|
||||||
return (this.destination instanceof Destination ? (Destination) this.destination : null);
|
return (this.destination instanceof Destination _destination ? _destination : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -236,7 +236,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getDestinationName() {
|
public String getDestinationName() {
|
||||||
return (this.destination instanceof String ? (String) this.destination : null);
|
return (this.destination instanceof String name ? name : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -326,8 +326,8 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
|
|||||||
* @see SubscriptionNameProvider
|
* @see SubscriptionNameProvider
|
||||||
*/
|
*/
|
||||||
protected String getDefaultSubscriptionName(Object messageListener) {
|
protected String getDefaultSubscriptionName(Object messageListener) {
|
||||||
if (messageListener instanceof SubscriptionNameProvider) {
|
if (messageListener instanceof SubscriptionNameProvider subscriptionNameProvider) {
|
||||||
return ((SubscriptionNameProvider) messageListener).getSubscriptionName();
|
return subscriptionNameProvider.getSubscriptionName();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return messageListener.getClass().getName();
|
return messageListener.getClass().getName();
|
||||||
@@ -692,11 +692,11 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
|
|||||||
protected void invokeListener(Session session, Message message) throws JMSException {
|
protected void invokeListener(Session session, Message message) throws JMSException {
|
||||||
Object listener = getMessageListener();
|
Object listener = getMessageListener();
|
||||||
|
|
||||||
if (listener instanceof SessionAwareMessageListener) {
|
if (listener instanceof SessionAwareMessageListener sessionAwareMessageListener) {
|
||||||
doInvokeListener((SessionAwareMessageListener) listener, session, message);
|
doInvokeListener(sessionAwareMessageListener, session, message);
|
||||||
}
|
}
|
||||||
else if (listener instanceof MessageListener) {
|
else if (listener instanceof MessageListener msgListener) {
|
||||||
doInvokeListener((MessageListener) listener, message);
|
doInvokeListener(msgListener, message);
|
||||||
}
|
}
|
||||||
else if (listener != null) {
|
else if (listener != null) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
@@ -853,15 +853,15 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
|
|||||||
* @throws jakarta.jms.JMSException if thrown by JMS API methods
|
* @throws jakarta.jms.JMSException if thrown by JMS API methods
|
||||||
*/
|
*/
|
||||||
protected MessageConsumer createConsumer(Session session, Destination destination) throws JMSException {
|
protected MessageConsumer createConsumer(Session session, Destination destination) throws JMSException {
|
||||||
if (isPubSubDomain() && destination instanceof Topic) {
|
if (isPubSubDomain() && destination instanceof Topic topic) {
|
||||||
if (isSubscriptionShared()) {
|
if (isSubscriptionShared()) {
|
||||||
return (isSubscriptionDurable() ?
|
return (isSubscriptionDurable() ?
|
||||||
session.createSharedDurableConsumer((Topic) destination, getSubscriptionName(), getMessageSelector()) :
|
session.createSharedDurableConsumer(topic, getSubscriptionName(), getMessageSelector()) :
|
||||||
session.createSharedConsumer((Topic) destination, getSubscriptionName(), getMessageSelector()));
|
session.createSharedConsumer(topic, getSubscriptionName(), getMessageSelector()));
|
||||||
}
|
}
|
||||||
else if (isSubscriptionDurable()) {
|
else if (isSubscriptionDurable()) {
|
||||||
return session.createDurableSubscriber(
|
return session.createDurableSubscriber(
|
||||||
(Topic) destination, getSubscriptionName(), getMessageSelector(), isPubSubNoLocal());
|
topic, getSubscriptionName(), getMessageSelector(), isPubSubNoLocal());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Only pass in the NoLocal flag in case of a Topic (pub-sub mode):
|
// Only pass in the NoLocal flag in case of a Topic (pub-sub mode):
|
||||||
@@ -888,8 +888,8 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
|
|||||||
// Internal exception - has been handled before.
|
// Internal exception - has been handled before.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ex instanceof JMSException) {
|
if (ex instanceof JMSException jmsException) {
|
||||||
invokeExceptionListener((JMSException) ex);
|
invokeExceptionListener(jmsException);
|
||||||
}
|
}
|
||||||
if (isActive()) {
|
if (isActive()) {
|
||||||
// Regular case: failed while active.
|
// Regular case: failed while active.
|
||||||
|
|||||||
@@ -188,9 +188,8 @@ public abstract class AbstractPollingMessageListenerContainer extends AbstractMe
|
|||||||
public void initialize() {
|
public void initialize() {
|
||||||
// Set sessionTransacted=true in case of a non-JTA transaction manager.
|
// Set sessionTransacted=true in case of a non-JTA transaction manager.
|
||||||
if (!this.sessionTransactedCalled &&
|
if (!this.sessionTransactedCalled &&
|
||||||
this.transactionManager instanceof ResourceTransactionManager &&
|
this.transactionManager instanceof ResourceTransactionManager rtm &&
|
||||||
!TransactionSynchronizationUtils.sameResourceFactory(
|
!TransactionSynchronizationUtils.sameResourceFactory(rtm, obtainConnectionFactory())) {
|
||||||
(ResourceTransactionManager) this.transactionManager, obtainConnectionFactory())) {
|
|
||||||
super.setSessionTransacted(true);
|
super.setSessionTransacted(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,8 +339,8 @@ public abstract class AbstractPollingMessageListenerContainer extends AbstractMe
|
|||||||
handleListenerException(ex);
|
handleListenerException(ex);
|
||||||
// Rethrow JMSException to indicate an infrastructure problem
|
// Rethrow JMSException to indicate an infrastructure problem
|
||||||
// that may have to trigger recovery...
|
// that may have to trigger recovery...
|
||||||
if (ex instanceof JMSException) {
|
if (ex instanceof JMSException jmsException) {
|
||||||
throw (JMSException) ex;
|
throw jmsException;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
|||||||
@@ -568,8 +568,8 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
|
|||||||
if (this.taskExecutor == null) {
|
if (this.taskExecutor == null) {
|
||||||
this.taskExecutor = createDefaultTaskExecutor();
|
this.taskExecutor = createDefaultTaskExecutor();
|
||||||
}
|
}
|
||||||
else if (this.taskExecutor instanceof SchedulingTaskExecutor &&
|
else if (this.taskExecutor instanceof SchedulingTaskExecutor ste &&
|
||||||
((SchedulingTaskExecutor) this.taskExecutor).prefersShortLivedTasks() &&
|
ste.prefersShortLivedTasks() &&
|
||||||
this.maxMessagesPerTask == Integer.MIN_VALUE) {
|
this.maxMessagesPerTask == Integer.MIN_VALUE) {
|
||||||
// TaskExecutor indicated a preference for short-lived tasks. According to
|
// TaskExecutor indicated a preference for short-lived tasks. According to
|
||||||
// setMaxMessagesPerTask javadoc, we'll use 10 message per task in this case
|
// setMaxMessagesPerTask javadoc, we'll use 10 message per task in this case
|
||||||
@@ -861,8 +861,8 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
|
|||||||
super.establishSharedConnection();
|
super.establishSharedConnection();
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
if (ex instanceof JMSException) {
|
if (ex instanceof JMSException jmsException) {
|
||||||
invokeExceptionListener((JMSException) ex);
|
invokeExceptionListener(jmsException);
|
||||||
}
|
}
|
||||||
logger.debug("Could not establish shared JMS Connection - " +
|
logger.debug("Could not establish shared JMS Connection - " +
|
||||||
"leaving it up to asynchronous invokers to establish a Connection as soon as possible", ex);
|
"leaving it up to asynchronous invokers to establish a Connection as soon as possible", ex);
|
||||||
@@ -913,8 +913,8 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
|
|||||||
* @see #recoverAfterListenerSetupFailure()
|
* @see #recoverAfterListenerSetupFailure()
|
||||||
*/
|
*/
|
||||||
protected void handleListenerSetupFailure(Throwable ex, boolean alreadyRecovered) {
|
protected void handleListenerSetupFailure(Throwable ex, boolean alreadyRecovered) {
|
||||||
if (ex instanceof JMSException) {
|
if (ex instanceof JMSException jmsException) {
|
||||||
invokeExceptionListener((JMSException) ex);
|
invokeExceptionListener(jmsException);
|
||||||
}
|
}
|
||||||
if (ex instanceof SharedConnectionNotInitializedException) {
|
if (ex instanceof SharedConnectionNotInitializedException) {
|
||||||
if (!alreadyRecovered) {
|
if (!alreadyRecovered) {
|
||||||
@@ -930,7 +930,8 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
|
|||||||
StringBuilder msg = new StringBuilder();
|
StringBuilder msg = new StringBuilder();
|
||||||
msg.append("Setup of JMS message listener invoker failed for destination '");
|
msg.append("Setup of JMS message listener invoker failed for destination '");
|
||||||
msg.append(getDestinationDescription()).append("' - trying to recover. Cause: ");
|
msg.append(getDestinationDescription()).append("' - trying to recover. Cause: ");
|
||||||
msg.append(ex instanceof JMSException ? JmsUtils.buildExceptionMessage((JMSException) ex) : ex.getMessage());
|
msg.append(ex instanceof JMSException jmsException ? JmsUtils.buildExceptionMessage(jmsException) :
|
||||||
|
ex.getMessage());
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.warn(msg, ex);
|
logger.warn(msg, ex);
|
||||||
}
|
}
|
||||||
@@ -990,14 +991,15 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
if (ex instanceof JMSException) {
|
if (ex instanceof JMSException jmsException) {
|
||||||
invokeExceptionListener((JMSException) ex);
|
invokeExceptionListener(jmsException);
|
||||||
}
|
}
|
||||||
StringBuilder msg = new StringBuilder();
|
StringBuilder msg = new StringBuilder();
|
||||||
msg.append("Could not refresh JMS Connection for destination '");
|
msg.append("Could not refresh JMS Connection for destination '");
|
||||||
msg.append(getDestinationDescription()).append("' - retrying using ");
|
msg.append(getDestinationDescription()).append("' - retrying using ");
|
||||||
msg.append(execution).append(". Cause: ");
|
msg.append(execution).append(". Cause: ");
|
||||||
msg.append(ex instanceof JMSException ? JmsUtils.buildExceptionMessage((JMSException) ex) : ex.getMessage());
|
msg.append(ex instanceof JMSException jmsException ? JmsUtils.buildExceptionMessage(jmsException) :
|
||||||
|
ex.getMessage());
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.error(msg, ex);
|
logger.error(msg, ex);
|
||||||
}
|
}
|
||||||
@@ -1026,8 +1028,8 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
|
|||||||
String destName = getDestinationName();
|
String destName = getDestinationName();
|
||||||
if (destName != null) {
|
if (destName != null) {
|
||||||
DestinationResolver destResolver = getDestinationResolver();
|
DestinationResolver destResolver = getDestinationResolver();
|
||||||
if (destResolver instanceof CachingDestinationResolver) {
|
if (destResolver instanceof CachingDestinationResolver cachingResolver) {
|
||||||
((CachingDestinationResolver) destResolver).removeFromCache(destName);
|
cachingResolver.removeFromCache(destName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,8 +180,8 @@ public class JmsMessageEndpointManager extends GenericMessageEndpointManager
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setupMessageListener(Object messageListener) {
|
public void setupMessageListener(Object messageListener) {
|
||||||
if (messageListener instanceof MessageListener) {
|
if (messageListener instanceof MessageListener msgListener) {
|
||||||
setMessageListener((MessageListener) messageListener);
|
setMessageListener(msgListener);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new IllegalArgumentException("Unsupported message listener '" +
|
throw new IllegalArgumentException("Unsupported message listener '" +
|
||||||
@@ -203,8 +203,8 @@ public class JmsMessageEndpointManager extends GenericMessageEndpointManager
|
|||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public DestinationResolver getDestinationResolver() {
|
public DestinationResolver getDestinationResolver() {
|
||||||
if (this.activationSpecFactory instanceof StandardJmsActivationSpecFactory) {
|
if (this.activationSpecFactory instanceof StandardJmsActivationSpecFactory standardFactory) {
|
||||||
return ((StandardJmsActivationSpecFactory) this.activationSpecFactory).getDestinationResolver();
|
return standardFactory.getDestinationResolver();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -269,41 +269,41 @@ public abstract class JmsUtils {
|
|||||||
public static JmsException convertJmsAccessException(JMSException ex) {
|
public static JmsException convertJmsAccessException(JMSException ex) {
|
||||||
Assert.notNull(ex, "JMSException must not be null");
|
Assert.notNull(ex, "JMSException must not be null");
|
||||||
|
|
||||||
if (ex instanceof jakarta.jms.IllegalStateException) {
|
if (ex instanceof jakarta.jms.IllegalStateException jakartaISE) {
|
||||||
return new org.springframework.jms.IllegalStateException((jakarta.jms.IllegalStateException) ex);
|
return new org.springframework.jms.IllegalStateException(jakartaISE);
|
||||||
}
|
}
|
||||||
if (ex instanceof jakarta.jms.InvalidClientIDException) {
|
if (ex instanceof jakarta.jms.InvalidClientIDException jakartaICIDE) {
|
||||||
return new InvalidClientIDException((jakarta.jms.InvalidClientIDException) ex);
|
return new InvalidClientIDException(jakartaICIDE);
|
||||||
}
|
}
|
||||||
if (ex instanceof jakarta.jms.InvalidDestinationException) {
|
if (ex instanceof jakarta.jms.InvalidDestinationException jakartaIDE) {
|
||||||
return new InvalidDestinationException((jakarta.jms.InvalidDestinationException) ex);
|
return new InvalidDestinationException(jakartaIDE);
|
||||||
}
|
}
|
||||||
if (ex instanceof jakarta.jms.InvalidSelectorException) {
|
if (ex instanceof jakarta.jms.InvalidSelectorException jakartaISE) {
|
||||||
return new InvalidSelectorException((jakarta.jms.InvalidSelectorException) ex);
|
return new InvalidSelectorException(jakartaISE);
|
||||||
}
|
}
|
||||||
if (ex instanceof jakarta.jms.JMSSecurityException) {
|
if (ex instanceof jakarta.jms.JMSSecurityException jakartaJMSSE) {
|
||||||
return new JmsSecurityException((jakarta.jms.JMSSecurityException) ex);
|
return new JmsSecurityException(jakartaJMSSE);
|
||||||
}
|
}
|
||||||
if (ex instanceof jakarta.jms.MessageEOFException) {
|
if (ex instanceof jakarta.jms.MessageEOFException jakartaMEOFE) {
|
||||||
return new MessageEOFException((jakarta.jms.MessageEOFException) ex);
|
return new MessageEOFException(jakartaMEOFE);
|
||||||
}
|
}
|
||||||
if (ex instanceof jakarta.jms.MessageFormatException) {
|
if (ex instanceof jakarta.jms.MessageFormatException jakartaMFE) {
|
||||||
return new MessageFormatException((jakarta.jms.MessageFormatException) ex);
|
return new MessageFormatException(jakartaMFE);
|
||||||
}
|
}
|
||||||
if (ex instanceof jakarta.jms.MessageNotReadableException) {
|
if (ex instanceof jakarta.jms.MessageNotReadableException jakartaMNRE) {
|
||||||
return new MessageNotReadableException((jakarta.jms.MessageNotReadableException) ex);
|
return new MessageNotReadableException(jakartaMNRE);
|
||||||
}
|
}
|
||||||
if (ex instanceof jakarta.jms.MessageNotWriteableException) {
|
if (ex instanceof jakarta.jms.MessageNotWriteableException jakartaMNWE) {
|
||||||
return new MessageNotWriteableException((jakarta.jms.MessageNotWriteableException) ex);
|
return new MessageNotWriteableException(jakartaMNWE);
|
||||||
}
|
}
|
||||||
if (ex instanceof jakarta.jms.ResourceAllocationException) {
|
if (ex instanceof jakarta.jms.ResourceAllocationException jakartaRAE) {
|
||||||
return new ResourceAllocationException((jakarta.jms.ResourceAllocationException) ex);
|
return new ResourceAllocationException(jakartaRAE);
|
||||||
}
|
}
|
||||||
if (ex instanceof jakarta.jms.TransactionInProgressException) {
|
if (ex instanceof jakarta.jms.TransactionInProgressException jakartaTIPE) {
|
||||||
return new TransactionInProgressException((jakarta.jms.TransactionInProgressException) ex);
|
return new TransactionInProgressException(jakartaTIPE);
|
||||||
}
|
}
|
||||||
if (ex instanceof jakarta.jms.TransactionRolledBackException) {
|
if (ex instanceof jakarta.jms.TransactionRolledBackException jakartaTRBE) {
|
||||||
return new TransactionRolledBackException((jakarta.jms.TransactionRolledBackException) ex);
|
return new TransactionRolledBackException(jakartaTRBE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// fallback
|
// fallback
|
||||||
|
|||||||
@@ -65,9 +65,9 @@ public class SimpleJmsHeaderMapper extends AbstractHeaderMapper<Message> impleme
|
|||||||
if (jmsCorrelationId instanceof Number) {
|
if (jmsCorrelationId instanceof Number) {
|
||||||
jmsCorrelationId = jmsCorrelationId.toString();
|
jmsCorrelationId = jmsCorrelationId.toString();
|
||||||
}
|
}
|
||||||
if (jmsCorrelationId instanceof String) {
|
if (jmsCorrelationId instanceof String correlationId) {
|
||||||
try {
|
try {
|
||||||
jmsMessage.setJMSCorrelationID((String) jmsCorrelationId);
|
jmsMessage.setJMSCorrelationID(correlationId);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
logger.debug("Failed to set JMSCorrelationID - skipping", ex);
|
logger.debug("Failed to set JMSCorrelationID - skipping", ex);
|
||||||
|
|||||||
@@ -348,11 +348,11 @@ public class MappingJackson2MessageConverter implements SmartMessageConverter, B
|
|||||||
* Convenience method to dispatch to converters for individual message types.
|
* Convenience method to dispatch to converters for individual message types.
|
||||||
*/
|
*/
|
||||||
private Object convertToObject(Message message, JavaType targetJavaType) throws JMSException, IOException {
|
private Object convertToObject(Message message, JavaType targetJavaType) throws JMSException, IOException {
|
||||||
if (message instanceof TextMessage) {
|
if (message instanceof TextMessage textMessage) {
|
||||||
return convertFromTextMessage((TextMessage) message, targetJavaType);
|
return convertFromTextMessage(textMessage, targetJavaType);
|
||||||
}
|
}
|
||||||
else if (message instanceof BytesMessage) {
|
else if (message instanceof BytesMessage bytesMessage) {
|
||||||
return convertFromBytesMessage((BytesMessage) message, targetJavaType);
|
return convertFromBytesMessage(bytesMessage, targetJavaType);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return convertFromMessage(message, targetJavaType);
|
return convertFromMessage(message, targetJavaType);
|
||||||
@@ -474,11 +474,11 @@ public class MappingJackson2MessageConverter implements SmartMessageConverter, B
|
|||||||
}
|
}
|
||||||
return extractViewClass(annotation, conversionHint);
|
return extractViewClass(annotation, conversionHint);
|
||||||
}
|
}
|
||||||
else if (conversionHint instanceof JsonView) {
|
else if (conversionHint instanceof JsonView jsonView) {
|
||||||
return extractViewClass((JsonView) conversionHint, conversionHint);
|
return extractViewClass(jsonView, conversionHint);
|
||||||
}
|
}
|
||||||
else if (conversionHint instanceof Class) {
|
else if (conversionHint instanceof Class<?> clazz) {
|
||||||
return (Class<?>) conversionHint;
|
return clazz;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public class MarshallingMessageConverter implements MessageConverter, Initializi
|
|||||||
*/
|
*/
|
||||||
public MarshallingMessageConverter(Marshaller marshaller) {
|
public MarshallingMessageConverter(Marshaller marshaller) {
|
||||||
Assert.notNull(marshaller, "Marshaller must not be null");
|
Assert.notNull(marshaller, "Marshaller must not be null");
|
||||||
if (!(marshaller instanceof Unmarshaller)) {
|
if (!(marshaller instanceof Unmarshaller _unmarshaller)) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Marshaller [" + marshaller + "] does not implement the Unmarshaller " +
|
"Marshaller [" + marshaller + "] does not implement the Unmarshaller " +
|
||||||
"interface. Please set an Unmarshaller explicitly by using the " +
|
"interface. Please set an Unmarshaller explicitly by using the " +
|
||||||
@@ -89,7 +89,7 @@ public class MarshallingMessageConverter implements MessageConverter, Initializi
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.marshaller = marshaller;
|
this.marshaller = marshaller;
|
||||||
this.unmarshaller = (Unmarshaller) marshaller;
|
this.unmarshaller = _unmarshaller;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import org.springframework.util.ObjectUtils;
|
|||||||
* a Serializable object to a {@link jakarta.jms.ObjectMessage} (or vice versa).
|
* a Serializable object to a {@link jakarta.jms.ObjectMessage} (or vice versa).
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Sam Brannen
|
||||||
* @since 1.1
|
* @since 1.1
|
||||||
* @see org.springframework.jms.core.JmsTemplate#convertAndSend
|
* @see org.springframework.jms.core.JmsTemplate#convertAndSend
|
||||||
* @see org.springframework.jms.core.JmsTemplate#receiveAndConvert
|
* @see org.springframework.jms.core.JmsTemplate#receiveAndConvert
|
||||||
@@ -59,20 +60,20 @@ public class SimpleMessageConverter implements MessageConverter {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
|
public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
|
||||||
if (object instanceof Message) {
|
if (object instanceof Message message) {
|
||||||
return (Message) object;
|
return message;
|
||||||
}
|
}
|
||||||
else if (object instanceof String) {
|
else if (object instanceof String text) {
|
||||||
return createMessageForString((String) object, session);
|
return createMessageForString(text, session);
|
||||||
}
|
}
|
||||||
else if (object instanceof byte[]) {
|
else if (object instanceof byte[] bytes) {
|
||||||
return createMessageForByteArray((byte[]) object, session);
|
return createMessageForByteArray(bytes, session);
|
||||||
}
|
}
|
||||||
else if (object instanceof Map) {
|
else if (object instanceof Map<?, ?> map) {
|
||||||
return createMessageForMap((Map<? ,?>) object, session);
|
return createMessageForMap(map, session);
|
||||||
}
|
}
|
||||||
else if (object instanceof Serializable) {
|
else if (object instanceof Serializable serializable) {
|
||||||
return createMessageForSerializable(((Serializable) object), session);
|
return createMessageForSerializable(serializable, session);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new MessageConversionException("Cannot convert object of type [" +
|
throw new MessageConversionException("Cannot convert object of type [" +
|
||||||
@@ -93,17 +94,17 @@ public class SimpleMessageConverter implements MessageConverter {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Object fromMessage(Message message) throws JMSException, MessageConversionException {
|
public Object fromMessage(Message message) throws JMSException, MessageConversionException {
|
||||||
if (message instanceof TextMessage) {
|
if (message instanceof TextMessage textMessage) {
|
||||||
return extractStringFromMessage((TextMessage) message);
|
return extractStringFromMessage(textMessage);
|
||||||
}
|
}
|
||||||
else if (message instanceof BytesMessage) {
|
else if (message instanceof BytesMessage bytesMessage) {
|
||||||
return extractByteArrayFromMessage((BytesMessage) message);
|
return extractByteArrayFromMessage(bytesMessage);
|
||||||
}
|
}
|
||||||
else if (message instanceof MapMessage) {
|
else if (message instanceof MapMessage mapMessage) {
|
||||||
return extractMapFromMessage((MapMessage) message);
|
return extractMapFromMessage(mapMessage);
|
||||||
}
|
}
|
||||||
else if (message instanceof ObjectMessage) {
|
else if (message instanceof ObjectMessage objectMessage) {
|
||||||
return extractSerializableFromMessage((ObjectMessage) message);
|
return extractSerializableFromMessage(objectMessage);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return message;
|
return message;
|
||||||
@@ -149,11 +150,11 @@ public class SimpleMessageConverter implements MessageConverter {
|
|||||||
MapMessage message = session.createMapMessage();
|
MapMessage message = session.createMapMessage();
|
||||||
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
||||||
Object key = entry.getKey();
|
Object key = entry.getKey();
|
||||||
if (!(key instanceof String)) {
|
if (!(key instanceof String str)) {
|
||||||
throw new MessageConversionException("Cannot convert non-String key of type [" +
|
throw new MessageConversionException("Cannot convert non-String key of type [" +
|
||||||
ObjectUtils.nullSafeClassName(key) + "] to JMS MapMessage entry");
|
ObjectUtils.nullSafeClassName(key) + "] to JMS MapMessage entry");
|
||||||
}
|
}
|
||||||
message.setObject((String) key, entry.getValue());
|
message.setObject(str, entry.getValue());
|
||||||
}
|
}
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import org.springframework.util.Assert;
|
|||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
|
* @author Sam Brannen
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
* @param <T> the message payload type
|
* @param <T> the message payload type
|
||||||
* @see GenericMessage
|
* @see GenericMessage
|
||||||
@@ -153,14 +154,14 @@ public final class MessageBuilder<T> {
|
|||||||
return this.providedMessage;
|
return this.providedMessage;
|
||||||
}
|
}
|
||||||
MessageHeaders headersToUse = this.headerAccessor.toMessageHeaders();
|
MessageHeaders headersToUse = this.headerAccessor.toMessageHeaders();
|
||||||
if (this.payload instanceof Throwable) {
|
if (this.payload instanceof Throwable throwable) {
|
||||||
if (this.providedMessage != null && this.providedMessage instanceof ErrorMessage) {
|
if (this.providedMessage != null && this.providedMessage instanceof ErrorMessage errorMessage) {
|
||||||
Message<?> message = ((ErrorMessage) this.providedMessage).getOriginalMessage();
|
Message<?> message = errorMessage.getOriginalMessage();
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
return (Message<T>) new ErrorMessage((Throwable) this.payload, headersToUse, message);
|
return (Message<T>) new ErrorMessage(throwable, headersToUse, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (Message<T>) new ErrorMessage((Throwable) this.payload, headersToUse);
|
return (Message<T>) new ErrorMessage(throwable, headersToUse);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return new GenericMessage<>(this.payload, headersToUse);
|
return new GenericMessage<>(this.payload, headersToUse);
|
||||||
@@ -203,8 +204,8 @@ public final class MessageBuilder<T> {
|
|||||||
public static <T> Message<T> createMessage(@Nullable T payload, MessageHeaders messageHeaders) {
|
public static <T> Message<T> createMessage(@Nullable T payload, MessageHeaders messageHeaders) {
|
||||||
Assert.notNull(payload, "Payload must not be null");
|
Assert.notNull(payload, "Payload must not be null");
|
||||||
Assert.notNull(messageHeaders, "MessageHeaders must not be null");
|
Assert.notNull(messageHeaders, "MessageHeaders must not be null");
|
||||||
if (payload instanceof Throwable) {
|
if (payload instanceof Throwable throwable) {
|
||||||
return (Message<T>) new ErrorMessage((Throwable) payload, messageHeaders);
|
return (Message<T>) new ErrorMessage(throwable, messageHeaders);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return new GenericMessage<>(payload, messageHeaders);
|
return new GenericMessage<>(payload, messageHeaders);
|
||||||
|
|||||||
Reference in New Issue
Block a user