diff options
Diffstat (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session')
22 files changed, 722 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/Count.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/Count.java new file mode 100644 index 0000000..21be867 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/Count.java @@ -0,0 +1,24 @@ +package examples.session.stateful;
+
+/**
+ * The business interface - a plain Java interface with only business methods.
+ */
+public interface Count {
+
+ /**
+ * Increments the counter by 1
+ */
+ public int count();
+
+ /**
+ * Sets the counter to val
+ *
+ * @param val
+ */
+ public void set(int val);
+
+ /**
+ * removes the counter
+ */
+ public void remove();
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountBean.java new file mode 100644 index 0000000..6afd4a3 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountBean.java @@ -0,0 +1,53 @@ +package examples.session.stateful;
+
+import javax.ejb.*;
+
+/**
+ * A Stateful Session Bean Class that shows the basics of
+ * how to write a stateful session bean.
+ *
+ * This Bean is initialized to some integer value. It has a
+ * business method which increments the value.
+ *
+ * The annotations below declare that:
+ * <ul>
+ * <li>this is a Stateful Session Bean
+ * <li>the bean's remote business interface is <code>Count</code>
+ * <li>any lifecycle callbacks go to the class <code>CountCallbacks</code>
+ * </ul>
+ */
+
+@Stateful
+@Remote(Count.class)
+@Interceptors(CountCallbacks.class)
+public class CountBean implements Count {
+
+ /** The current counter is our conversational state. */
+ private int val;
+
+ /**
+ * The count() business method.
+ */
+ public int count() {
+ System.out.println("count()");
+ return ++val;
+ }
+
+ /**
+ * The set() business method.
+ */
+ public void set(int val) {
+ this.val = val;
+ System.out.println("set()");
+ }
+
+ /**
+ * The remove method is annotated so that the container knows
+ * it can remove the bean after this method returns.
+ */
+ @Remove
+ public void remove() {
+ System.out.println("remove()");
+ }
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountCallbacks.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountCallbacks.java new file mode 100644 index 0000000..d6f6aa1 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountCallbacks.java @@ -0,0 +1,53 @@ +package examples.session.stateful;
+
+import javax.ejb.InvocationContext;
+import javax.ejb.PostActivate;
+import javax.ejb.PrePassivate;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+
+/**
+ * This class is a lifecycle callback interceptor for the Count bean.
+ * The callback methods simply print a message when invoked by the
+ * container.
+ */
+public class CountCallbacks {
+
+ public CountCallbacks() {}
+ /**
+ * Called by the container after construction
+ */
+ @PostConstruct
+ public void construct(InvocationContext ctx) throws Exception {
+ System.out.println("cb:construct() ");
+ ctx.proceed();
+ }
+
+ /**
+ * Called by the container after activation
+ */
+ @PostActivate
+ public void activate(InvocationContext ctx) throws Exception {
+ System.out.println("cb:activate()");
+ ctx.proceed();
+ }
+
+ /**
+ * Called by the container before passivation
+ */
+ @PrePassivate
+ public void passivate(InvocationContext ctx) throws Exception {
+ System.out.println("cb:passivate()");
+ ctx.proceed();
+ }
+
+ /**
+ * Called by the container before destruction
+ */
+ @PreDestroy
+ public void destroy(InvocationContext ctx) throws Exception {
+ System.out.println("cb:destroy()");
+ ctx.proceed();
+ }
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountClient.java new file mode 100644 index 0000000..3536705 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountClient.java @@ -0,0 +1,63 @@ +package examples.session.stateful;
+
+import javax.naming.*;
+
+/**
+ * This class is a simple client for a stateful session bean.
+ *
+ * To illustrate how passivation works, configure your EJB server
+ * to allow only 2 stateful session beans in memory. (Consult your
+ * vendor documentation for details on how to do this.) We create
+ * 3 beans in this example to see how and when beans are passivated.
+ */
+public class CountClient {
+
+ public static final int noOfClients = 3;
+
+ public static void main(String[] args) {
+ try {
+ /* Get a reference to the bean */
+ Context ctx = new InitialContext(System.getProperties());
+
+ /* An array to hold the Count beans */
+ Count count[] = new Count[noOfClients];
+ int countVal = 0;
+
+ /* Create and count() on each member of array */
+ System.out.println("Instantiating beans...");
+ for (int i = 0; i < noOfClients; i++) {
+ count[i] = (Count) ctx.lookup(Count.class.getName());
+
+ /* initialize each bean to the current count value */
+ count[i].set(countVal);
+
+ /* Add 1 and print */
+ countVal = count[i].count();
+ System.out.println(countVal);
+
+ /* Sleep for 1/2 second */
+ Thread.sleep(100);
+ }
+
+ /*
+ * Let's call count() on each bean to make sure the
+ * beans were passivated and activated properly.
+ */
+ System.out.println("Calling count() on beans...");
+ for (int i = 0; i < noOfClients; i++) {
+
+ /* Add 1 and print */
+ countVal = count[i].count();
+ System.out.println(countVal);
+
+ /* call remove to let the container dispose of the bean */
+ count[i].remove();
+
+ /* Sleep for 1/2 second */
+ Thread.sleep(50);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/META-INF/ejb-jar.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/META-INF/ejb-jar.xml new file mode 100644 index 0000000..9503e74 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/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/Gerald Examples/src/examples/session/stateful/build.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/build.xml new file mode 100644 index 0000000..d958085 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/build.xml @@ -0,0 +1,29 @@ +<?xml version="1.0"?> +<!DOCTYPE project [ <!ENTITY include SYSTEM "../../../../etc/common.xml"> ]> + +<project name="ejb3-examples-session-stateful" default="deploy" + 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="StatefulSession"/> + <property name="client.class" value="examples.session.stateful.CountClient"/> + <property name="app.pkg" value="examples/session/stateful"/> + <property name="package" value="${app.pkg}"/> + <property name="pack.dir" value="${src.dir}/${app.pkg}"/> + <property name="jar.pkg" value="examples/session/stateful"/> + + <!-- Include common.xml --> + &include; + + <target name="jar" depends="compile_common, create_ejbjar_common"/> + + <target name="deploy" depends="jar"> + <copy file="${assemble.ejbjar}/${ejbjar}" + todir="${deploy.dir}"/> + </target> + +</project> + diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/Count.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/Count.java new file mode 100644 index 0000000..f20ae5e --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/Count.java @@ -0,0 +1,24 @@ +package examples.session.stateful_dd;
+
+/**
+ * The business interface - a plain Java interface with only business methods.
+ */
+public interface Count {
+
+ /**
+ * Increments the counter by 1
+ */
+ public int count();
+
+ /**
+ * Sets the counter to val
+ *
+ * @param val
+ */
+ public void set(int val);
+
+ /**
+ * removes the counter
+ */
+ public void remove();
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/CountBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/CountBean.java new file mode 100644 index 0000000..0a2ab2c --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/CountBean.java @@ -0,0 +1,47 @@ +package examples.session.stateful_dd;
+
+import java.io.Serializable;
+
+/**
+ * A Stateful Session Bean Class that shows the basics of
+ * how to write a stateful session bean.
+ *
+ * This Bean is initialized to some integer value. It has a
+ * business method which increments the value.
+ *
+ * The annotations below declare that:
+ * <ul>
+ * <li>this is a Stateful Session Bean
+ * <li>the bean's remote business interface is <code>Count</code>
+ * <li>any lifecycle callbacks go to the class <code>CountCallbacks</code>
+ * </ul>
+ */
+
+public class CountBean implements Count {
+
+ /** The current counter is our conversational state. */
+ private int val;
+
+ /**
+ * The count() business method.
+ */
+ public int count() {
+ System.out.println("count()");
+ return ++val;
+ }
+
+ /**
+ * The set() business method.
+ */
+ public void set(int val) {
+ this.val = val;
+ System.out.println("set()");
+ }
+
+ /**
+ */
+ public void remove() {
+ System.out.println("remove()");
+ }
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/CountCallbacks.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/CountCallbacks.java new file mode 100644 index 0000000..f2ed8b0 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/CountCallbacks.java @@ -0,0 +1,43 @@ +package examples.session.stateful_dd;
+
+import javax.ejb.InvocationContext;
+
+/**
+ * This class is a lifecycle callback interceptor for the Count bean.
+ * The callback methods simply print a message when invoked by
+ * the container.
+ */
+public class CountCallbacks {
+
+ public CountCallbacks() {}
+
+ /**
+ * Called by the container after construction
+ */
+ public void construct(InvocationContext ctx) {
+ System.out.println("cb:construct()");
+ }
+
+ /**
+ * Called by the container after activation
+ */
+ public void activate(InvocationContext ctx) {
+ System.out.println("cb:activate()");
+ }
+
+ /**
+ * Called by the container before passivation
+ */
+ public void passivate(InvocationContext ctx) {
+ System.out.println("cb:passivate()");
+ }
+
+ /**
+ * Called by the container before destruction
+ */
+
+ public void destroy(InvocationContext ctx) {
+ System.out.println("cb:destroy()");
+ }
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/CountClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/CountClient.java new file mode 100644 index 0000000..46fb0cc --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/CountClient.java @@ -0,0 +1,63 @@ +package examples.session.stateful_dd;
+
+import javax.naming.*;
+
+/**
+ * This class is a simple client for a stateful session bean.
+ *
+ * To illustrate how passivation works, configure your EJB server
+ * to allow only 2 stateful session beans in memory. (Consult your
+ * vendor documentation for details on how to do this.) We create
+ * 3 beans in this example to see how and when beans are passivated.
+ */
+public class CountClient {
+
+ public static final int noOfClients = 3;
+
+ public static void main(String[] args) {
+ try {
+ /* Get a reference to the bean */
+ Context ctx = new InitialContext();
+
+ /* An array to hold the Count beans */
+ Count count[] = new Count[noOfClients];
+ int countVal = 0;
+
+ /* Create and count() on each member of array */
+ System.out.println("Instantiating beans...");
+ for (int i = 0; i < noOfClients; i++) {
+ //count[i] = (Count) ctx.lookup("StatefulCount" );
+ count[i] = (Count) ctx.lookup(Count.class.getName());
+ /* initialize each bean to the current count value */
+ count[i].set(countVal);
+
+ /* Add 1 and print */
+ countVal = count[i].count();
+ System.out.println(countVal);
+
+ /* Sleep for 1/2 second */
+ Thread.sleep(100);
+ }
+
+ /*
+ * Let's call count() on each bean to make sure the
+ * beans were passivated and activated properly.
+ */
+ System.out.println("Calling count() on beans...");
+ for (int i = 0; i < noOfClients; i++) {
+
+ /* Add 1 and print */
+ countVal = count[i].count();
+ System.out.println(countVal);
+
+ /* call remove to let the container dispose of the bean */
+ count[i].remove();
+
+ /* Sleep for 1/2 second */
+ Thread.sleep(50);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/META-INF/ejb-jar.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/META-INF/ejb-jar.xml new file mode 100644 index 0000000..a483584 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/META-INF/ejb-jar.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8" ?>
+<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
+ <description>Stateful Session Bean Example</description>
+ <display-name>Stateful Session Bean Example</display-name>
+ <enterprise-beans>
+ <session>
+ <ejb-name>CountBean</ejb-name>
+ <business-remote>examples.session.stateful_dd.Count</business-remote>
+ <ejb-class>examples.session.stateful_dd.CountBean</ejb-class>
+ <session-type>Stateful</session-type>
+ <transaction-type>Container</transaction-type>
+ </session>
+ </enterprise-beans>
+
+ <interceptors>
+ <interceptor>
+ <interceptor-class>examples.session.stateful_dd.CountCallbacks
+ </interceptor-class>
+ <post-construct><lifecycle-callback-method>construct</lifecycle-callback-method></post-construct>
+ <post-activate><lifecycle-callback-method>activate</lifecycle-callback-method></post-activate>
+ <pre-passivate><lifecycle-callback-method>passivate</lifecycle-callback-method></pre-passivate>
+<!-- <pre-destroy><lifecycle-callback-method>destroy</lifecycle-callback-method></pre-destroy> -->
+ </interceptor>
+ </interceptors>
+
+ <assembly-descriptor>
+ <interceptor-binding>
+ <ejb-name>CountBean</ejb-name>
+ <interceptor-class>examples.session.stateful_dd.CountCallbacks
+ </interceptor-class>
+ </interceptor-binding>
+ </assembly-descriptor>
+</ejb-jar>
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/build.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/build.xml new file mode 100644 index 0000000..8c9181a --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/build.xml @@ -0,0 +1,32 @@ +<?xml version="1.0"?> +<!DOCTYPE project [ <!ENTITY include SYSTEM "../../../../etc/common.xml"> ]> + +<project name="ejb3-examples-session-statefull_dd" default="all" + 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="StatefulSession-Hello"/> + <property name="client.class" value="examples.session.stateful_dd.CountClient"/> + <property name="app.pkg" value="examples/session/stateful_dd"/> + <property name="package" value="${app.pkg}"/> + <property name="pack.dir" value="${src.dir}/${app.pkg}"/> + <property name="jar.pkg" value="examples/session/stateful_dd"/> + + <!-- Include common.xml --> + &include; + + <target name="jar" depends="compile_common, create_ejbjar_common"/> + <target name="all" depends="compile_common, jar, deploy"/> + + <target name="deploy" depends="jar"> + <copy file="${assemble.ejbjar}/${ejbjar}" + todir="${deploy.dir}"/> + </target> + + <target name="clean" depends="undeploy_common, clean_common" /> + +</project> + diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/Hello.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald 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/Gerald 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/Gerald Examples/src/examples/session/stateless/HelloBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald 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/Gerald 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/Gerald Examples/src/examples/session/stateless/HelloClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/HelloClient.java new file mode 100644 index 0000000..29ebd03 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/HelloClient.java @@ -0,0 +1,35 @@ +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.
+ */
+ Context ctx = new InitialContext(System.getProperties());
+
+ /*
+ * Get a reference to a bean instance, looked up by class name
+ */
+ Hello hello = (Hello) ctx.lookup(Hello.class.getName());
+
+ /*
+ * 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/Gerald Examples/src/examples/session/stateless/META-INF/ejb-jar.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald 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/Gerald 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/Gerald Examples/src/examples/session/stateless/build.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/build.xml new file mode 100644 index 0000000..33b4751 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/build.xml @@ -0,0 +1,32 @@ +<?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="deploy.file" value="${assemble.ejbjar}/${ejbjar}" /> + + <target name="jar" depends="compile_common, create_ejbjar_common"/> + <target name="ear" depends="jar,create_ear_common"/> + + <target name="deploy" depends="jar"> + <copy file="${deploy.file}" todir="${deploy.dir}"/> + </target> + +</project> + diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/Hello.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/Hello.java new file mode 100644 index 0000000..22ad6ea --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/Hello.java @@ -0,0 +1,15 @@ +package examples.session.ws;
+
+
+/**
+ * This is the Hello business interface.
+ */
+
+
+public interface Hello {
+
+ public String hello();
+
+ public void foo();
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/HelloBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/HelloBean.java new file mode 100644 index 0000000..13e6eef --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/HelloBean.java @@ -0,0 +1,18 @@ +package examples.session.ws;
+
+import javax.ejb.Stateless;
+import javax.jws.WebService;
+
+@Stateless
+@WebService(serviceName="Greeter", portName="GreeterPort")
+public class HelloBean {
+
+ public String hello() {
+ System.out.println("hello()");
+ return "Hello, World!";
+ }
+
+ public void foo() {
+ ;
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/JAXWSClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/JAXWSClient.java new file mode 100644 index 0000000..be8401e --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/JAXWSClient.java @@ -0,0 +1,40 @@ +package examples.session.ws;
+
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+
+/**
+ * This is an example of a standalone JAX-WS client. To compile,
+ * it requires some XML artifacts to be generated from the service's
+ * WSDL. This is done in the build file.
+ *
+ * The mapped XML classes used her are
+ * 1. the HelloBean port type class (this is NOT the bean impl. class!)
+ * 2. the Greeter service class
+ */
+public class JAXWSClient {
+
+ static String host = "localhost";
+ static String portType = "HelloBean";
+ static String serviceName = "Greeter";
+ static String serviceEndpointAddress = "http://" + host + ":8080/" + serviceName;
+ static String nameSpace = "urn:ws.session.examples";
+
+ public static void main(String[] args) throws Exception {
+
+ URL wsdlLocation = new URL(serviceEndpointAddress + "/" + portType + "?WSDL");
+ QName serviceNameQ = new QName( nameSpace, serviceName);
+
+ // dynamic service usage
+ Service service = Service.create(wsdlLocation, serviceNameQ);
+ HelloBean firstGreeterPort = service.getPort(HelloBean.class);
+ System.out.println("1: " + firstGreeterPort.hello());
+
+ // static service usage
+// Greeter greeter = new Greeter();
+// HelloBean secondGreeterPort = greeter.getGreeterPort();
+// System.out.println("2: " +secondGreeterPort.hello());
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/META-INF/ejb-jar.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/META-INF/ejb-jar.xml new file mode 100644 index 0000000..9503e74 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/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/Gerald Examples/src/examples/session/ws/build.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/build.xml new file mode 100644 index 0000000..2d4a975 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/build.xml @@ -0,0 +1,72 @@ +<?xml version="1.0"?> +<!DOCTYPE project [ <!ENTITY include SYSTEM "../../../../etc/common.xml"> ]> + +<project name="ejb3-examples-session-ws" default="all" + basedir="../../../.."> + + <!-- properties overriding common ones --> + <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="WS"/> + <property name="client.class" value="examples.session.ws.JAXWSClient"/> + <property name="app.pkg" value="examples/session/ws"/> + <property name="package" value="${app.pkg}"/> + <property name="pack.dir" value="${src.dir}/${app.pkg}"/> + <property name="jar.pkg" value="examples/session/ws"/> + <property name="ServiceName" value="Greeter" /> + <property name="PortType" value="HelloBean" /> + + <!-- Include common.xml --> + &include; + + <!-- specific properties --> + <property name="deploy.file" value="${ejbjar}" /> + <property name="assemble.dir" value="${assemble.ejbjar}" /> + + <!-- targets --> + <target name="client_jar" depends="compile_client, create_client_jar"/> + <target name="all" depends="client_jar"/> + + <target name="compile_service" depends="init_common"> + <mkdir dir="${build.classes.dir}"/> + <javac srcdir="${pack.dir}" debug="true" excludes="**/*Client.java" + destdir="${build.classes.dir}" + classpath="${build.classpath}"/> + </target> + + <target name="compile_client" depends="init_common,clean_clientjar_common"> + <mkdir dir="${assemble.clientjar}"/> + <mkdir dir="${build.classes.dir}"/> + <get src="${service.wsdl}" dest="${build.classes.dir}/service.wsdl"/> + <wsimport + fork="true" keep="true" + wsdl="${build.classes.dir}/service.wsdl" + sourcedestdir="${build.classes.dir}" + destdir="${assemble.clientjar}" > + </wsimport> + <javac srcdir="${pack.dir}" debug="true" includes="**/*Client.java" + destdir="${assemble.clientjar}" + classpath="${build.classpath}"/> + </target> + + <target name="run_wsclient_standalone" depends="client_jar"> + <java classname="${client.class}" + classpath="${assemble.clientjar}/${clientjar};${appserver.home}/lib/appserv-rt.jar;${appserver.home}/lib/appserv-ws.jar;${appserver.home}/lib/appserv-admin.jar;${appserver.home}/lib/javaee.jar;" fork="yes"> + </java> + </target> + + <target name="create_ejbjar" depends="clean_ejbjar_common,compile_service"> + <mkdir dir="${assemble.ejbjar}"/> + <jar destfile="${assemble.ejbjar}/${ejbjar}"> + <zipfileset dir="${build.classesdir}/${app.pkg}/" includes="**/*.class" + excludes="**/servlet/, **/client/" prefix="${jar.pkg}"/> + <fileset dir="${src.dir}/${package}" includes="META-INF/${jarDD}"/> + </jar> + </target> + + <target name="deploy" depends="compile_service,create_ejbjar, deploy_common" /> + <target name="clean" depends="undeploy_common, clean_common" /> + +</project> + |
