Initial Contribution
Signed-off-by: Vinay Vishal <vinay.vishal@oracle.com>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/README
new file mode 100644
index 0000000..633f9b5
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/README
@@ -0,0 +1,12 @@
+- Test support for enabled beans' classes deployed as a standalone RAR
+[test originally from connector1.5 test in Connectors developer tests]
+section 12.1. Bean archives of JSR 299 spec:
+
+"Bean classes of enabled beans must be deployed in bean archives.
+• A library jar, EJB jar, application client jar or rar archive is a
+bean archive if it has a file named beans.xml in the META-INF
+directory."
+
+In this test, a standalone RAR has a TestCDIBean Bean class. This is injected into a MDB in another ejb-jar in the EAR.
+
+[Note: This test doesn't seem to work now -- need to investigate]
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/META-INF/application.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/META-INF/application.xml
new file mode 100644
index 0000000..fe9b32e
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/META-INF/application.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN' 'http://java.sun.com/dtd/application_1_3.dtd'>
+<!--
+
+ Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<application>
+ <display-name>GenericMessageDrivenBean</display-name>
+ <description>Application description</description>
+ <module>
+ <ejb>simplemdb-ejb.jar</ejb>
+ </module>
+ <module>
+ <java>simplemdb-client.jar</java>
+ </module>
+</application>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/build.xml
new file mode 100644
index 0000000..210abae
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/build.xml
@@ -0,0 +1,85 @@
+<!--
+
+ Copyright (c) 2002, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<!DOCTYPE project [
+ <!ENTITY common SYSTEM "../../../../../config/common.xml">
+ <!ENTITY testcommon SYSTEM "../../../../../config/properties.xml">
+ <!ENTITY database SYSTEM "../../../config/database.xml">
+]>
+
+<project name="connector1.5 MDB" default="all" basedir=".">
+
+ <property name="j2ee.home" value="../../.."/>
+ <property name="earfile" value="simplemdb.ear"/>
+
+
+ <!-- include common.xml and testcommon.xml -->
+ &database;
+ &common;
+ &testcommon;
+
+ <target name="all" depends="init-common, clean-common">
+ <ant dir="src" inheritAll="false" target="all"/>
+ <antcall target="ear-common">
+ <param name="appname" value="simplemdb"/>
+ <param name="application.xml" value="META-INF/application.xml"/>
+ </antcall>
+ </target>
+
+ <target name="setupJdbc" depends="init-common">
+ <antcall target="create-jdbc-conpool-connector">
+ <param name="db.class" value="org.apache.derby.jdbc.ClientXADataSource"/>
+ <param name="jdbc.conpool.name" value="jdbc-pointbase-pool1"/>
+ <param name="jdbc.resource.type" value="javax.sql.XADataSource"/>
+ </antcall>
+
+ <antcall target="create-jdbc-resource-common">
+ <param name="jdbc.conpool.name" value="jdbc-pointbase-pool1"/>
+ <param name="jdbc.resource.name" value="jdbc/XAPointbase"/>
+ </antcall>
+
+ <antcall target="execute-sql-connector">
+ <param name="sql.file" value="createdb.sql"/>
+ </antcall>
+ </target>
+
+ <target name="unsetJdbc" depends="init-common">
+ <antcall target="delete-jdbc-resource-common">
+ <param name="jdbc.resource.name" value="jdbc/XAPointbase"/>
+ </antcall>
+ <antcall target="delete-jdbc-connpool-common">
+ <param name="jdbc.conpool.name" value="jdbc-pointbase-pool1"/>
+ </antcall>
+ </target>
+
+ <target name="deploy-ear" depends="init-common">
+ <antcall target="deploy-common">
+ <param name="appname" value="simplemdb"/>
+ </antcall>
+ </target>
+
+ <target name="undeploy" depends="init-common">
+ <antcall target="undeploy-common">
+ <param name="appname" value="simplemdb"/>
+ </antcall>
+ </target>
+
+ <target name="clean">
+ <antcall target="clean-common"/>
+ </target>
+</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/createdb.sql b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/createdb.sql
new file mode 100644
index 0000000..7d93610
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/createdb.sql
@@ -0,0 +1,2 @@
+drop table MESSAGES;
+create table MESSAGES (messageId CHAR(50), message varchar(80));
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/application-client.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/application-client.xml
new file mode 100644
index 0000000..75d2e9a
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/application-client.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE application-client PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.3//EN' 'http://java.sun.com/dtd/application-client_1_3.dtd'>
+<!--
+
+ Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<application-client>
+ <display-name>simplemdbClient</display-name>
+</application-client>
+
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/beans.xml
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/ejb-jar.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/ejb-jar.xml
new file mode 100644
index 0000000..4bdcc6f
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/ejb-jar.xml
@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+ http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"
+ version="2.1">
+ <display-name>Ejb1</display-name>
+ <enterprise-beans>
+ <message-driven>
+ <display-name>Generic_Message_Bean</display-name>
+ <ejb-name>GenericMessageBean</ejb-name>
+ <ejb-class>mdb.MyMessageBean</ejb-class>
+ <messaging-type>connector.MyMessageListener</messaging-type>
+ <transaction-type>Container</transaction-type>
+ <activation-config>
+ <activation-config-property>
+ <activation-config-property-name>
+ DestinationType
+ </activation-config-property-name>
+ <activation-config-property-value>
+ java.lang.String
+ </activation-config-property-value>
+ </activation-config-property>
+ <activation-config-property>
+ <activation-config-property-name>
+ TestProp
+ </activation-config-property-name>
+ <activation-config-property-value>
+ WrongValue
+ </activation-config-property-value>
+ </activation-config-property>
+ <!-- non-String activation spec property -->
+ <activation-config-property>
+ <activation-config-property-name>
+ TestIntegerProp
+ </activation-config-property-name>
+ <activation-config-property-value>
+ 1
+ </activation-config-property-value>
+ </activation-config-property>
+
+ </activation-config>
+ <resource-ref>
+ <description>description</description>
+ <res-ref-name>MyDB</res-ref-name>
+ <res-type>javax.sql.DataSource</res-type>
+ <res-auth>Container</res-auth>
+ <res-sharing-scope>Shareable</res-sharing-scope>
+ </resource-ref>
+ </message-driven>
+ <session>
+ <display-name>MyMessageChecker</display-name>
+ <ejb-name>MyMessageChecker</ejb-name>
+ <home>beans.MessageCheckerHome</home>
+ <remote>beans.MessageChecker</remote>
+ <ejb-class>beans.MessageCheckerEJB</ejb-class>
+ <session-type>Stateless</session-type>
+ <transaction-type>Container</transaction-type>
+ <env-entry>
+ <env-entry-name>user</env-entry-name>
+ <env-entry-type>java.lang.String</env-entry-type>
+ <env-entry-value>PBPUBLIC</env-entry-value>
+ </env-entry>
+ <env-entry>
+ <env-entry-name>password</env-entry-name>
+ <env-entry-type>java.lang.String</env-entry-type>
+ <env-entry-value>PBPUBLIC</env-entry-value>
+ </env-entry>
+ <resource-ref>
+ <res-ref-name>MyDB</res-ref-name>
+ <res-type>javax.sql.DataSource</res-type>
+ <res-auth>Container</res-auth>
+ <res-sharing-scope>Shareable</res-sharing-scope>
+ </resource-ref>
+ <resource-env-ref>
+ <resource-env-ref-name>eis/testAdmin</resource-env-ref-name>
+ <resource-env-ref-type>connector.MyAdminObject</resource-env-ref-type>
+ </resource-env-ref>
+ <security-identity>
+ <use-caller-identity/>
+ </security-identity>
+ </session>
+ </enterprise-beans>
+ <assembly-descriptor>
+ <container-transaction>
+ <method>
+ <ejb-name>GenericMessageBean</ejb-name>
+ <method-name>onMessage</method-name>
+ <method-params>
+ <method-param>java.lang.String</method-param>
+ </method-params>
+ </method>
+ <trans-attribute>Required</trans-attribute>
+ </container-transaction>
+ <container-transaction>
+ <method>
+ <ejb-name>MyMessageChecker</ejb-name>
+ <method-intf>Remote</method-intf>
+ <method-name>getMessageCount</method-name>
+ </method>
+ <trans-attribute>Required</trans-attribute>
+ </container-transaction>
+ </assembly-descriptor>
+</ejb-jar>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/sun-application-client.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/sun-application-client.xml
new file mode 100644
index 0000000..2b9166a
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/sun-application-client.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE sun-application-client PUBLIC "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 Application Client 1.3//EN" "http://www.sun.com/software/sunone/appserver/dtds/sun-application-client_1_3-0.dtd">
+<!--
+
+ Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<sun-application-client>
+</sun-application-client>
+
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/sun-ejb-jar.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/sun-ejb-jar.xml
new file mode 100644
index 0000000..42cd604
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/sun-ejb-jar.xml
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 EJB 2.0//EN" "http://www.sun.com/software/sun
+<!--
+
+ Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+one/appserver/dtds/sun-ejb-jar_2_0-0.dtd">
+
+
+<sun-ejb-jar>
+ <enterprise-beans>
+ <module-name>ejb.jar</module-name>
+ <unique-id>1</unique-id>
+ <ejb>
+ <ejb-name>GenericMessageBean</ejb-name>
+ <mdb-resource-adapter>
+ <resource-adapter-mid>generic-ra</resource-adapter-mid>
+ <activation-config>
+ <!-- override prop value -->
+ <activation-config-property>
+ <activation-config-property-name>
+ TestIntegerProp
+ </activation-config-property-name>
+ <activation-config-property-value>
+ 2
+ </activation-config-property-value>
+ </activation-config-property>
+ </activation-config>
+ </mdb-resource-adapter>
+ <ior-security-config>
+ <transport-config>
+ <integrity>supported</integrity>
+ <confidentiality>supported</confidentiality>
+ <establish-trust-in-target>supported</establish-trust-in-target>
+ <establish-trust-in-client>supported</establish-trust-in-client>
+ </transport-config>
+ <as-context>
+ <auth-method>username_password</auth-method>
+ <realm>default</realm>
+ <required>true</required>
+ </as-context>
+ <sas-context>
+ <caller-propagation>supported</caller-propagation>
+ </sas-context>
+ </ior-security-config>
+ <resource-ref>
+ <res-ref-name>MyDB</res-ref-name>
+ <jndi-name>jdbc/XAPointbase</jndi-name>
+ </resource-ref>
+ <gen-classes />
+ </ejb>
+ <ejb>
+ <ejb-name>MyMessageChecker</ejb-name>
+ <jndi-name>MyMessageChecker</jndi-name>
+ <ior-security-config>
+ <transport-config>
+ <integrity>supported</integrity>
+ <confidentiality>supported</confidentiality>
+ <establish-trust-in-target>supported</establish-trust-in-target>
+ <establish-trust-in-client>supported</establish-trust-in-client>
+ </transport-config>
+ <as-context>
+ <auth-method>username_password</auth-method>
+ <realm>default</realm>
+ <required>false</required>
+ </as-context>
+ <sas-context>
+ <caller-propagation>supported</caller-propagation>
+ </sas-context>
+ </ior-security-config>
+ <resource-ref>
+ <res-ref-name>MyDB</res-ref-name>
+ <jndi-name>jdbc/XAPointbase</jndi-name>
+ </resource-ref>
+ <resource-env-ref>
+ <resource-env-ref-name>eis/testAdmin</resource-env-ref-name>
+ <jndi-name>eis/testAdmin</jndi-name>
+ </resource-env-ref>
+ <gen-classes/>
+ </ejb>
+ </enterprise-beans>
+</sun-ejb-jar>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/beans/MessageChecker.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/beans/MessageChecker.java
new file mode 100644
index 0000000..48573f8
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/beans/MessageChecker.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package beans;
+
+import javax.ejb.EJBObject;
+import java.rmi.RemoteException;
+import java.sql.SQLException;
+
+public interface MessageChecker extends EJBObject {
+ int getMessageCount() throws RemoteException;
+ boolean done() throws RemoteException;
+ int expectedResults() throws RemoteException;
+ void notifyAndWait() throws RemoteException;
+}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/beans/MessageCheckerEJB.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/beans/MessageCheckerEJB.java
new file mode 100644
index 0000000..bdc3f62
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/beans/MessageCheckerEJB.java
@@ -0,0 +1,188 @@
+/*
+ * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package beans;
+
+import connector.MyAdminObject;
+import javax.rmi.PortableRemoteObject;
+import javax.ejb.SessionBean;
+import javax.ejb.SessionContext;
+import javax.ejb.EJBException;
+import javax.ejb.CreateException;
+import java.util.Properties;
+import java.util.Vector;
+import java.sql.*;
+import java.rmi.RemoteException;
+
+import javax.transaction.UserTransaction;
+import javax.naming.*;
+import javax.sql.*;
+
+public class MessageCheckerEJB implements SessionBean {
+
+ private int WAIT_TIME = 15;
+ private String user = "j2ee";
+ private String password = "j2ee";
+ private Properties beanProps = null;
+ private SessionContext sessionContext = null;
+ private Connection heldCon = null;
+ private MyAdminObject Controls;
+
+ public MessageCheckerEJB() {}
+
+ public void ejbCreate()
+ throws CreateException {
+ System.out.println("bean removed");
+ heldCon = null;
+ /*
+ if (holdConnection) {
+ try {
+ heldCon = getDBConnection();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ throw new CreateException("Error in ejbCreate");
+ }
+ }
+ */
+ }
+
+ public boolean done() {
+ return Controls.done();
+ }
+
+ public int expectedResults() {
+ return Controls.expectedResults();
+ }
+
+ public void notifyAndWait() {
+ try {
+ synchronized (Controls.getLockObject()) {
+ //Tell the resource adapter the client is ready to run
+ Controls.getLockObject().notifyAll();
+
+ debug("NOTIFIED... START WAITING");
+ //Wait until being told to read from the database
+ Controls.getLockObject().wait();
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ public int getMessageCount() {
+ try {
+ Connection con = getFreshConnection();
+ int count1 = getCount(con);
+ con.close();
+
+ /*
+ synchronized(Controls.getLockObject()) {
+ Controls.getLockObject().notify();
+ }
+ */
+
+ return count1;
+ } catch (Exception e) {
+ e.printStackTrace(System.out);
+ throw new EJBException(e);
+ }
+ }
+
+ private int getCount(Connection con) throws SQLException {
+ Statement stmt = con.createStatement();
+ int count = 0;
+ String messages = "";
+ ResultSet result = stmt.executeQuery(
+ "SELECT messageId, message "+ "FROM messages");
+ while (result.next()) {
+ count++;
+ messages = messages + " - " + result.getString("messageId")+" "+
+ result.getString("message") + "\n";
+ }
+ messages = messages + "count = " + count;
+ System.out.println(messages);
+ stmt.close();
+ return count;
+ }
+
+ public void setSessionContext(SessionContext context) {
+ sessionContext = context;
+ try {
+ Context ic = new InitialContext();
+ user = (String) ic.lookup("java:comp/env/user");
+ password = (String) ic.lookup("java:comp/env/password");
+ Controls = (MyAdminObject) ic.lookup("java:comp/env/eis/testAdmin");
+ System.out.println("CALLING INITILIZE ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]");
+ Controls.initialize();
+ System.out.println("CALLED INITILIZE ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]");
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ public void ejbRemove() {
+ System.out.println("bean removed");
+ }
+
+ public void ejbActivate() {
+ System.out.println("bean activated");
+ }
+
+ public void ejbPassivate() {
+ System.out.println("bean passivated");
+ }
+
+ private Connection getFreshConnection() throws Exception {
+ Connection oldHeldCon = heldCon;
+ heldCon = null;
+ Connection result = getDBConnection();
+ heldCon = oldHeldCon;
+ return result;
+ }
+
+ private Connection getDBConnection() throws Exception {
+ if (heldCon != null) return heldCon;
+ Connection con = null;
+ try {
+ Context ic = new InitialContext();
+ DataSource ds = (DataSource) ic.lookup("java:comp/env/MyDB");
+ debug("Looked up Datasource\n");
+ debug("Get JDBC connection, auto sign on");
+ con = ds.getConnection();
+
+ if (con != null) {
+ return con;
+ } else {
+ throw new Exception("Unable to get database connection ");
+ }
+ } catch (SQLException ex1) {
+ //ex1.printStackTrace();
+ throw ex1;
+ }
+ }
+
+ private void closeConnection(Connection con) throws SQLException {
+ if (heldCon != null) {
+ return;
+ } else {
+ con.close();
+ }
+ }
+
+ private void debug(String msg) {
+ System.out.println("[MessageCheckerEJB]:: -> " + msg);
+ }
+}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/beans/MessageCheckerHome.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/beans/MessageCheckerHome.java
new file mode 100644
index 0000000..4bcc578
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/beans/MessageCheckerHome.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package beans;
+
+import java.rmi.RemoteException;
+import javax.ejb.EJBHome;
+import javax.ejb.CreateException;
+
+public interface MessageCheckerHome extends EJBHome {
+ MessageChecker create() throws RemoteException, CreateException;
+ boolean done() throws RemoteException, CreateException;
+ int expectedResults() throws RemoteException, CreateException;
+ void notifyAndWait() throws RemoteException, CreateException;
+}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/build.properties
new file mode 100644
index 0000000..dad207b
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/build.properties
@@ -0,0 +1,21 @@
+<!--
+
+ Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+
+ejb-jar.xml=META-INF/ejb-jar.xml
+sun-ejb-jar.xml=META-INF/sun-ejb-jar.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/build.xml
new file mode 100644
index 0000000..24e1832
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/build.xml
@@ -0,0 +1,68 @@
+<!--
+
+ Copyright (c) 2002, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<!DOCTYPE project [
+ <!ENTITY common SYSTEM "../../../../../../config/common.xml">
+ <!ENTITY testcommon SYSTEM "../../../../../../config/properties.xml">
+]>
+
+<project name="connector1.5 MDB" default="all" basedir=".">
+
+ <property name="j2ee.home" value="../../../.."/>
+
+ <!-- include common.xml and testcommon.xml -->
+ &common;
+ &testcommon;
+
+ <target name="all" depends="init-common">
+ <antcall target="compile-common">
+ <param name="src" value="." />
+ <param name="s1astest.classpath" value="${s1astest.classpath}:../../ra/src/classes" />
+ </antcall>
+
+ <antcall target="ejb-jar-common">
+ <param name="ejb-jar.xml" value="META-INF/ejb-jar.xml" />
+ <param name="ejbjar.classes" value="mdb/*.class, beans/*.class, connector/*.class" />
+ <param name="beans.xml" value="META-INF/beans.xml" />
+ <param name="sun-ejb-jar.xml" value="META-INF/sun-ejb-jar.xml" />
+ <param name="appname" value="simplemdb" />
+ </antcall>
+
+ <antcall target="appclient-jar-common">
+ <param name="appname" value="simplemdb" />
+ <param name="application-client.xml" value="META-INF/application-client.xml" />
+ <param name="appclientjar.classes" value="mdb/*.class, beans/*.class, connector/*.class, client/Client.class" />
+ <param name="sun-application-client.xml" value="META-INF/sun-application-client.xml" />
+ </antcall>
+<!--
+ <jar jarfile="../ejb.jar" basedir="classes"
+ includes="mdb/*.class, beans/*.class, connector/*.class" >
+ <metainf dir="META-INF">
+ <include name="ejb-jar.xml"/>
+ <include name="sun-ejb-jar.xml"/>
+ </metainf>
+ </jar>
+-->
+ </target>
+
+ <target name="clean">
+ <antcall target="clean-classes-common">
+ <param name="build.classes.dir" value="classes" />
+ </antcall>
+ </target>
+</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/client/Client.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/client/Client.java
new file mode 100644
index 0000000..f551ce1
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/client/Client.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package client;
+
+import beans.*;
+import connector.*;
+import java.io.*;
+import java.util.*;
+import javax.naming.*;
+import javax.rmi.PortableRemoteObject;
+import com.sun.ejte.ccl.reporter.SimpleReporterAdapter;
+
+public class Client {
+
+ private static SimpleReporterAdapter stat =
+ new SimpleReporterAdapter("appserv-tests");
+
+ public Client (String[] args) {
+ //super(args);
+ }
+
+ public static void main(String[] args) {
+ Client client = new Client(args);
+ client.doTest();
+ }
+
+ public String doTest() {
+ stat.addDescription("This is to test connector 1.5 "+
+ "contracts.");
+
+ String res = "NOT RUN";
+ debug("doTest() ENTER...");
+ boolean pass = false;
+ try {
+ res = "ALL TESTS PASSED";
+ int testCount = 1;
+ while (!done()) {
+
+ notifyAndWait();
+ if (!done()) {
+ debug("Running...");
+ pass = checkResults(expectedResults());
+ debug("Got expected results = " + pass);
+
+ //do not continue if one test failed
+ if (!pass) {
+ res = "SOME TESTS FAILED";
+ stat.addStatus("ID Connector 1.5 test - " + testCount, stat.FAIL);
+ } else {
+ stat.addStatus("ID Connector 1.5 test - " + testCount, stat.PASS);
+ }
+ } else {
+ break;
+ }
+ testCount ++;
+ }
+
+ } catch (Exception ex) {
+ System.out.println("Importing transaction test failed.");
+ ex.printStackTrace();
+ res = "TEST FAILED";
+ }
+ stat.printSummary("connector1.5ID");
+
+
+ debug("EXITING... STATUS = " + res);
+ return res;
+ }
+
+ private boolean checkResults(int num) throws Exception {
+ Object o = (new InitialContext()).lookup("MyMessageChecker");
+ MessageCheckerHome home = (MessageCheckerHome)
+ PortableRemoteObject.narrow(o, MessageCheckerHome.class);
+ MessageChecker checker = home.create();
+ int result = checker.getMessageCount();
+ return result == num;
+ }
+
+ private boolean done() throws Exception {
+ Object o = (new InitialContext()).lookup("MyMessageChecker");
+ MessageCheckerHome home = (MessageCheckerHome)
+ PortableRemoteObject.narrow(o, MessageCheckerHome.class);
+ MessageChecker checker = home.create();
+ return checker.done();
+ }
+
+ private int expectedResults() throws Exception {
+ Object o = (new InitialContext()).lookup("MyMessageChecker");
+ MessageCheckerHome home = (MessageCheckerHome)
+ PortableRemoteObject.narrow(o, MessageCheckerHome.class);
+ MessageChecker checker = home.create();
+ return checker.expectedResults();
+ }
+
+ private void notifyAndWait() throws Exception {
+ Object o = (new InitialContext()).lookup("MyMessageChecker");
+ MessageCheckerHome home = (MessageCheckerHome)
+ PortableRemoteObject.narrow(o, MessageCheckerHome.class);
+ MessageChecker checker = home.create();
+ checker.notifyAndWait();
+ }
+
+
+ private void debug(String msg) {
+ System.out.println("[CLIENT]:: --> " + msg);
+ }
+}
+
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/client/MANIFEST.MF b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/client/MANIFEST.MF
new file mode 100644
index 0000000..179cd4d
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/client/MANIFEST.MF
@@ -0,0 +1,4 @@
+Manifest-Version: 1.0
+Created-By: 1.4.0 (Sun Microsystems Inc.)
+Main-Class: client.Client
+
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/connector/MyMessageListener.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/connector/MyMessageListener.java
new file mode 100644
index 0000000..a3928d3
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/connector/MyMessageListener.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package connector;
+
+public interface MyMessageListener {
+ public void onMessage (String message);
+}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/mdb/MyMessageBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/mdb/MyMessageBean.java
new file mode 100644
index 0000000..3af505b
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/mdb/MyMessageBean.java
@@ -0,0 +1,247 @@
+/*
+ * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package mdb;
+
+import java.sql.Statement;
+
+import javax.ejb.MessageDrivenBean;
+import javax.ejb.MessageDrivenContext;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+
+import connector.MyMessageListener;
+import javax.ejb.*;
+import javax.naming.*;
+import java.io.*;
+import java.rmi.RemoteException;
+import javax.servlet.*;
+import javax.servlet.http.*;
+import java.sql.*;
+import javax.sql.*;
+import javax.jms.*;
+import javax.transaction.*;
+
+
+/**
+ */
+public class MyMessageBean implements MessageDrivenBean,
+ MyMessageListener {
+
+ private transient MessageDrivenContext mdc = null;
+ private Context context;
+
+ @javax.inject.Inject
+ private connector.TestCDIBean tb;
+
+ /**
+ * Constructor, which is public and takes no arguments.
+ */
+ public MyMessageBean() {}
+
+ /**
+ * setMessageDrivenContext method, declared as public (but
+ * not final or static), with a return type of void, and
+ * with one argument of type javax.ejb.MessageDrivenContext.
+ *
+ * @param mdc the context to set
+ */
+ public void setMessageDrivenContext(MessageDrivenContext mdc) {
+ this.mdc = mdc;
+ }
+
+ /**
+ * ejbCreate method, declared as public (but not final or
+ * static), with a return type of void, and with no
+ * arguments.
+ */
+ public void ejbCreate() { }
+
+ /**
+ * onMessage method, declared as public (but not final or
+ * static), with a return type of void, and with one argument
+ * of type javax.jms.Message.
+ *
+ * Casts the incoming Message to a TextMessage and displays
+ * the text.
+ *
+ * @param inMessage the incoming message
+ */
+ public void onMessage(String inMessage) {
+
+ debug("onMessage:: RECEIVED [" + inMessage + "]");
+ debug("TestCDIBean injected:" + tb);
+
+ if (tb == null)
+ throw new RuntimeException("Injection of enabled Bean "
+ + "in RAR into a MDB injection point failed");
+
+ try {
+ if (inMessage.endsWith("WRITE")) {
+ doDbStuff("WRITE",
+ inMessage.substring(0, inMessage.lastIndexOf(":")));
+ } else if (inMessage.endsWith("DELETE")) {
+ doDbStuff("DELETE",
+ inMessage.substring(0, inMessage.lastIndexOf(":")));
+ } else if (inMessage.endsWith("DELETE_ALL")) {
+ doDbStuff("DELETE_ALL", "::");
+ } else {
+ //unsupported op.
+ }
+ } catch (Exception ex) {
+ debug("UH OH...");
+ ex.printStackTrace();
+ }
+
+ }
+
+ /**
+ * ejbRemove method, declared as public (but not final or
+ * static), with a return type of void, and with no
+ * arguments.
+ */
+ public void ejbRemove() {}
+
+
+ private void doDbStuff(String op, String message) throws Exception {
+
+ java.sql.Connection dbConnection = null;
+ String id = message.substring(0, message.indexOf(":"));
+ String body = message.substring(message.indexOf(":")+1);
+ try {
+ Context ic = new InitialContext();
+
+ if ("READ".equals(op)) {
+
+ debug("Reading row from database...");
+
+ // Creating a database connection
+ /*
+ DataSource ds = (DataSource) ic.lookup("java:comp/env/MyDB");
+ debug("Looked up Datasource\n");
+ debug("Get JDBC connection, auto sign on");
+ dbConnection = ds.getConnection();
+
+ Statement stmt = dbConnection.createStatement();
+ String query =
+ "SELECT id from messages where id = 'QQ'";
+ ResultSet results = stmt.executeQuery(query);
+ results.next();
+ System.out.println("QQ has balance " +
+ results.getInt("balance") + " dollars");
+ results.close();
+ stmt.close();
+
+ System.out.println("Read one account\n");
+ */
+
+ } else if ("WRITE".equals(op)) {
+
+ debug("Inserting one message in the database\n");
+
+ // Creating a database connection
+ DataSource ds = (DataSource) ic.lookup("java:comp/env/MyDB");
+ //debug("Looked up Datasource\n");
+ //debug("Get JDBC connection, auto sign on");
+ dbConnection = ds.getConnection();
+
+ createRow(id, body, dbConnection);
+ System.out.println("Created one message\n");
+
+ } else if ("DELETE".equals(op)) {
+
+ debug("Deleting one message from the database\n");
+
+ // Creating a database connection
+ DataSource ds = (DataSource) ic.lookup("java:comp/env/MyDB");
+ //debug("Looked up Datasource\n");
+ //debug("Get JDBC connection, auto sign on");
+ dbConnection = ds.getConnection();
+
+ deleteRow(id, dbConnection);
+ System.out.println("Deleted one message\n");
+ } else if ("DELETE_ALL".equals(op)) {
+
+ debug("Deleting all messages from the database\n");
+
+ // Creating a database connection
+ DataSource ds = (DataSource) ic.lookup("java:comp/env/MyDB");
+ //debug("Looked up Datasource\n");
+ //debug("Get JDBC connection, auto sign on");
+ dbConnection = ds.getConnection();
+ deleteAll(dbConnection);
+ System.out.println("Deleted all messages\n");
+ } else {
+ //unsupported op
+ }
+
+ }finally{
+ try{
+ dbConnection.close();
+ }catch(Exception ex){
+ debug("Exception occured while closing database con nection.");
+ }
+ }
+ }
+
+ private void createRow(String id, String body,
+ java.sql.Connection dbConnection)
+ throws Exception {
+
+ // Create row for this message
+ debug("CreateRow with ID = " + id + ", BODY = " + body);
+ Statement stmt = dbConnection.createStatement();
+ String query = "INSERT INTO messages (messageId, message)" +
+ "VALUES ('" + id + "', '" + body + "')";
+ int resultCount = stmt.executeUpdate(query);
+ if ( resultCount != 1 ) {
+ throw new Exception(
+ "ERROR in INSERT !! resultCount = "+resultCount);
+ }
+ stmt.close();
+ }
+
+ private void deleteRow(String id, java.sql.Connection dbConnection)
+ throws Exception {
+
+ // Delete row for this message
+ debug("DeleteRow with ID = " + id);
+ Statement stmt = dbConnection.createStatement();
+ String query = "DELETE FROM messages WHERE messageId = '" + id + "'";
+ int resultCount = stmt.executeUpdate(query);
+ if ( resultCount != 1 ) {
+ throw new Exception(
+ "ERROR in INSERT !! resultCount = "+resultCount);
+ }
+ stmt.close();
+ }
+
+ private void deleteAll(java.sql.Connection dbConnection)
+ throws Exception {
+
+ // Delete row for this message
+ Statement stmt = dbConnection.createStatement();
+ String query = "DELETE FROM messages";
+ int resultCount = stmt.executeUpdate(query);
+ debug("Delete all rows from messages... count = " + resultCount);
+ stmt.close();
+ }
+
+ private void debug(String msg) {
+ System.out.println("[MyMessageBean] --> " + msg);
+ }
+}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/build.xml
new file mode 100644
index 0000000..645f1c9
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/build.xml
@@ -0,0 +1,98 @@
+<!--
+
+ Copyright (c) 2002, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<!DOCTYPE project [
+ <!ENTITY common SYSTEM "../../../../config/common.xml">
+ <!ENTITY testcommon SYSTEM "../../../../config/properties.xml">
+]>
+
+<project name="connector1.5 TEST" default="all" basedir=".">
+<property name="j2ee.home" value="../.."/>
+<property name="client.class" value="client/Client"/>
+
+ <!-- include common.xml and testcommon.xml -->
+ &common;
+ &testcommon;
+
+ <target name="all" depends="init-common, build, setup, runtest, unset"/>
+ <target name="run-dp-test" depends="init-common, build, setup-dp, deploy-dp, runtest, unset-dp, undeploy-dp"/>
+ <target name="build" depends="init-common">
+ <ant dir="ra" inheritAll="false" target="all"/>
+ <ant dir="app" inheritAll="false" target="all"/>
+ </target>
+
+ <target name="setup">
+ <ant dir="app" inheritAll="false" target="setupJdbc"/>
+ <ant dir="." inheritAll="false" target="deploy"/>
+ </target>
+
+ <target name="setup-dp">
+ <ant dir="app" inheritAll="false" target="setupJdbc"/>
+ </target>
+
+ <target name="deploy">
+ <ant dir="ra" inheritAll="false" target="deploy"/>
+ <ant dir="ra" inheritAll="false" target="testAddAdmin"/>
+ <ant dir="app" inheritAll="false" target="deploy-ear"/>
+ <ant dir="." inheritAll="false" target="restart"/>
+ </target>
+
+ <target name="deploy-dp">
+ <ant dir="ra" inheritAll="false" target="testAddAdmin"/>
+ <ant dir="app" inheritAll="false" target="deploy-ear"/>
+ <ant dir="." inheritAll="false" target="restart"/>
+ </target>
+
+ <target name="runtest" depends="init-common">
+ <antcall target="runclient-common">
+ <param name="appname" value="simplemdb" />
+ </antcall>
+ </target>
+
+ <target name="unset">
+ <ant dir="app" inheritAll="false" target="unsetJdbc"/>
+ <ant dir="." inheritAll="false" target="undeploy"/>
+ <ant dir="." inheritAll="false" target="restart"/>
+ </target>
+
+ <target name="unset-dp">
+ <ant dir="app" inheritAll="false" target="unsetJdbc"/>
+ <ant dir="." inheritAll="false" target="restart"/>
+ </target>
+
+ <target name="undeploy">
+ <ant dir="app" inheritAll="false" target="undeploy"/>
+ <ant dir="ra" inheritAll="false" target="testDelAdmin"/>
+ <ant dir="ra" inheritAll="false" target="undeploy"/>
+ </target>
+
+ <target name="undeploy-dp">
+ <ant dir="app" inheritAll="false" target="undeploy"/>
+ <ant dir="ra" inheritAll="false" target="testDelAdmin"/>
+ </target>
+
+ <target name="restart" depends="init-common">
+ <echo message="Not required to restart"/>
+ </target>
+
+ <target name="clean">
+ <ant dir="ra" inheritAll="false" target="clean"/>
+ <ant dir="app" inheritAll="false" target="clean"/>
+ </target>
+
+</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/createdb.sql b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/createdb.sql
new file mode 100644
index 0000000..19f3324
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/createdb.sql
@@ -0,0 +1,2 @@
+drop table messages;
+create table messages (messageId CHAR(50), message varchar(80));
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/META-INF/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/META-INF/beans.xml
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/META-INF/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/META-INF/ra.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/META-INF/ra.xml
new file mode 100644
index 0000000..2ca2ebc
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/META-INF/ra.xml
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<!--
+<!DOCTYPE connector PUBLIC '-//Sun Microsystems, Inc.//DTD Connector 1.5//EN' 'http://java.sun.com/dtd/connector_1_5.dtd'>
+-->
+<connector xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+ http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd"
+ version="1.5">
+ <display-name>Simple Resource Adapter</display-name>
+ <vendor-name>Java Software</vendor-name>
+ <eis-type>Generic Type</eis-type>
+ <resourceadapter-version>1.0Alpha</resourceadapter-version>
+ <resourceadapter>
+ <resourceadapter-class>
+ connector.SimpleResourceAdapterImpl
+ </resourceadapter-class>
+ <config-property>
+ <config-property-name>
+ TestName
+ </config-property-name>
+ <config-property-type>
+ java.lang.String
+ </config-property-type>
+ <config-property-value>
+ ConfigPropertyForRA
+ </config-property-value>
+ </config-property>
+ <inbound-resourceadapter>
+ <messageadapter>
+ <messagelistener>
+ <messagelistener-type>
+ connector.MyMessageListener
+ </messagelistener-type>
+ <activationspec>
+ <activationspec-class>
+ connector.SimpleActivationSpec
+ </activationspec-class>
+ </activationspec>
+ </messagelistener>
+ </messageadapter>
+ </inbound-resourceadapter>
+ <adminobject>
+ <adminobject-interface>connector.MyAdminObject</adminobject-interface>
+ <adminobject-class>connector.MyAdminObject</adminobject-class>
+ <config-property>
+ <config-property-name>ResetControl</config-property-name>
+ <config-property-type>java.lang.String</config-property-type>
+ <config-property-value>NORESET</config-property-value>
+ </config-property>
+ <config-property>
+ <config-property-name>ExpectedResult</config-property-name>
+ <config-property-type>java.lang.Integer</config-property-type>
+ <config-property-value>88</config-property-value>
+ </config-property>
+ </adminobject>
+ </resourceadapter>
+</connector>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/build.xml
new file mode 100644
index 0000000..5267dc3
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/build.xml
@@ -0,0 +1,81 @@
+<!--
+
+ Copyright (c) 2002, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<!DOCTYPE project [
+ <!ENTITY common SYSTEM "../../../../../config/common.xml">
+ <!ENTITY props SYSTEM "../../../../../config/properties.xml">
+]>
+
+<project name="connector1.5 RA" default="all" basedir=".">
+
+ <property name="j2ee.home" value="../../.."/>
+ <property name="earfile" value="generic-ra.rar"/>
+
+ <!-- include common.xml and testcommon.xml -->
+ &common;
+ &props;
+
+ <target name="all">
+ <ant dir="src" inheritAll="false" target="all"/>
+
+ <jar jarfile="generic-ra.rar" basedir="."
+ includes="generic-ra.jar, META-INF/ra.xml, META-INF/beans.xml" />
+ </target>
+
+ <target name="deploy" depends="init-common">
+ <antcall target="deploy-rar-common">
+ <param name="rarfile" value="generic-ra.rar"/>
+ </antcall>
+ </target>
+
+ <target name="undeploy" depends="init-common">
+ <antcall target="undeploy-rar-common">
+ <param name="undeployrar" value="generic-ra"/>
+ </antcall>
+ </target>
+
+ <target name="testAddAdmin" depends="init-common">
+ <antcall target="asadmin-common">
+ <param name="admin.command" value="create-admin-object --target ${appserver.instance.name} --restype connector.MyAdminObject --raname generic-ra --property ResetControl=BEGINNING"/>
+ <param name="operand.props" value="eis/testAdmin"/>
+ </antcall>
+ </target>
+
+ <target name="testDelAdmin" depends="init-common">
+ <antcall target="asadmin-common">
+ <param name="admin.command" value="delete-admin-object"/>
+ <param name="operand.props" value="--target ${appserver.instance.name} eis/testAdmin"/>
+ </antcall>
+ </target>
+
+ <target name="sendMessage" depends="init-common">
+ <echo message="Class path is ${s1astest.classpath}"/>
+ <java fork="true" classname="connector.Messages" failonerror="true">
+ <arg line="add Foo TestMessage"/>
+ <classpath>
+ <pathelement location="${s1astest.classpath}"/>
+ <pathelement location="generic-ra.jar"/>
+ </classpath>
+ </java>
+ </target>
+
+ <target name="clean">
+ <ant dir="src" inheritAll="false" target="clean"/>
+ </target>
+
+</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/build.xml
new file mode 100644
index 0000000..fad2edb
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/build.xml
@@ -0,0 +1,49 @@
+<!--
+
+ Copyright (c) 2002, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<!DOCTYPE project [
+ <!ENTITY common SYSTEM "../../../../../../config/common.xml">
+ <!ENTITY props SYSTEM "../../../../../../config/properties.xml">
+]>
+
+<project name="connector1.5 RA SRC" default="all" basedir=".">
+
+
+ <!-- include common.xml and testcommon.xml -->
+ &common;
+ &props;
+
+ <target name="all" depends="init-common" >
+ <antcall target="compile-common">
+ <param name="build.classes.dir" value="classes" />
+ <param name="src" value="connector" />
+ </antcall>
+ <jar jarfile="../generic-ra.jar" basedir="classes"
+ includes="connector/*.class" />
+ </target>
+
+
+ <target name="clean">
+ <antcall target="clean-classes-common">
+ <param name="build.classes.dir" value="classes" />
+ </antcall>
+ <delete file="../generic-ra.jar"/>
+ <delete file="../generic-ra.rar"/>
+ </target>
+
+</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/Controls.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/Controls.java
new file mode 100644
index 0000000..42188a6
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/Controls.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package connector;
+
+/**
+ *
+ * @author Qingqing Ouyang
+ */
+public class Controls {
+ public static Object readyLock = new Object();
+ public static int expectedResults;
+ public static boolean done = false;
+}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/DeliveryWork.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/DeliveryWork.java
new file mode 100644
index 0000000..43377e8
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/DeliveryWork.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package connector;
+
+import java.lang.reflect.Method;
+import java.util.Iterator;
+import javax.resource.spi.endpoint.MessageEndpoint;
+import javax.resource.spi.endpoint.MessageEndpointFactory;
+import javax.resource.spi.UnavailableException;
+import javax.resource.spi.work.Work;
+import javax.resource.spi.work.WorkManager;
+import javax.resource.spi.work.ExecutionContext;
+
+/**
+ *
+ * @author Qingqing Ouyang
+ */
+public class DeliveryWork implements Work {
+
+ private MessageEndpoint ep;
+ private int num;
+ private String op;
+ private boolean keepCount;
+ private static int counter = 0;
+
+ public DeliveryWork(MessageEndpoint ep, int numOfMessages, String op) {
+ this.ep = ep;
+ this.num = numOfMessages;
+ this.op = op;
+ this.keepCount = false;
+ }
+
+ public DeliveryWork(MessageEndpoint ep, int numOfMessages,
+ String op, boolean keepCount) {
+ this.ep = ep;
+ this.num = numOfMessages;
+ this.op = op;
+ this.keepCount = keepCount;
+ }
+
+ public void run() {
+
+ debug("ENTER...");
+
+ try {
+ //Method onMessage = getOnMessageMethod();
+ //ep.beforeDelivery(onMessage);
+
+ if (!keepCount) {
+ for (int i = 0; i < num; i++) {
+ String msgId = String.valueOf(i);
+ String msgBody = "This is message " + msgId;
+ String msg = msgId + ":" + msgBody + ":" + op;
+ ((MyMessageListener) ep).onMessage(msg);
+ }
+ } else {
+ for (int i = 0; i < num; i++) {
+ String msgId = String.valueOf(i+counter);
+ String msgBody = "This is message " + msgId;
+ String msg = msgId + ":" + msgBody + ":" + op;
+ ((MyMessageListener) ep).onMessage(msg);
+ }
+ counter = counter + num;
+ }
+
+ //ep.afterDelivery();
+
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+
+ debug("LEAVE...");
+ }
+
+ public void release() {}
+
+ public String toString() {
+ return op;
+ }
+
+ private Method getOnMessageMethod() {
+
+ Method onMessageMethod = null;
+ try {
+ Class msgListenerClass = connector.MyMessageListener.class;
+ Class[] paramTypes = { java.lang.String.class };
+ onMessageMethod =
+ msgListenerClass.getMethod("onMessage", paramTypes);
+
+ } catch (NoSuchMethodException ex) {
+ ex.printStackTrace();
+ }
+ return onMessageMethod;
+ }
+
+ private void debug(String mesg) {
+ System.out.println("DeliveryWork[" + op + "] --> " + mesg);
+ }
+}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/FakeXAResource.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/FakeXAResource.java
new file mode 100644
index 0000000..97ed09e
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/FakeXAResource.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package connector;
+
+import javax.transaction.xa.*;
+
+/**
+ * This is class is used for debugging. It prints out
+ * trace information on TM calls to XAResource before
+ * directing the call to the actual XAResource object
+ */
+public class FakeXAResource implements XAResource {
+
+ public FakeXAResource() {}
+
+ public void commit(Xid xid, boolean onePhase) throws XAException {
+ print("FakeXAResource.commit: " + xidToString(xid) + "," + onePhase);
+ }
+
+ public void end(Xid xid, int flags) throws XAException {
+ print("FakeXAResource.end: " + xidToString(xid) + "," +
+ flagToString(flags));
+ }
+
+
+ public void forget(Xid xid) throws XAException {
+ print("FakeXAResource.forget: " + xidToString(xid));
+ }
+
+ public int getTransactionTimeout() throws XAException {
+ return 60*1000;
+ }
+
+ public boolean isSameRM(XAResource xares) throws XAException {
+ return false;
+ }
+
+ public int prepare(Xid xid) throws XAException {
+ print("FakeXAResource.prepare: " + xidToString(xid));
+ return XAResource.XA_OK;
+ }
+
+ public Xid[] recover(int flag) throws XAException {
+ print("FakeXAResource.recover: " + flagToString(flag));
+ return null;
+ }
+
+ public void rollback(Xid xid) throws XAException {
+ print("FakeXAResource.rollback: " + xidToString(xid));
+ }
+
+ public boolean setTransactionTimeout(int seconds) throws XAException {
+ return false;
+ }
+
+ public void start(Xid xid, int flags) throws XAException {
+ print("FakeXAResource.start: " + xidToString(xid) + "," +
+ flagToString(flags));
+ throw new XAException();
+ }
+
+ private void print(String s) {
+ System.out.println(s);
+ }
+
+ static public String xidToString(Xid xid) {
+ return String.valueOf((new String(xid.getGlobalTransactionId()) +
+ new String(xid.getBranchQualifier())).hashCode());
+ }
+
+ static public String flagToString(int flag) {
+ switch (flag) {
+ case TMFAIL:
+ return "TMFAIL";
+ case TMJOIN:
+ return "TMJOIN";
+ case TMNOFLAGS:
+ return "TMNOFLAGS";
+ case TMONEPHASE:
+ return "TMONEPHASE";
+ case TMRESUME:
+ return "TMRESUME";
+ case TMSTARTRSCAN:
+ return "TMSTARTRSCAN";
+ case TMENDRSCAN:
+ return "TMENDRSCAN";
+ case TMSUCCESS:
+ return "TMSUCCESS";
+ case TMSUSPEND:
+ return "TMSUSPEND";
+ case XA_RDONLY:
+ return "XA_RDONLY";
+ default:
+ return "" + Integer.toHexString(flag);
+ }
+ }
+
+ public boolean equals(Object obj) {
+ return false;
+ }
+
+ public int hashCode() {
+ return 1;
+ }
+}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/Messages.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/Messages.java
new file mode 100644
index 0000000..84e1c71
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/Messages.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package connector;
+
+import java.util.*;
+
+/**
+ * collection of messages.
+ *
+ * @author Qingqing Ouyang
+ */
+public class Messages {
+
+ private static Hashtable messages = new Hashtable();
+
+ public static void sendMessage (String destName, String message) {
+ if (messages.get(destName) != null) {
+ ((ArrayList) messages.get(destName)).add(message);
+ } else {
+ ArrayList list = new ArrayList();
+ list.add(message);
+ messages.put(destName, list);
+ }
+ System.out.println("sendMessage. message at foo is " + Messages.hasMessages("Foo"));
+ }
+
+ public static boolean hasMessages (String destName) {
+ return messages.get(destName) != null;
+ }
+
+ public static ArrayList getMessages (String destName) {
+ return (ArrayList) messages.get(destName);
+ }
+
+ public static void main (String[] args) {
+ if (args.length != 3) {
+ System.exit(1);
+ }
+
+ String command = args[0];
+ String destName = args[1];
+ String message = args[2];
+
+ if (!"add".equals(command)) {
+ System.exit(1);
+ }
+
+ sendMessage(destName, message);
+ System.out.println("Message : " + message + " sent to " + destName);
+ }
+}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/MyAdminObject.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/MyAdminObject.java
new file mode 100644
index 0000000..f33a711
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/MyAdminObject.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package connector;
+
+public class MyAdminObject implements java.io.Serializable {
+
+ private String resetControl="NORESET";
+ private Integer expectedResults;
+
+ public void setResetControl (String value) {
+ resetControl = value;
+ }
+
+ public String getResetControl () {
+ return resetControl;
+ }
+
+ public void setExpectedResults (Integer value) {
+ expectedResults = value;
+ }
+
+ public Integer getExpectedResults () {
+ return expectedResults;
+ }
+
+ public void initialize() {
+ System.out.println("[MyAdminObject] Initializing the Controls to false:"+resetControl);
+ if (resetControl.equals("BEGINNING")) {
+ Controls.done=false;
+ System.out.println("[MyAdminObject] Initialized the Controls to false");
+ }
+ }
+
+ public boolean done() {
+ return Controls.done;
+ }
+
+ public int expectedResults(){
+ return Controls.expectedResults;
+ }
+
+ public Object getLockObject(){
+ return Controls.readyLock;
+ }
+
+}
+
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/MyMessageListener.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/MyMessageListener.java
new file mode 100644
index 0000000..a3928d3
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/MyMessageListener.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package connector;
+
+public interface MyMessageListener {
+ public void onMessage (String message);
+}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/MyWork.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/MyWork.java
new file mode 100644
index 0000000..0513628
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/MyWork.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package connector;
+
+import java.lang.reflect.Method;
+import java.util.Iterator;
+import javax.resource.spi.endpoint.MessageEndpoint;
+import javax.resource.spi.endpoint.MessageEndpointFactory;
+import javax.resource.spi.UnavailableException;
+import javax.resource.spi.work.Work;
+import javax.resource.spi.work.WorkManager;
+import javax.resource.spi.work.ExecutionContext;
+
+/**
+ *
+ * @author Qingqing Ouyang
+ */
+public class MyWork implements Work {
+
+ private String name;
+ private boolean stop = false;
+ private MessageEndpointFactory factory;
+ private WorkManager wm;
+
+ public MyWork(
+ String name, MessageEndpointFactory factory, WorkManager wm) {
+ this.factory = factory;
+ this.name = name;
+ this.wm = wm;
+ }
+
+ public void run() {
+
+ debug("ENTER...");
+
+ //try 3 times to create endpoint (in case of failure)
+ for (int i = 0; i < 3; i++) {
+
+ try {
+
+ Method onMessage = getOnMessageMethod();
+ System.out.println("isDeliveryTransacted = " +
+ factory.isDeliveryTransacted(onMessage));
+
+ /*
+ MessageEndpoint ep = factory.createEndpoint(null);
+ ep.beforeDelivery(onMessage);
+ ((MyMessageListener) ep).onMessage(name + ": TEST MSG ONE");
+ ((MyMessageListener) ep).onMessage(name + ": TEST MSG TWO");
+ ((MyMessageListener) ep).onMessage(name + ": TEST MSG THREE");
+ ep.afterDelivery();
+ break;
+ */
+
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ debug("LEAVE...");
+ }
+
+ public void release() {}
+
+ public void stop() {
+ this.stop = true;
+ }
+
+ public String toString() {
+ return name;
+ }
+
+ public Method getOnMessageMethod() {
+
+ Method onMessageMethod = null;
+ try {
+ Class msgListenerClass = connector.MyMessageListener.class;
+ Class[] paramTypes = { java.lang.String.class };
+ onMessageMethod =
+ msgListenerClass.getMethod("onMessage", paramTypes);
+
+ } catch (NoSuchMethodException ex) {
+ ex.printStackTrace();
+ }
+ return onMessageMethod;
+ }
+
+ private void debug(String mesg) {
+ System.out.println("MyWork[" + name + "] --> " + mesg);
+ }
+}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/SimpleActivationSpec.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/SimpleActivationSpec.java
new file mode 100644
index 0000000..fc14e69
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/SimpleActivationSpec.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package connector;
+
+import javax.resource.spi.ActivationSpec;
+import javax.resource.spi.ResourceAdapter;
+
+/**
+ * This class is supposed to implemented as a JavaBean
+ * so that the app server can instantiate and configure
+ * it at the runtime.
+ *
+ * @author Qingqing Ouyang
+ */
+public class SimpleActivationSpec
+ implements ActivationSpec, java.io.Serializable {
+
+ private String destinationName;
+ private String destinationType;
+ private String testProp;
+ private Integer testIntegerProp;
+ private ResourceAdapter resourceadapter;
+
+ /**
+ * Default constructor.
+ */
+ public SimpleActivationSpec () {}
+
+ public String getDestinationName () {
+ return this.destinationName;
+ }
+
+ public void setDestinationName (String name) {
+ debug("setDestinationName() called... name = " + name);
+ this.destinationName = name;
+ }
+
+ public String getDestinationType() {
+ return this.destinationType;
+ }
+
+ public void setDestinationType (String type) {
+ debug("setDestinationType () called... type = " + type);
+ this.destinationType= type;
+ }
+
+ public String getTestProp() {
+ return this.testProp;
+ }
+
+ public void setTestProp (String testProp) {
+ debug("setTestProp () called... testProp = " + testProp);
+ this.testProp = testProp;
+ }
+
+ public Integer getTestIntegerProp() {
+ return this.testIntegerProp;
+ }
+
+ public void setTestIntegerProp (Integer testProp1) {
+ debug("setTestIntegerProp () called... testIntegerProp = " + testProp1);
+ this.testIntegerProp = testProp1;
+ }
+
+ public ResourceAdapter getResourceAdapter () {
+ debug("getResourceAdapter() called... ");
+ return this.resourceadapter;
+ }
+
+ public void setResourceAdapter (ResourceAdapter ra) {
+ debug("setResourceAdapter() called... ra = " + ra);
+ this.resourceadapter = ra;
+ }
+
+ public void validate() {
+ if (this.testIntegerProp.intValue() == 2 && this.testProp.equals("WrongValue")) {
+ //valid
+ } else {
+ throw new RuntimeException("Invalid Configuration testIntegerProp: " + this.testIntegerProp.intValue() + " testProp " + this.testProp);
+
+ }
+
+ }
+
+ private void debug (String message)
+ {
+ System.out.println("[SimpleActivationSpec] ==> " + message);
+ }
+}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/SimpleResourceAdapterImpl.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/SimpleResourceAdapterImpl.java
new file mode 100644
index 0000000..4d4d6c4
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/SimpleResourceAdapterImpl.java
@@ -0,0 +1,235 @@
+/*
+ * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package connector;
+
+import java.util.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Properties;
+import javax.resource.NotSupportedException;
+import javax.resource.ResourceException;
+import javax.resource.spi.ActivationSpec;
+import javax.resource.spi.ActivationSpec;
+import javax.resource.spi.BootstrapContext;
+import javax.resource.spi.ResourceAdapter;
+import javax.resource.spi.XATerminator;
+import javax.resource.spi.endpoint.MessageEndpoint;
+import javax.resource.spi.endpoint.MessageEndpointFactory;
+import javax.resource.spi.UnavailableException;
+import javax.resource.spi.ResourceAdapterInternalException;
+import javax.resource.spi.work.ExecutionContext;
+import javax.resource.spi.work.Work;
+import javax.resource.spi.work.WorkManager;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
+
+/**
+ * This is a sample resource adapter
+ *
+ * @author Qingqing Ouyang
+ */
+public class SimpleResourceAdapterImpl
+implements ResourceAdapter, java.io.Serializable {
+
+ private BootstrapContext ctx;
+ private WorkManager wm;
+ private String testName;
+
+ private boolean debug = true;
+ private Work work;
+
+ public SimpleResourceAdapterImpl () {
+ debug ("constructor...");
+ }
+
+ public void
+ start(BootstrapContext ctx) throws ResourceAdapterInternalException{
+
+ debug("001. Simple RA start...");
+
+ this.ctx = ctx;
+ debug("002. Simple RA start...");
+ this.wm = ctx.getWorkManager();
+ debug("003. Simple RA start...");
+
+ //testing creat timer
+ Timer timer = null;
+ try{
+ timer = ctx.createTimer();
+ } catch(UnavailableException ue) {
+ System.out.println("Error");
+ throw new ResourceAdapterInternalException("Error form bootstrap");
+ }
+ debug("004. Simple RA start...");
+
+ try {
+
+ XATerminator xa = ctx.getXATerminator();
+
+ Xid xid1 = new XID();
+ System.out.println(" XID1 = " + xid1);
+
+ ExecutionContext ec = new ExecutionContext();
+ ec.setXid(xid1);
+ ec.setTransactionTimeout(5*1000); //5 seconds
+ TestWMWork outw = new TestWMWork(1000, false, true, ec);
+ outw.setWorkManager(wm);
+ try {
+ wm.doWork(outw, 1*1000, ec, null);
+ xa.commit(xid1, true);
+ } catch (Exception ex) {
+
+ System.out.println(" ex = " + ex.getMessage());
+ xa.rollback(xid1);
+ }
+
+ Xid xid2 = new XID();
+ System.out.println(" XID2 = " + xid2);
+
+ ec = new ExecutionContext();
+ ec.setXid(xid2);
+ ec.setTransactionTimeout(5*1000); //5 seconds
+ TestWMWork anotherw = new TestWMWork(3000, false);
+ anotherw.setWorkManager(wm);
+ try {
+ wm.doWork(anotherw, 1*1000, ec, null);
+ xa.commit(xid2, true);
+ } catch (Exception ex) {
+ xa.rollback(xid2);
+ }
+
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+
+
+ for (int i = 0 ; i < 3; i++) {
+ TestWMWork w = new TestWMWork(i, false);
+ try {
+ wm.doWork(w, 1, null, null);
+ } catch (Exception ex) {
+ System.out.println("FAIL: CAUGHT exception : i = " + i);
+ ex.printStackTrace();
+ }
+ }
+
+ for (int i = 3 ; i < 6; i++) {
+ TestWMWork w = new TestWMWork(i, true);
+ boolean pass = false;
+ try {
+ wm.doWork(w, 1, null, null);
+ } catch (Exception ex) {
+ pass = true;
+ System.out.println("PASS: CAUGHT EXPECTED exception : i = " + i);
+ ex.printStackTrace();
+ } finally {
+ if (!pass) {
+ System.out.println("FAIL: DID NOT GET EXPECTED exception :");
+ }
+ }
+ }
+
+ for (int i = 6 ; i < 9; i++) {
+ TestWMWork w = new TestWMWork(i, false);
+ try {
+ wm.doWork(w, 1, null, null);
+ } catch (Exception ex) {
+ System.out.println("FAIL: CAUGHT exception : i = " + i);
+ ex.printStackTrace();
+ }
+ }
+
+ for (int i = 9 ; i < 12; i++) {
+ TestWMWork w = new TestWMWork(i, false);
+ try {
+ wm.startWork(w);
+ } catch (Exception ex) {
+ System.out.println("FAIL: CAUGHT exception : i = " + i);
+ ex.printStackTrace();
+ }
+ }
+
+ for (int i = 12 ; i < 15; i++) {
+ TestWMWork w = new TestWMWork(i, false);
+ try {
+ wm.scheduleWork(w);
+ } catch (Exception ex) {
+ System.out.println("FAIL: CAUGHT exception : i = " + i);
+ ex.printStackTrace();
+ }
+ }
+
+ debug("005. Simple RA start...");
+ }
+
+ public void
+ stop() {
+ debug("999. Simple RA stop...");
+ if (work != null) {
+ ((WorkDispatcher) work).stop();
+
+ synchronized (Controls.readyLock) {
+ Controls.readyLock.notify();
+ }
+
+ }
+ }
+
+ public void
+ endpointActivation ( MessageEndpointFactory factory, ActivationSpec spec)
+ throws NotSupportedException {
+ try {
+ debug("B.000. Create and schedule Dispatcher");
+ spec.validate();
+ work = new WorkDispatcher("DISPATCHER", ctx, factory, spec);
+ wm.scheduleWork(work, 4*1000, null, null);
+ debug("B.001. Scheduled Dispatcher");
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ throw new RuntimeException(ex);
+ }
+ }
+
+ public void
+ endpointDeactivation (
+ MessageEndpointFactory endpointFactory,
+ ActivationSpec spec) {
+ debug ("endpointDeactivation called...");
+
+ ((WorkDispatcher) work).stop();
+ }
+
+ public String getTestName() {
+ return testName;
+ }
+
+ public void setTestName(String name) {
+ debug("setTestName called... name = " + name);
+ testName = name;
+ }
+
+ public void
+ debug (String message) {
+ if (debug)
+ System.out.println("[SimpleResourceAdapterImpl] ==> " + message);
+ }
+
+ public XAResource[] getXAResources(ActivationSpec[] specs)
+ throws ResourceException {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/TestCDIBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/TestCDIBean.java
new file mode 100644
index 0000000..c4ec82d
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/TestCDIBean.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package connector;
+
+//A test CDI bean that is bundled along with an embedded RAR
+public class TestCDIBean {
+
+}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/TestWMWork.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/TestWMWork.java
new file mode 100644
index 0000000..f132758
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/TestWMWork.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package connector;
+
+import java.lang.reflect.Method;
+import java.util.Iterator;
+import javax.resource.spi.endpoint.MessageEndpoint;
+import javax.resource.spi.endpoint.MessageEndpointFactory;
+import javax.resource.spi.UnavailableException;
+import javax.resource.spi.work.ExecutionContext;
+import javax.resource.spi.work.Work;
+import javax.resource.spi.work.WorkManager;
+import javax.resource.spi.work.WorkException;
+
+/**
+ *
+ * @author Qingqing Ouyang
+ */
+public class TestWMWork implements Work {
+
+ private boolean stop = false;
+ private int id;
+ private boolean isRogue;
+ private boolean doNest;
+ private WorkManager wm;
+ private ExecutionContext ctx;
+
+ public TestWMWork(int id, boolean isRogue) {
+ this(id, isRogue, false, null);
+ }
+
+ public TestWMWork(int id, boolean isRogue,
+ boolean doNest, ExecutionContext ctx) {
+ this.id = id;
+ this.isRogue = isRogue;
+ this.doNest = doNest;
+ this.ctx = ctx;
+ }
+
+ public void setWorkManager (WorkManager wm) {
+ this.wm = wm;
+ }
+
+ public void run() {
+
+ System.out.println("TestWMWork[" + id + "].start running");
+ if (!isRogue) {
+ try {
+ Thread.currentThread().sleep(1000);
+ } catch (Exception ex) {
+ System.out.println("TestWMWork[" + id + "].interrupted = ");
+ ex.printStackTrace();
+ }
+ } else {
+ System.out.println("TestWMWork: Simulating rogue RA's Work: Expected Arithmetic Exception - divide by Zero");
+ int j = 100/0;
+ }
+
+ if (doNest && (wm != null)) {
+ Work nestedWork = new TestWMWork(8888, false);
+ try {
+ wm.doWork(nestedWork, 1*1000, ctx, null);
+ } catch (WorkException ex) {
+ if (ex.getErrorCode().equals(
+ WorkException.TX_CONCURRENT_WORK_DISALLOWED)) {
+ System.out.println("TestWMWork[" + id + "] " +
+ "PASS: CAUGHT EXPECTED = " + ex.getErrorCode());
+ } else {
+ System.out.println("TestWMWork[" + id + "] " +
+ "FAIL: CAUGHT UNEXPECTED = " + ex.getErrorCode());
+ }
+ }
+
+ nestedWork = new TestWMWork(9999, false);
+ try {
+ ExecutionContext ec = new ExecutionContext();
+ ec.setXid(new XID());
+ ec.setTransactionTimeout(5*1000); //5 seconds
+ wm.doWork(nestedWork, 1*1000, ec, null);
+ } catch (Exception ex) {
+ System.out.println("TestWMWork[" + id + "] " +
+ "FAIL: CAUGHT UNEXPECTED = " + ex.getMessage());
+ }
+ }
+
+ System.out.println("TestWMWork[" + id + "].stop running");
+ }
+
+ public void release() {}
+
+ public void stop() {
+ this.stop = true;
+ }
+
+ public String toString() {
+ return String.valueOf(id);
+ }
+}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/WorkDispatcher.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/WorkDispatcher.java
new file mode 100644
index 0000000..5aa436c
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/WorkDispatcher.java
@@ -0,0 +1,323 @@
+/*
+ * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package connector;
+
+import java.lang.reflect.Method;
+import java.util.Iterator;
+import javax.resource.spi.ActivationSpec;
+import javax.resource.spi.BootstrapContext;
+import javax.resource.spi.XATerminator;
+import javax.resource.spi.endpoint.MessageEndpoint;
+import javax.resource.spi.endpoint.MessageEndpointFactory;
+import javax.resource.spi.UnavailableException;
+import javax.resource.spi.work.Work;
+import javax.resource.spi.work.WorkManager;
+import javax.resource.spi.work.ExecutionContext;
+import javax.transaction.xa.Xid;
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+
+/**
+ *
+ * @author Qingqing Ouyang
+ */
+public class WorkDispatcher implements Work {
+
+ private boolean stop = false;
+ private String id;
+ private MessageEndpointFactory factory;
+ private BootstrapContext ctx;
+ private ActivationSpec spec;
+ private WorkManager wm;
+ private XATerminator xa;
+
+ public WorkDispatcher(
+ String id,
+ BootstrapContext ctx,
+ MessageEndpointFactory factory,
+ ActivationSpec spec) {
+ this.id = id;
+ this.ctx = ctx;
+ this.factory = factory;
+ this.spec = spec;
+ this.wm = ctx.getWorkManager();
+ this.xa = ctx.getXATerminator();
+ }
+
+ public void run() {
+
+ debug("ENTER...");
+
+ try {
+ synchronized (Controls.readyLock) {
+ debug("WAIT...");
+ Controls.readyLock.wait();
+
+ if (stop) {
+ return;
+ }
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+
+ debug("Running...");
+
+ //try 3 times to create endpoint (in case of failure)
+ for (int i = 0; i < 3; i++) {
+
+ try {
+
+ Method onMessage = getOnMessageMethod();
+ System.out.println("isDeliveryTransacted = " +
+ factory.isDeliveryTransacted(onMessage));
+
+ if (!factory.isDeliveryTransacted(onMessage)) {
+ //MessageEndpoint ep = factory.createEndpoint(null);
+ //DeliveryWork d = new DeliveryWork("NO_TX", ep);
+ //wm.doWork(d, 0, null, null);
+ } else {
+
+ //MessageEndpoint ep = factory.createEndpoint(null);
+ MessageEndpoint ep = factory.createEndpoint(new FakeXAResource());
+ int numOfMessages = 5;
+
+ //importing transaction
+
+ //write/commit
+ ExecutionContext ec = startTx();
+ debug("Start TX - " + ec.getXid());
+
+ DeliveryWork w =
+ new DeliveryWork(ep, numOfMessages, "WRITE");
+ wm.doWork(w, 0, ec, null);
+ xa.commit(ec.getXid(), true);
+
+ debug("DONE WRITE TO DB");
+ Controls.expectedResults = numOfMessages;
+ notifyAndWait();
+
+ //delete/rollback
+ ec = startTx();
+ debug("Start TX - " + ec.getXid());
+
+ w = new DeliveryWork(ep, numOfMessages, "DELETE");
+ wm.doWork(w, 0, ec, null);
+ xa.rollback(ec.getXid());
+
+ debug("DONE ROLLBACK FROM DB");
+ Controls.expectedResults = numOfMessages;
+ notifyAndWait();
+
+ //delete/commit
+ ec = startTx();
+ debug("Start TX - " + ec.getXid());
+
+ w = new DeliveryWork(ep, numOfMessages, "DELETE");
+ wm.doWork(w, 0, ec, null);
+ xa.commit(ec.getXid(), true);
+
+ debug("DONE DELETE FROM DB");
+ Controls.expectedResults = 0;
+ notifyAndWait();
+
+ //write/commit
+ ec = startTx();
+ debug("Start TX - " + ec.getXid());
+
+ w = new DeliveryWork(ep, numOfMessages, "WRITE");
+ wm.doWork(w, 0, ec, null);
+ xa.commit(ec.getXid(), true);
+
+ debug("DONE WRITE TO DB");
+ Controls.expectedResults = numOfMessages;
+ notifyAndWait();
+
+ //delete/commit
+ ec = startTx();
+ debug("Start TX - " + ec.getXid());
+
+ w = new DeliveryWork(ep, numOfMessages, "DELETE");
+ wm.doWork(w, 0, ec, null);
+ xa.commit(ec.getXid(), true);
+
+ debug("DONE DELETE FROM DB");
+ Controls.expectedResults = 0;
+ notifyAndWait();
+
+ //write multiple times using doWork/commit
+ ec = startTx();
+ debug("Start TX - " + ec.getXid());
+
+ w = new DeliveryWork(ep, 1, "WRITE", true);
+ wm.doWork(w, 0, ec, null);
+ wm.doWork(w, 0, ec, null);
+ wm.doWork(w, 0, ec, null);
+ xa.commit(ec.getXid(), true);
+
+ debug("DONE WRITE TO DB");
+ Controls.expectedResults = 3;
+ notifyAndWait();
+
+ //write multiple times using doWork/rollback
+ ec = startTx();
+ debug("Start TX - " + ec.getXid());
+
+ w = new DeliveryWork(ep, 1, "WRITE", true);
+ wm.doWork(w, 0, ec, null);
+ wm.doWork(w, 0, ec, null);
+ wm.doWork(w, 0, ec, null);
+ xa.rollback(ec.getXid());
+
+ debug("DONE WRITE TO DB");
+ Controls.expectedResults = 3;
+ notifyAndWait();
+
+ ec = startTx();
+ debug("Start TX - " + ec.getXid());
+
+ //write multiple times using doWork/rollback
+ w = new DeliveryWork(ep, 2, "WRITE", true);
+ wm.doWork(w, 0, ec, null);
+ wm.doWork(w, 0, ec, null);
+ wm.doWork(w, 0, ec, null);
+
+ if (XAResource.XA_OK == xa.prepare(ec.getXid())) {
+ xa.commit(ec.getXid(), false);
+ debug("XA PREPARE/COMMIT. DONE WRITE TO DB ");
+ Controls.expectedResults = 9;
+ notifyAndWait();
+ } else {
+ xa.rollback(ec.getXid());
+ debug("XA PREPARE UNSUCCESSFUL. DONE ROLLBACK");
+ Controls.expectedResults = 3;
+ notifyAndWait();
+ }
+
+ //delete all.
+ ec = startTx();
+ debug("Start TX - " + ec.getXid());
+
+ w = new DeliveryWork(ep, 1, "DELETE_ALL");
+ wm.doWork(w, 0, ec, null);
+ xa.commit(ec.getXid(), true);
+
+ debug("DONE DELETE ALL FROM DB");
+ Controls.expectedResults = 0;
+ notifyAndWait();
+
+ done();
+ }
+
+ break;
+ } catch (UnavailableException ex) {
+ //ex.printStackTrace();
+ System.out.println("WorkDispatcher["+id+"] Endpoint Unavailable");
+ try {
+ Thread.currentThread().sleep(3*1000); //3 seconds
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } catch (XAException ex) {
+ ex.printStackTrace();
+ System.out.println("ERROR CODE = " + ex.errorCode);
+ done();
+ break;
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ done();
+ break;
+ }
+ }
+
+ debug("LEAVE...");
+ }
+
+ public void release() {}
+
+ public void stop() {
+ this.stop = true;
+ }
+
+ public String toString() {
+ return id;
+ }
+
+ public Method getOnMessageMethod() {
+
+ Method onMessageMethod = null;
+ try {
+ Class msgListenerClass = connector.MyMessageListener.class;
+ Class[] paramTypes = { java.lang.String.class };
+ onMessageMethod =
+ msgListenerClass.getMethod("onMessage", paramTypes);
+
+ } catch (NoSuchMethodException ex) {
+ ex.printStackTrace();
+ }
+ return onMessageMethod;
+ }
+
+ private ExecutionContext startTx() {
+ ExecutionContext ec = new ExecutionContext();
+ try {
+ Xid xid = new XID();
+ ec.setXid(xid);
+ ec.setTransactionTimeout(5*1000); //5 seconds
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ return ec;
+ }
+
+ private void notifyAndWait() {
+ try {
+ //Sleep for 5 seconds
+ //Thread.currentThread().sleep(5*1000);
+
+ synchronized(Controls.readyLock) {
+ //Notify the client to check the results
+ Controls.readyLock.notify();
+
+ //Wait until results are verified by the client
+ Controls.readyLock.wait();
+
+ if (stop) {
+ return;
+ }
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ private void done() {
+ try {
+ Controls.done = true;
+ synchronized(Controls.readyLock) {
+ //Notify the client to check the results
+ Controls.readyLock.notify();
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ private void debug(String mesg) {
+ System.out.println("Dispatcher[" + id + "] --> " + mesg);
+ }
+}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/XID.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/XID.java
new file mode 100644
index 0000000..138e91b
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/XID.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package connector;
+
+import javax.transaction.xa.Xid;
+
+/**
+ * The XID class provides an implementation of the X/Open
+ * transaction identifier it implements the javax.transaction.xa.Xid interface.
+ */
+public class XID implements Xid {
+
+
+ private static int ID = initializeID();
+
+ private static int initializeID() {
+ return (int)(Math.random()*100000);
+ }
+
+ public int formatID; // Format identifier
+ // (-1) means that the XID is null
+ public int branchQualifier;
+ public int globalTxID;
+
+ static public final int MAXGTRIDSIZE= 64;
+ static public final int MAXBQUALSIZE= 64;
+
+ public XID() {
+ int foo = ID++;
+ formatID = foo;
+ branchQualifier = foo;
+ globalTxID = foo;
+ }
+
+ public boolean equals(Object o) {
+ XID other; // The "other" XID
+ int L; // Combined gtrid_length + bqual_length
+ int i;
+
+ if (!(o instanceof XID)) // If the other XID isn't an XID
+ {
+ return false; // It can't be equal
+ }
+
+ other = (XID)o; // The other XID, now properly cast
+
+ if (this.formatID == other.formatID
+ && this.branchQualifier == other.branchQualifier
+ && this.globalTxID == other.globalTxID) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Compute the hash code.
+ *
+ * @return the computed hashcode
+ */
+ public int hashCode() {
+ if (formatID == (-1)) {
+ return (-1);
+ }
+
+ return formatID + branchQualifier + globalTxID;
+
+ }
+
+ /*
+ * Convert to String
+ *
+ * <p> This is normally used to display the XID when debugging.
+ */
+
+ /**
+ * Return a string representing this XID.
+ *
+ * @return the string representation of this XID
+ */
+ public String toString() {
+
+ String s = new String("{XID: " +
+ "formatID(" + formatID + "), " +
+ "branchQualifier (" + branchQualifier + "), " +
+ "globalTxID(" + globalTxID + ")}");
+
+ return s;
+ }
+
+ /*
+ * Return branch qualifier
+ */
+
+ /**
+ * Returns the branch qualifier for this XID.
+ *
+ * @return the branch qualifier
+ */
+ public byte[] getBranchQualifier() {
+ String foo = (new Integer(branchQualifier)).toString();
+ return foo.getBytes();
+ }
+
+ public int getFormatId() {
+ return formatID;
+ }
+
+ public byte[] getGlobalTransactionId() {
+ String foo = (new Integer(globalTxID)).toString();
+ return foo.getBytes();
+ }
+}