diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnectionFactory.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnectionFactory.java index ef3eaa5719..c6d764581a 100644 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnectionFactory.java +++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnectionFactory.java @@ -958,7 +958,9 @@ public class ActiveMQConnectionFactory extends JNDIStorable implements Connectio @Override protected void finalize() throws Throwable { try { - serverLocator.close(); + if (serverLocator != null) { + serverLocator.close(); + } } catch (Exception e) { e.printStackTrace(); //not much we can do here diff --git a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRALogger.java b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRALogger.java index 455d8aa024..e03a28e0a8 100644 --- a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRALogger.java +++ b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRALogger.java @@ -47,9 +47,11 @@ import javax.jms.IllegalStateException; public interface ActiveMQRALogger extends BasicLogger { /** - * The default logger. + * The default logger. Note this uses ActiveMQRALogger.class.getName() instead of ActiveMQRALogger.class.getPackage().getName() + * like the other loggers, this is because some Application Servers use introspection to identify properties which can + * sometimes use a classloader when the rar is uploaded and its possible getpackage() can return null */ - ActiveMQRALogger LOGGER = Logger.getMessageLogger(ActiveMQRALogger.class, ActiveMQRALogger.class.getPackage().getName()); + ActiveMQRALogger LOGGER = Logger.getMessageLogger(ActiveMQRALogger.class, ActiveMQRALogger.class.getName()); @LogMessage(level = Logger.Level.INFO) @Message(id = 151000, value = "awaiting topic/queue creation {0}", format = Message.Format.MESSAGE_FORMAT) diff --git a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRAMCFProperties.java b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRAMCFProperties.java index f6dc92bdca..3217f529aa 100644 --- a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRAMCFProperties.java +++ b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRAMCFProperties.java @@ -39,7 +39,16 @@ public class ActiveMQRAMCFProperties extends ConnectionFactoryProperties impleme * The topic type */ private static final String TOPIC_TYPE = Topic.class.getName(); - protected boolean allowLocalTransactions; + /** + * If true then for outbound connections a local tx will be used if no JTA is configured + */ + private boolean allowLocalTransactions; + + /** + * If true then for outbound connections will always assume that they are part of a transaction. + * This is helpful when running in containers where access to the Transaction manager can't be configured + */ + private boolean inJtaTransaction; private String strConnectorClassName; @@ -176,4 +185,12 @@ public class ActiveMQRAMCFProperties extends ConnectionFactoryProperties impleme public void setAllowLocalTransactions(boolean allowLocalTransactions) { this.allowLocalTransactions = allowLocalTransactions; } + + public boolean isInJtaTransaction() { + return inJtaTransaction; + } + + public void setInJtaTransaction(boolean inJtaTransaction) { + this.inJtaTransaction = inJtaTransaction; + } } diff --git a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRAManagedConnectionFactory.java b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRAManagedConnectionFactory.java index a93965cac8..2154a4aa51 100644 --- a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRAManagedConnectionFactory.java +++ b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRAManagedConnectionFactory.java @@ -63,11 +63,16 @@ public final class ActiveMQRAManagedConnectionFactory implements ManagedConnecti */ private ActiveMQConnectionFactory recoveryConnectionFactory; - /* - * The resource recovery if there is one - * */ + /** + * The resource recovery if there is one + */ private XARecoveryConfig resourceRecovery; + /** + * Used to configure whether the connection should be part of the JTA TX. This is when the RA doesn not have access to the Transaction manager to deduct whether this is the case. + */ + private boolean inJtaTransaction; + /** * Constructor */ @@ -508,6 +513,13 @@ public final class ActiveMQRAManagedConnectionFactory implements ManagedConnecti mcfProperties.setMinLargeMessageSize(minLargeMessageSize); } + /** + * A getter as well as a setter for those servers that use introspection + */ + public Boolean getBlockOnAcknowledge() { + return mcfProperties.isBlockOnAcknowledge(); + } + public Boolean isBlockOnAcknowledge() { return mcfProperties.isBlockOnAcknowledge(); } @@ -516,6 +528,13 @@ public final class ActiveMQRAManagedConnectionFactory implements ManagedConnecti mcfProperties.setBlockOnAcknowledge(blockOnAcknowledge); } + /** + * A getter as well as a setter for those servers that use introspection + */ + public Boolean getBlockOnNonDurableSend() { + return mcfProperties.isBlockOnNonDurableSend(); + } + public Boolean isBlockOnNonDurableSend() { return mcfProperties.isBlockOnNonDurableSend(); } @@ -524,6 +543,13 @@ public final class ActiveMQRAManagedConnectionFactory implements ManagedConnecti mcfProperties.setBlockOnNonDurableSend(blockOnNonDurableSend); } + /** + * A getter as well as a setter for those servers that use introspection + */ + public Boolean getBlockOnDurableSend() { + return mcfProperties.isBlockOnDurableSend(); + } + public Boolean isBlockOnDurableSend() { return mcfProperties.isBlockOnDurableSend(); } @@ -532,6 +558,13 @@ public final class ActiveMQRAManagedConnectionFactory implements ManagedConnecti mcfProperties.setBlockOnDurableSend(blockOnDurableSend); } + /** + * A getter as well as a setter for those servers that use introspection + */ + public Boolean getAutoGroup() { + return mcfProperties.isAutoGroup(); + } + public Boolean isAutoGroup() { return mcfProperties.isAutoGroup(); } @@ -540,6 +573,13 @@ public final class ActiveMQRAManagedConnectionFactory implements ManagedConnecti mcfProperties.setAutoGroup(autoGroup); } + /** + * A getter as well as a setter for those servers that use introspection + */ + public Boolean getPreAcknowledge() { + return mcfProperties.isPreAcknowledge(); + } + public Boolean isPreAcknowledge() { return mcfProperties.isPreAcknowledge(); } @@ -572,6 +612,13 @@ public final class ActiveMQRAManagedConnectionFactory implements ManagedConnecti mcfProperties.setReconnectAttempts(reconnectAttempts); } + /** + * A getter as well as a setter for those servers that use introspection + */ + public Boolean getUseGlobalPools() { + return mcfProperties.isUseGlobalPools(); + } + public Boolean isUseGlobalPools() { return mcfProperties.isUseGlobalPools(); } @@ -580,6 +627,13 @@ public final class ActiveMQRAManagedConnectionFactory implements ManagedConnecti mcfProperties.setUseGlobalPools(useGlobalPools); } + /** + * A getter as well as a setter for those servers that use introspection + */ + public Boolean getCacheDestinations() { + return mcfProperties.isCacheDestinations(); + } + public Boolean isCacheDestinations() { return mcfProperties.isCacheDestinations(); } @@ -588,6 +642,13 @@ public final class ActiveMQRAManagedConnectionFactory implements ManagedConnecti mcfProperties.setCacheDestinations(cacheDestinations); } + /** + * A getter as well as a setter for those servers that use introspection + */ + public Boolean getEnable1xPrefixes() { + return mcfProperties.isEnable1xPrefixes(); + } + public Boolean isEnable1xPrefixes() { return mcfProperties.isEnable1xPrefixes(); } @@ -612,6 +673,13 @@ public final class ActiveMQRAManagedConnectionFactory implements ManagedConnecti mcfProperties.setThreadPoolMaxSize(threadPoolMaxSize); } + /** + * A getter as well as a setter for those servers that use introspection + */ + public Boolean getHA() { + return mcfProperties.isHA(); + } + public Boolean isHA() { return mcfProperties.isHA(); } @@ -620,10 +688,32 @@ public final class ActiveMQRAManagedConnectionFactory implements ManagedConnecti mcfProperties.setAllowLocalTransactions(allowLocalTransactions); } + /** + * A getter as well as a setter for those servers that use introspection + */ + public Boolean getAllowLocalTransactions() { + return mcfProperties.isAllowLocalTransactions(); + } + public Boolean isAllowLocalTransactions() { return mcfProperties.isAllowLocalTransactions(); } + /** + * A getter as well as a setter for those servers that use introspection + */ + public Boolean getInJtaTransaction() { + return mcfProperties.isInJtaTransaction(); + } + + public Boolean isInJtaTransaction() { + return mcfProperties.isInJtaTransaction(); + } + + public void setInJtaTransaction(Boolean inJtaTransaction) { + mcfProperties.setInJtaTransaction(inJtaTransaction); + } + public void setHA(Boolean ha) { mcfProperties.setHA(ha); } diff --git a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRASessionFactoryImpl.java b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRASessionFactoryImpl.java index 4073438b97..f35cb056fa 100644 --- a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRASessionFactoryImpl.java +++ b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRASessionFactoryImpl.java @@ -816,7 +816,7 @@ public final class ActiveMQRASessionFactoryImpl extends ActiveMQConnectionForCon //Both arguments {@code transacted} and {@code acknowledgeMode} are ignored. // fix of ARTEMIS-1669 - when a JMSConnectionFactoryDefinition annotation with the transactional attribute set to false="false" is set // then it should not be included in any JTA transaction and behave like that there is no JTA transaction. - if (!mcf.isIgnoreJTA() && inJtaTransaction()) { + if (!mcf.isIgnoreJTA() && (inJtaTransaction() || mcf.isInJtaTransaction())) { transacted = true; //from getAcknowledgeMode // If the session is transacted, returns SESSION_TRANSACTED. diff --git a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ConnectionFactoryProperties.java b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ConnectionFactoryProperties.java index 9cb783a951..ca07ed94af 100644 --- a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ConnectionFactoryProperties.java +++ b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ConnectionFactoryProperties.java @@ -750,12 +750,15 @@ public class ConnectionFactoryProperties implements ConnectionFactoryOptions { return hasBeenUpdated; } + /* + * This is here just for backward compatibility and not used + * */ public void setEnableSharedClientID(boolean enable) { this.enableSharedClientID = enable; } public boolean isEnableSharedClientID() { - return enableSharedClientID; + return enableSharedClientID != null ? enableSharedClientID : false; } @Override diff --git a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/inflow/ActiveMQActivationSpec.java b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/inflow/ActiveMQActivationSpec.java index e2b67bf673..af111e7895 100644 --- a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/inflow/ActiveMQActivationSpec.java +++ b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/inflow/ActiveMQActivationSpec.java @@ -143,7 +143,8 @@ public class ActiveMQActivationSpec extends ConnectionFactoryProperties implemen logger.trace("constructor()"); } - ra = null; + // we create an Adapter here but only for Application Servers that do introspection on loading to avoid an NPE + ra = new ActiveMQResourceAdapter(); destination = null; destinationType = null; messageSelector = null; diff --git a/examples/features/sub-modules/artemis-ra-rar/pom.xml b/examples/features/sub-modules/artemis-ra-rar/pom.xml index 315b567bfa..4cfc0cd930 100644 --- a/examples/features/sub-modules/artemis-ra-rar/pom.xml +++ b/examples/features/sub-modules/artemis-ra-rar/pom.xml @@ -50,8 +50,12 @@ under the License. artemis-jms-client - org.apache.geronimo.specs - geronimo-jms_2.0_spec + jakarta.jms + jakarta.jms-api + + + jakarta.json + jakarta.json-api org.apache.geronimo.specs @@ -63,11 +67,35 @@ under the License. org.apache.activemq artemis-ra ${project.version} + + + jakarta.transaction + jakarta.transaction-api + + + jakarta.jms + jakarta.jms-api + + org.apache.activemq artemis-jms-server ${project.version} + + + jakarta.transaction + jakarta.transaction-api + + + jakarta.jms + jakarta.jms-api + + + jakarta.json + jakarta.json-api + + org.apache.activemq @@ -78,6 +106,10 @@ under the License. org.apache.activemq artemis-core-client + + jakarta.json + jakarta.json-api + diff --git a/examples/features/sub-modules/artemis-ra-rar/src/main/resources/ra.xml b/examples/features/sub-modules/artemis-ra-rar/src/main/resources/ra.xml index 3240be62be..a3500bd7a0 100644 --- a/examples/features/sub-modules/artemis-ra-rar/src/main/resources/ra.xml +++ b/examples/features/sub-modules/artemis-ra-rar/src/main/resources/ra.xml @@ -8,11 +8,10 @@ http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd" version="1.5"> - ActiveMQ Artemis 2.0 Resource Adapter - ActiveMQ Artemis 2.0 Resource Adapter - + ArtemisRA + ActiveMQ Artemis Resource Adapter Apache Software Foundation - JMS 1.1 Server + JMS 2.0 Server 1.0 @@ -44,7 +43,7 @@ ConnectorClassName java.lang.String - org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory + org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory The transport configuration. These values must be in the form of key=val;key=val;, @@ -53,217 +52,182 @@ ConnectionParameters java.lang.String - server-id=0 + host=localhost,port=61616 - @@ -276,6 +240,12 @@ java.lang.String javax.jms.Queue + + Whether or not to participate in a JTA transaction, this is used if the RA does not have access to the Transaction Manager + InJtaTransaction + java.lang.Boolean + true + Try to obtain a lock within specified number of seconds; less than or equal to 0 disable this functionality UseTryLock diff --git a/pom.xml b/pom.xml index 953db6c503..422906b750 100644 --- a/pom.xml +++ b/pom.xml @@ -93,7 +93,7 @@ 2.9.0 1.16 30.1-jre - 3.4.0.Final + 3.4.2.Final 9.4.40.v20210413 3.6.13.Final 2.6.0