Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Index: devtests/ejb/ejb32/mdb/ejb/ResultsBean.java
===================================================================
--- devtests/ejb/ejb32/mdb/ejb/ResultsBean.java (revision 0)
+++ devtests/ejb/ejb32/mdb/ejb/ResultsBean.java (revision 0)
@@ -0,0 +1,40 @@
+package com.sun.s1asdev.ejb.ejb32.mdb.ejb;
+
+import javax.ejb.LocalBean;
+import javax.ejb.Lock;
+import javax.ejb.LockType;
+import javax.ejb.Singleton;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author David Blevins
+ */
+@Singleton
+@LocalBean
+@Lock(LockType.READ)
+public class ResultsBean implements ResultsRemote {
+
+ private final List<String> invoked = new ArrayList<String>();
+ private final CountDownLatch expected = new CountDownLatch(3);
+
+ public void addInvoked(String name) {
+ invoked.add(name);
+ expected.countDown();
+ }
+
+ public boolean awaitInvocations() {
+ try {
+ return expected.await(1, TimeUnit.MINUTES);
+ } catch (InterruptedException e) {
+ Thread.interrupted();
+ return false;
+ }
+ }
+
+ public List<String> getInvoked() {
+ return invoked;
+ }
+}
Property changes on: devtests/ejb/ejb32/mdb/ejb/ResultsBean.java
___________________________________________________________________
Added: svn:eol-style
+ native
Index: devtests/ejb/ejb32/mdb/ejb/ModernBean.java
===================================================================
--- devtests/ejb/ejb32/mdb/ejb/ModernBean.java (revision 0)
+++ devtests/ejb/ejb32/mdb/ejb/ModernBean.java (revision 0)
@@ -0,0 +1,47 @@
+package com.sun.s1asdev.ejb.ejb32.mdb.ejb;
+
+import com.sun.s1asdev.ejb.ejb32.mdb.ra.Command;
+import com.sun.s1asdev.ejb.ejb32.mdb.ra.CommandListener;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.ejb.MessageDriven;
+import javax.ejb.MessageDrivenContext;
+import javax.interceptor.Interceptors;
+
+/**
+ * @author David Blevins
+ */
+@MessageDriven
+@Interceptors(EnsureProxied.class)
+public class ModernBean implements CommandListener {
+
+ @EJB
+ private ResultsBean resultsBean;
+
+ @Resource
+ private MessageDrivenContext messageDrivenContext;
+
+ @Command
+ public void doSomething() {
+ resultsBean.addInvoked("one" + getInterceptorData());
+ }
+
+ @Command
+ public void doSomethingElse() {
+ resultsBean.addInvoked("two" + getInterceptorData());
+ }
+
+ @Command
+ public void doItOneMoreTime() {
+ resultsBean.addInvoked("three" + getInterceptorData());
+ }
+
+ /**
+ * Ensure that the bean was invoked via a proxy with interceptors
+ */
+ private Object getInterceptorData() {
+ return messageDrivenContext.getContextData().get("data");
+ }
+
+}
Property changes on: devtests/ejb/ejb32/mdb/ejb/ModernBean.java
___________________________________________________________________
Added: svn:eol-style
+ native
Index: devtests/ejb/ejb32/mdb/ejb/EnsureProxied.java
===================================================================
--- devtests/ejb/ejb32/mdb/ejb/EnsureProxied.java (revision 0)
+++ devtests/ejb/ejb32/mdb/ejb/EnsureProxied.java (revision 0)
@@ -0,0 +1,16 @@
+package com.sun.s1asdev.ejb.ejb32.mdb.ejb;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+/**
+ * @author David Blevins
+ */
+public class EnsureProxied {
+
+ @AroundInvoke
+ public Object invoke(InvocationContext context) throws Exception {
+ context.getContextData().put("data", " - intercepted");
+ return context.proceed();
+ }
+}
Property changes on: devtests/ejb/ejb32/mdb/ejb/EnsureProxied.java
___________________________________________________________________
Added: svn:eol-style
+ native
Index: devtests/ejb/ejb32/mdb/ejb/ResultsRemote.java
===================================================================
--- devtests/ejb/ejb32/mdb/ejb/ResultsRemote.java (revision 0)
+++ devtests/ejb/ejb32/mdb/ejb/ResultsRemote.java (revision 0)
@@ -0,0 +1,13 @@
+package com.sun.s1asdev.ejb.ejb32.mdb.ejb;
+
+import javax.ejb.Remote;
+import java.util.List;
+
+/**
+ * @author David Blevins
+ */
+@Remote
+public interface ResultsRemote {
+ boolean awaitInvocations();
+ List<String> getInvoked();
+}
Property changes on: devtests/ejb/ejb32/mdb/ejb/ResultsRemote.java
___________________________________________________________________
Added: svn:eol-style
+ native
Index: devtests/ejb/ejb32/mdb/ra/META-INF/ra.xml
===================================================================
--- devtests/ejb/ejb32/mdb/ra/META-INF/ra.xml (revision 0)
+++ devtests/ejb/ejb32/mdb/ra/META-INF/ra.xml (revision 0)
@@ -0,0 +1,32 @@
+<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">
+
+ <description>Generic ResourceAdapter</description>
+ <display-name>Generic ResourceAdapter</display-name>
+
+ <vendor-name>Generic Connector</vendor-name>
+
+ <eis-type>Generic Adapter</eis-type>
+
+ <resourceadapter-version>1.0</resourceadapter-version>
+
+ <resourceadapter id="CommandResourceAdapter">
+
+ <resourceadapter-class>com.sun.s1asdev.ejb.ejb32.mdb.ra.CommandResourceAdapter</resourceadapter-class>
+
+ <inbound-resourceadapter>
+ <messageadapter>
+ <messagelistener>
+ <messagelistener-type>com.sun.s1asdev.ejb.ejb32.mdb.ra.CommandListener</messagelistener-type>
+ <activationspec>
+ <activationspec-class>com.sun.s1asdev.ejb.ejb32.mdb.ra.CommandActivationSpec</activationspec-class>
+ </activationspec>
+ </messagelistener>
+ </messageadapter>
+ </inbound-resourceadapter>
+
+ </resourceadapter>
+</connector>
Property changes on: devtests/ejb/ejb32/mdb/ra/META-INF/ra.xml
___________________________________________________________________
Added: svn:eol-style
+ native
Index: devtests/ejb/ejb32/mdb/ra/CommandListener.java
===================================================================
--- devtests/ejb/ejb32/mdb/ra/CommandListener.java (revision 0)
+++ devtests/ejb/ejb32/mdb/ra/CommandListener.java (revision 0)
@@ -0,0 +1,14 @@
+package com.sun.s1asdev.ejb.ejb32.mdb.ra;
+
+/**
+ * EJB 3.2 No-method interface that signifies the
+ * connector wishes to have an @LocalBean-like view
+ * of the MessageEndpoint proxy.
+ *
+ * Future versions of the specification could allow
+ * this class to be an annotation the bean uses.
+ *
+ * @author David Blevins
+ */
+public interface CommandListener {
+}
Property changes on: devtests/ejb/ejb32/mdb/ra/CommandListener.java
___________________________________________________________________
Added: svn:eol-style
+ native
Index: devtests/ejb/ejb32/mdb/ra/CommandResourceAdapter.java
===================================================================
--- devtests/ejb/ejb32/mdb/ra/CommandResourceAdapter.java (revision 0)
+++ devtests/ejb/ejb32/mdb/ra/CommandResourceAdapter.java (revision 0)
@@ -0,0 +1,97 @@
+package com.sun.s1asdev.ejb.ejb32.mdb.ra;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ActivationSpec;
+import javax.resource.spi.BootstrapContext;
+import javax.resource.spi.ResourceAdapter;
+import javax.resource.spi.ResourceAdapterInternalException;
+import javax.resource.spi.endpoint.MessageEndpoint;
+import javax.resource.spi.endpoint.MessageEndpointFactory;
+import javax.transaction.xa.XAResource;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author David Blevins
+ */
+public class CommandResourceAdapter implements ResourceAdapter {
+
+ private Map<CommandActivationSpec, ActivatedEndpoint> endpoints = new HashMap<CommandActivationSpec, ActivatedEndpoint>();
+
+ public void start(BootstrapContext bootstrapContext) throws ResourceAdapterInternalException {
+ }
+
+ public void stop() {
+ }
+
+ public void endpointActivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) throws ResourceException {
+ final CommandActivationSpec commandActivationSpec = (CommandActivationSpec) activationSpec;
+ final ActivatedEndpoint activatedEndpoint = new ActivatedEndpoint(messageEndpointFactory, commandActivationSpec);
+ endpoints.put(commandActivationSpec, activatedEndpoint);
+ final Thread thread = new Thread(activatedEndpoint);
+ thread.setDaemon(true);
+ thread.start();
+ }
+
+ public void endpointDeactivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) {
+ endpoints.remove((CommandActivationSpec) activationSpec);
+ }
+
+ public XAResource[] getXAResources(ActivationSpec[] activationSpecs) throws ResourceException {
+ return new XAResource[0];
+ }
+
+ private static class ActivatedEndpoint implements Runnable {
+
+ private final MessageEndpointFactory factory;
+ private final List<Method> commands = new ArrayList<Method>();
+
+ private ActivatedEndpoint(MessageEndpointFactory factory, CommandActivationSpec spec) {
+ this.factory = factory;
+
+ final Method[] methods = factory.getBeanClass().getMethods();
+ for (Method method : methods) {
+ if (method.isAnnotationPresent(Command.class)) {
+ commands.add(method);
+ }
+ }
+
+ }
+
+ public void run() {
+ pause();
+ try {
+ final MessageEndpoint endpoint = factory.createEndpoint(null);
+ try {
+ for (Method method : commands) {
+ endpoint.beforeDelivery(method);
+ try {
+ method.invoke(endpoint);
+ } finally {
+ endpoint.afterDelivery();
+ }
+ }
+ } finally {
+ endpoint.release();
+ }
+ } catch (Throwable e) {
+ e.printStackTrace();
+ // fail
+ }
+ }
+
+ /**
+ * Have to wait till the application is fully started
+ */
+ private static void pause() {
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ Thread.interrupted();
+ }
+ }
+ }
+}
Property changes on: devtests/ejb/ejb32/mdb/ra/CommandResourceAdapter.java
___________________________________________________________________
Added: svn:eol-style
+ native
Index: devtests/ejb/ejb32/mdb/ra/CommandActivationSpec.java
===================================================================
--- devtests/ejb/ejb32/mdb/ra/CommandActivationSpec.java (revision 0)
+++ devtests/ejb/ejb32/mdb/ra/CommandActivationSpec.java (revision 0)
@@ -0,0 +1,24 @@
+package com.sun.s1asdev.ejb.ejb32.mdb.ra;
+
+import javax.resource.spi.ActivationSpec;
+import javax.resource.spi.InvalidPropertyException;
+import javax.resource.spi.ResourceAdapter;
+
+/**
+ * @author David Blevins
+ */
+public class CommandActivationSpec implements ActivationSpec {
+
+ private ResourceAdapter resourceAdapter;
+
+ public void validate() throws InvalidPropertyException {
+ }
+
+ public ResourceAdapter getResourceAdapter() {
+ return resourceAdapter;
+ }
+
+ public void setResourceAdapter(ResourceAdapter resourceAdapter) {
+ this.resourceAdapter = resourceAdapter;
+ }
+}
Property changes on: devtests/ejb/ejb32/mdb/ra/CommandActivationSpec.java
___________________________________________________________________
Added: svn:eol-style
+ native
Index: devtests/ejb/ejb32/mdb/ra/Command.java
===================================================================
--- devtests/ejb/ejb32/mdb/ra/Command.java (revision 0)
+++ devtests/ejb/ejb32/mdb/ra/Command.java (revision 0)
@@ -0,0 +1,14 @@
+package com.sun.s1asdev.ejb.ejb32.mdb.ra;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @author David Blevins
+ */
+@Target({ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Command {
+}
Property changes on: devtests/ejb/ejb32/mdb/ra/Command.java
___________________________________________________________________
Added: svn:eol-style
+ native
Index: devtests/ejb/ejb32/mdb/build.xml
===================================================================
--- devtests/ejb/ejb32/mdb/build.xml (revision 0)
+++ devtests/ejb/ejb32/mdb/build.xml (revision 0)
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!DOCTYPE project [
+<!ENTITY commonSetup SYSTEM "../../../../config/properties.xml">
+<!ENTITY commonBuild SYSTEM "../../../../config/common.xml">
+]>
+
+<project name="ejb32-mdb-App" default="usage" basedir=".">
+
+ &commonSetup;
+ &commonBuild;
+
+ <property name="module" value="ejb32-mdb"/>
+ <property name="appname" value="${module}"/>
+ <property name="se.client" value="com.sun.s1asdev.ejb.ejb32.mdb.client.Client"/>
+
+ <target name="all" depends="clean,build,deploy,run,undeploy"/>
+
+ <target name="clean" depends="init-common">
+ <antcall target="clean-common"/>
+ </target>
+
+ <target name="compile" depends="clean">
+ <echo message="${build.classes.dir}"/>
+ <echo message="${build.base.dir}"/>
+ <antcall target="compile-common">
+ <param name="src" value="ra"/>
+ </antcall>
+ <antcall target="compile-common">
+ <param name="src" value="ejb"/>
+ </antcall>
+ <antcall target="compile-common">
+ <param name="src" value="client"/>
+ </antcall>
+ </target>
+
+ <target name="build" depends="compile">
+ <mkdir dir="${assemble.dir}"/>
+ <!-- EJB JAR -->
+ <jar jarfile="${assemble.dir}/${appname}-ejb.jar" includes ="**/mdb/ejb/*.class"
+ basedir="${build.classes.dir}" update="false"/>
+ <!-- RAR -->
+ <jar jarfile="${assemble.dir}/${appname}-ra.jar" includes ="**/mdb/ra/*.class"
+ basedir="${build.classes.dir}" update="false"/>
+ <jar jarfile="${assemble.dir}/${appname}-ra.rar" includes ="*-ra.jar"
+ basedir="${assemble.dir}" update="false">
+ <metainf dir="ra/META-INF">
+ <include name="ra.xml"/>
+ </metainf>
+ </jar>
+ <!-- EAR -->
+ <jar jarfile="${assemble.dir}/${appname}.ear" update="false">
+ <fileset dir="${assemble.dir}" includes="*-ejb.jar"/>
+ <fileset dir="${assemble.dir}" includes="*-ra.rar"/>
+ </jar>
+ </target>
+
+ <target name="deploy" depends="init-common">
+ <exec executable="${ASADMIN}" failonerror="true">
+ <arg line="deploy"/>
+ <arg line="${as.props}"/>
+ <arg line="--upload=true"/>
+ <arg line="--target ${appserver.instance.name}"/>
+ <arg line="${assemble.dir}/${appname}.ear"/>
+ </exec>
+ </target>
+
+ <target name="run" depends="init-common">
+ <java fork="on"
+ failonerror="true"
+ classpath="${env.S1AS_HOME}/lib/javaee.jar:${env.S1AS_HOME}/lib/gf-client.jar:${build.classes.dir}:${env.APS_HOME}/lib/reporter.jar"
+ classname="${se.client}">
+ <sysproperty key="org.omg.CORBA.ORBInitialPort" value="${orb.port}"/>
+ <arg line="${jndiroot}"/>
+ </java>
+ </target>
+
+ <target name="undeploy" depends="init-common">
+ <exec executable="${ASADMIN}" failonerror="false">
+ <arg line="undeploy"/>
+ <arg line="${as.props}"/>
+ <arg line="--target ${appserver.instance.name}"/>
+ <arg line="${appname}"/>
+ </exec>
+ </target>
+
+ <target name="usage">
+ <antcall target="usage-common"/>
+ </target>
+</project>
Property changes on: devtests/ejb/ejb32/mdb/build.xml
___________________________________________________________________
Added: svn:eol-style
+ native
Index: devtests/ejb/ejb32/mdb/client/Client.java
===================================================================
--- devtests/ejb/ejb32/mdb/client/Client.java (revision 0)
+++ devtests/ejb/ejb32/mdb/client/Client.java (revision 0)
@@ -0,0 +1,49 @@
+package com.sun.s1asdev.ejb.ejb32.mdb.client;
+
+import com.sun.ejte.ccl.reporter.SimpleReporterAdapter;
+import com.sun.s1asdev.ejb.ejb32.mdb.ejb.ResultsRemote;
+
+import javax.naming.InitialContext;
+import java.util.List;
+
+/**
+ * Modern MDB test
+ *
+ * Verifies that the resource adapter:
+ * - has access to the beanClass via the activation spec
+ * - can obtain a LocalBean-like view
+ *
+ * @author David Blevins
+ */
+public class Client {
+ private static SimpleReporterAdapter stat =
+ new SimpleReporterAdapter("appserv-tests");
+
+ public static void main(String args[]) {
+ stat.addDescription("ejb32-mdb");
+
+ try {
+ ResultsRemote resultsRemote = (ResultsRemote) new InitialContext().lookup("java:global/ejb32-mdb/ejb32-mdb-ejb/ResultsBean!com.sun.s1asdev.ejb.ejb32.mdb.ejb.ResultsRemote");
+
+// System.out.println("awaitInvocations - start");
+ assertStatus("ejb32-mdb: awaitInvocations", resultsRemote.awaitInvocations());
+
+ final List<String> invoked = resultsRemote.getInvoked();
+ assertStatus("ejb32-mdb: method one", invoked.contains("one - intercepted"));
+ assertStatus("ejb32-mdb: method two", invoked.contains("two - intercepted"));
+ assertStatus("ejb32-mdb: method three", invoked.contains("three - intercepted"));
+ assertStatus("ejb32-mdb: total invocations", invoked.size() == 3);
+
+ } catch (Exception e) {
+ stat.addStatus("ejb32-mdb: ", stat.FAIL);
+ e.printStackTrace();
+ }
+
+ stat.printSummary("ejb32-mdb");
+ }
+
+ private static void assertStatus(final String message, final boolean condition) {
+ System.out.println(message + " : " + condition);
+ stat.addStatus(message, condition ? stat.PASS : stat.FAIL);
+ }
+}
Property changes on: devtests/ejb/ejb32/mdb/client/Client.java
___________________________________________________________________
Added: svn:eol-style
+ native
Index: devtests/ejb/ejb32/build.xml
===================================================================
--- devtests/ejb/ejb32/build.xml (revision 59349)
+++ devtests/ejb/ejb32/build.xml (working copy)
@@ -73,6 +73,12 @@
<record name="persistence.output" action="stop" />
</target>
+ <target name="mdb">
+ <record name="mdb.output" action="start" />
+ <ant dir="mdb" target="all"/>
+ <record name="mdb.output" action="stop" />
+ </target>
+
<target name="usage">
<echo>
Usage:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment