diff options
Diffstat (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd')
5 files changed, 118 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/LogBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/LogBean.java new file mode 100644 index 0000000..89364d9 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/LogBean.java @@ -0,0 +1,22 @@ +package examples.messaging.dd;
+
+import javax.jms.*;
+
+public class LogBean implements MessageListener {
+
+ public LogBean() {
+ }
+
+ public void onMessage(Message msg) {
+ if (msg instanceof TextMessage) {
+ TextMessage tm = (TextMessage) msg;
+ try {
+ String text = tm.getText();
+ System.err.println("Received new message : " + text);
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/LogClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/LogClient.java new file mode 100644 index 0000000..14b6008 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/LogClient.java @@ -0,0 +1,34 @@ +package examples.messaging.dd;
+
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+import javax.naming.InitialContext;
+
+public class LogClient {
+
+ public static void main(String[] args) throws Exception {
+ InitialContext ctx = new InitialContext(System.getProperties());
+
+ Topic topic = (Topic) ctx.lookup("jms/Topic");
+ TopicConnectionFactory factory =
+ (TopicConnectionFactory) ctx
+ .lookup("jms/TopicConnectionFactory");
+ TopicConnection connection = factory.createTopicConnection();
+ TopicSession session = connection.createTopicSession(false,
+ Session.AUTO_ACKNOWLEDGE);
+
+ TopicPublisher publisher = session.createPublisher(topic);
+
+ // create and publish a message
+ TextMessage msg = session.createTextMessage();
+ msg.setText("This is a test message.");
+ publisher.publish(msg);
+
+ System.out.println("Message published. Please check application server's console to see the response from MDB.");
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/META-INF/ejb-jar.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/META-INF/ejb-jar.xml new file mode 100644 index 0000000..92cee32 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/META-INF/ejb-jar.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<ejb-jar> + <enterprise-beans> + <message-driven> + <ejb-name>LogBeanDD</ejb-name> + <ejb-class>examples.messaging.dd.LogBean</ejb-class> + <messaging-type>javax.jms.MessageListener</messaging-type> + <transaction-type>Bean</transaction-type> + <message-destination-type>javax.jms.Topic</message-destination-type> + <!-- further details --> + <activation-config> + <activation-config-property> + <activation-config-property-name>destinationType</activation-config-property-name> + <activation-config-property-value>javax.jms.Topic</activation-config-property-value> + </activation-config-property> + </activation-config> + </message-driven> + </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/messaging/dd/META-INF/sun-ejb-jar.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/META-INF/sun-ejb-jar.xml new file mode 100644 index 0000000..85caf26 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/META-INF/sun-ejb-jar.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<sun-ejb-jar>
+ <enterprise-beans>
+ <name>LogBeanDD</name>
+ <ejb>
+ <ejb-name>LogBeanDD</ejb-name>
+ <jndi-name>jms/Topic</jndi-name>
+ <mdb-connection-factory>
+ <jndi-name>jms/TopicConnectionFactory</jndi-name>
+ </mdb-connection-factory>
+ </ejb>
+ </enterprise-beans>
+</sun-ejb-jar>
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/build.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/build.xml new file mode 100644 index 0000000..b6b0013 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/build.xml @@ -0,0 +1,30 @@ +<?xml version="1.0"?> +<!DOCTYPE project [ <!ENTITY include SYSTEM "../../../../etc/common.xml"> ]> + +<project name="ejb3-examples-messaging-dd" 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="MessageDrivenLogDD"/> + <property name="client.class" value="examples.messaging.dd.LogClient"/> + <property name="app.pkg" value="examples/messaging/dd"/> + <property name="package" value="${app.pkg}"/> + <property name="pack.dir" value="${src.dir}/${app.pkg}"/> + <property name="jar.pkg" value="${app.pkg}"/> + + <!-- 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> + |
