diff options
Diffstat (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/session/stateless')
7 files changed, 177 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/session/stateless/Hello.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/session/stateless/Hello.java new file mode 100644 index 0000000..fa4648b --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/session/stateless/Hello.java @@ -0,0 +1,13 @@ +package examples.session.stateless;
+
+/**
+ * This is the Hello business interface.
+ */
+
+public interface Hello {
+
+ /**
+ * @return a greeting to the client.
+ */
+ public String hello();
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/session/stateless/HelloBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/session/stateless/HelloBean.java new file mode 100644 index 0000000..10e6baf --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/session/stateless/HelloBean.java @@ -0,0 +1,16 @@ +package examples.session.stateless;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+/**
+ * Demonstration stateless session bean.
+ */
+@Stateless
+@Remote(Hello.class)
+public class HelloBean implements Hello {
+ public String hello() {
+ System.out.println("hello()");
+ return "Hello, World!";
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/session/stateless/HelloClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/session/stateless/HelloClient.java new file mode 100644 index 0000000..9becd53 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/session/stateless/HelloClient.java @@ -0,0 +1,59 @@ +package examples.session.stateless;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import java.util.Hashtable;
+
+// The following import should be removed.
+
+import examples.session.stateless.*;
+import javax.naming.*;
+
+/**
+ * This class is an example of client code which invokes
+ * methods on a simple, remote stateless session bean.
+ */
+public class HelloClient {
+
+ public static void main(String[] args) throws Exception {
+ /*
+ * Obtain the JNDI initial context.
+ *
+ * The initial context is a starting point for
+ * connecting to a JNDI tree. We choose our JNDI
+ * driver, the network location of the server, etc
+ * by passing in the environment properties.
+ */
+
+ System.out.println("about to create initialcontext");
+
+ Hashtable env = new Hashtable();
+ env.put("java.naming.factory.initial","com.sun.enterprise.naming.SerialInitContextFactory");
+ env.put("java.naming.factory.url.pkgs","com.sun.enterprise.naming");
+ env.put("java.naming.provider.url","localhost:3700");
+ Context ctx = new InitialContext();
+
+ //System.out.println ("Trying to get the name of this context: " + ctx.getNameInNamespace());
+
+ System.out.println("Got initial context ... yeah ");
+
+ /*
+ * Get a reference to a bean instance, looked up by class name
+ */
+ NamingEnumeration ne = ctx.list("");
+ System.out.println("Got list... ");
+ while(ne.hasMore())
+ {
+ NameClassPair nc = (NameClassPair)ne.next();
+ System.out.println("Entry is ... "+nc.getName()+" -- "+nc.getClassName());
+ }
+
+ Hello hello = (Hello) ctx.lookup("examples.session.stateless.Hello");
+
+ /*
+ * Call the hello() method on the bean.
+ * We then print the result to the screen.
+ */
+ System.out.println(hello.hello());
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/session/stateless/HelloClient.java.original b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/session/stateless/HelloClient.java.original new file mode 100644 index 0000000..f90a759 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/session/stateless/HelloClient.java.original @@ -0,0 +1,41 @@ +package examples.session.stateless;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+/**
+ * This class is an example of client code which invokes
+ * methods on a simple, remote stateless session bean.
+ */
+public class HelloClient {
+
+ public static void main(String[] args) throws Exception {
+ /*
+ * Obtain the JNDI initial context.
+ *
+ * The initial context is a starting point for
+ * connecting to a JNDI tree. We choose our JNDI
+ * driver, the network location of the server, etc
+ * by passing in the environment properties.
+ */
+
+ System.out.println("about to create initialcontext");
+ //Context ctx = new InitialContext(System.getProperties());
+ Context ctx = new InitialContext();
+
+ //System.out.println ("Trying to get the name of this context: " + ctx.getNameInNamespace());
+
+ System.out.println("Got initial context ... yeah ");
+
+ /*
+ * Get a reference to a bean instance, looked up by class name
+ */
+ Hello hello = (Hello) ctx.lookup("HelloBean");
+
+ /*
+ * Call the hello() method on the bean.
+ * We then print the result to the screen.
+ */
+ System.out.println(hello.hello());
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/session/stateless/META-INF/ejb-jar.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/session/stateless/META-INF/ejb-jar.xml new file mode 100644 index 0000000..9503e74 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/session/stateless/META-INF/ejb-jar.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8" ?>
+ <ejb-jar>
+ <enterprise-beans>
+ </enterprise-beans>
+</ejb-jar>
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/session/stateless/Readme.txt b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/session/stateless/Readme.txt new file mode 100644 index 0000000..a35bbb5 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/session/stateless/Readme.txt @@ -0,0 +1,13 @@ +1) asant jar
+
+2) asant deploy_common
+
+3) asant base_clientjar_common
+
+4) Turn off the firewall right before running the client (for Glassfish)
+
+asant run_client
+
+5) asant undeploy_common
+
+6) asant clean_all
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/session/stateless/build.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/session/stateless/build.xml new file mode 100644 index 0000000..7fbd159 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/session/stateless/build.xml @@ -0,0 +1,30 @@ +<?xml version="1.0"?>
+<!DOCTYPE project [ <!ENTITY include SYSTEM "../../../../etc/common.xml"> ]>
+
+<project name="ejb3-examples-session-stateless" default="jar"
+ basedir="../../../..">
+
+ <!-- basic settings -->
+ <property name="src.dir" value="${basedir}/src"/>
+ <property name="build.dir" value="${basedir}/build"/>
+ <property name="build.classes.dir" value="${build.dir}/classes"/>
+ <property name="appname" value="StatelessSession"/>
+ <property name="client.class" value="examples.session.stateless.HelloClient"/>
+ <property name="app.pkg" value="examples/session/stateless"/>
+ <property name="package" value="${app.pkg}"/>
+ <property name="pack.dir" value="${src.dir}/${app.pkg}"/>
+ <property name="jar.pkg" value="examples/session/stateless"/>
+
+
+ <!-- Include common.xml -->
+ &include;
+
+ <property name="assemble.dir" value="${assemble.ejbjar}"/>
+ <property name="deploy.file" value="${ejbjar}"/>
+
+ <target name="jar" depends="compile_common, create_ejbjar_common"/>
+ <target name="ear" depends="jar,create_ear_common"/>
+
+ <target name="clean_all" depends="clean_common, clean_ejbjar_common, clean_clientjar_common"/>
+</project>
+
|
