Author: ptahchiev Date: Thu May 22 10:48:12 2008 New Revision: 659176 URL: http://svn.apache.org/viewvc?rev=659176&view=rev Log: Added an example of the jms mdb. Initial state - should be improved.
Added: jakarta/cactus/trunk/samples/ejb/src/main/java/org/apache/cactus/sample/ejb/EmailMDB.java (with props) jakarta/cactus/trunk/samples/ejb/src/main/java/org/apache/cactus/sample/ejb/TestSampleMDB.java (with props) jakarta/cactus/trunk/samples/ejb/src/main/resources/jboss.xml (with props) Modified: jakarta/cactus/trunk/samples/ejb/pom.xml jakarta/cactus/trunk/samples/ejb/src/main/resources/ejb-jar.xml Modified: jakarta/cactus/trunk/samples/ejb/pom.xml URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/samples/ejb/pom.xml?rev=659176&r1=659175&r2=659176&view=diff ============================================================================== --- jakarta/cactus/trunk/samples/ejb/pom.xml (original) +++ jakarta/cactus/trunk/samples/ejb/pom.xml Thu May 22 10:48:12 2008 @@ -22,7 +22,7 @@ <parent> <groupId>org.apache.cactus</groupId> <artifactId>cactus.samples</artifactId> - <version>1.8.0-SNAPSHOT</version> + <version>1.8.1-SNAPSHOT</version> </parent> <artifactId>cactus.samples.ejb</artifactId> <name>Cactus Ejb Samples - Parent Project</name> @@ -67,12 +67,12 @@ <dependency> <groupId>org.codehaus.cargo</groupId> <artifactId>cargo-core-uberjar</artifactId> - <version>0.9</version> + <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.codehaus.cargo</groupId> <artifactId>cargo-ant</artifactId> - <version>0.9</version> + <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>xerces</groupId> @@ -104,10 +104,25 @@ <artifactId>ivy</artifactId> <version>2.0.0-beta1</version> </dependency> - <dependency> + <!--dependency> <groupId>geronimo-spec</groupId> <artifactId>geronimo-spec-ejb</artifactId> <version>2.1-rc4</version> + </dependency--> + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-jms_1.1_spec</artifactId> + <version>1.0</version> + </dependency> + <!--dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-ejb_2.1_spec</artifactId> + <version>1.0</version> + </dependency--> + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-ejb_3.0_spec</artifactId> + <version>1.0</version> </dependency> </dependencies> <build> Added: jakarta/cactus/trunk/samples/ejb/src/main/java/org/apache/cactus/sample/ejb/EmailMDB.java URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/samples/ejb/src/main/java/org/apache/cactus/sample/ejb/EmailMDB.java?rev=659176&view=auto ============================================================================== --- jakarta/cactus/trunk/samples/ejb/src/main/java/org/apache/cactus/sample/ejb/EmailMDB.java (added) +++ jakarta/cactus/trunk/samples/ejb/src/main/java/org/apache/cactus/sample/ejb/EmailMDB.java Thu May 22 10:48:12 2008 @@ -0,0 +1,56 @@ +package org.apache.cactus.sample.ejb; + +import java.util.*; +import javax.ejb.*; +import javax.jms.*; + +public class EmailMDB implements MessageDrivenBean, MessageListener +{ + + private MessageDrivenContext context; + + // -------------------------------------------------------------- + // EJB Methods from MessageDrivenBean interface + // -------------------------------------------------------------- + public void ejbCreate() { + System.out.println("EmailMDB: ejbCreate called"); + } + + public void ejbRemove() { + System.out.println("EmailMDB: ejbRemove called"); + } + + public void setMessageDrivenContext(MessageDrivenContext context) { + System.out.println("setMessageDrivenContext called"); + this.context = context; + } + + + // -------------------------------------------------------------- + // Method from MessageListener interface + // -------------------------------------------------------------- + /** + * Take in a MapMessage and use the EmailHelper to send out an email message + */ + public void onMessage(Message message) { + System.out.println("EmailMDB: onMessage called"); + MapMessage mapmessage = (MapMessage) message; + try { + + // Go through the map message and create a map for sendmail(Map) + Enumeration e = mapmessage.getMapNames(); + Hashtable mail = new Hashtable(); + + while (e.hasMoreElements()) { + String key = (String) e.nextElement(); + String val = mapmessage.getString(key); + mail.put(key, val); + } + + System.out.println("Sending email: EmailHelper.sendmail(mail)"); + + } catch(Exception e) { + e.printStackTrace(); + } + } +} Propchange: jakarta/cactus/trunk/samples/ejb/src/main/java/org/apache/cactus/sample/ejb/EmailMDB.java ------------------------------------------------------------------------------ svn:eol-style = native Added: jakarta/cactus/trunk/samples/ejb/src/main/java/org/apache/cactus/sample/ejb/TestSampleMDB.java URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/samples/ejb/src/main/java/org/apache/cactus/sample/ejb/TestSampleMDB.java?rev=659176&view=auto ============================================================================== --- jakarta/cactus/trunk/samples/ejb/src/main/java/org/apache/cactus/sample/ejb/TestSampleMDB.java (added) +++ jakarta/cactus/trunk/samples/ejb/src/main/java/org/apache/cactus/sample/ejb/TestSampleMDB.java Thu May 22 10:48:12 2008 @@ -0,0 +1,116 @@ +/* + * ======================================================================== + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ======================================================================== + */ +package org.apache.cactus.sample.ejb; + +import java.util.Properties; + +import javax.jms.JMSException; +import javax.jms.Queue; +import javax.jms.QueueConnection; +import javax.jms.QueueConnectionFactory; +import javax.jms.QueueSender; +import javax.jms.QueueSession; +import javax.jms.Session; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import org.apache.cactus.JmsTestCase; + +/** + * Tests of the <code>SampleTag</code> class. + * + * @version $Id: TestSampleTag.java 238816 2004-02-29 16:36:46Z vmassol $ + */ +public class TestSampleMDB extends JmsTestCase +{ + private static String QUEUE_NAME = "CactusQueue"; + private static String PROVIDER_URL = "t3://localhost:7001"; + private static String CONNECTION_FACTORY = "javax.jms.QueueConnectionFactory"; + + private QueueSender sender; + private QueueSession session; + + public void setUp() + { + try { + + Context con = getInitialContext(); + + // Lookup a JMS connection factory + QueueConnectionFactory conFactory = + (QueueConnectionFactory) con.lookup(CONNECTION_FACTORY); + + // Create a JMS connection + QueueConnection connection = conFactory.createQueueConnection(); + + // Create a JMS session object + session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); + + // Lookup a JMS queue + Queue chatQueue = (Queue) con.lookup(QUEUE_NAME); + + // Create a JMS sender + sender = session.createSender(chatQueue); + } catch(Exception e) { + e.printStackTrace(); + } + + } + + public TestSampleMDB(String msg) + { + super(msg); + } + + public void testSayHello() + { + + + // send the mapmessage to the Queue + try + { + sender.send(message); + this.message.setStringProperty("aaaa", "bbbb"); + } catch (JMSException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /** + * Method: getInitialContext() + * + * Login to JNDI + * + * @return Context The initial context + */ + private Context getInitialContext() throws NamingException { + Properties env = new Properties(); + env.put("cactus.jndi.initialContextFactory", "weblogic.jndi.WLInitialContextFactory"); + env.put("cactus.jndi.providerUrl", PROVIDER_URL); + env.put("cactus.jndi.securityPrincipal", "system"); + env.put("cactus.jndi.securityCredentials", "weblogic"); + + return new InitialContext(env); + } + +} Propchange: jakarta/cactus/trunk/samples/ejb/src/main/java/org/apache/cactus/sample/ejb/TestSampleMDB.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: jakarta/cactus/trunk/samples/ejb/src/main/resources/ejb-jar.xml URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/samples/ejb/src/main/resources/ejb-jar.xml?rev=659176&r1=659175&r2=659176&view=diff ============================================================================== --- jakarta/cactus/trunk/samples/ejb/src/main/resources/ejb-jar.xml (original) +++ jakarta/cactus/trunk/samples/ejb/src/main/resources/ejb-jar.xml Thu May 22 10:48:12 2008 @@ -17,6 +17,14 @@ <session-type>Stateless</session-type> <transaction-type>Container</transaction-type> </session> + <message-driven> + <ejb-name>EmailMDB</ejb-name> + <ejb-class>org.apache.cactus.sample.ejb.EmailMDB</ejb-class> + <transaction-type>Container</transaction-type> + <message-driven-destination> + <destination-type>javax.jms.Queue</destination-type> + </message-driven-destination> + </message-driven> </enterprise-beans> <assembly-descriptor> <container-transaction> Added: jakarta/cactus/trunk/samples/ejb/src/main/resources/jboss.xml URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/samples/ejb/src/main/resources/jboss.xml?rev=659176&view=auto ============================================================================== --- jakarta/cactus/trunk/samples/ejb/src/main/resources/jboss.xml (added) +++ jakarta/cactus/trunk/samples/ejb/src/main/resources/jboss.xml Thu May 22 10:48:12 2008 @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="Cp1252"?> +<jboss> + <enterprise-beans> + <message-driven> + <ejb-name>EmailMDB</ejb-name> + <configuration-name>Standard Message Driven Bean</configuration-name> + <destination-jndi-name>queue/cactusQueue</destination-jndi-name> + </message-driven> + </enterprise-beans> +</jboss> \ No newline at end of file Propchange: jakarta/cactus/trunk/samples/ejb/src/main/resources/jboss.xml ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]