Commits

Anonymous committed fa80b21

QUARTZ-765: JNDI Parameters from JobDataMap are not being honored

git-svn-id: http://svn.opensymphony.com/svn/quartz/trunk@92669f7d36a-ea1c-0410-88ea-9fd03e4c9665

Comments (0)

Files changed (2)

src/java/org/quartz/jobs/ee/jms/SendDestinationMessageJob.java

  */
 public final class SendDestinationMessageJob implements Job {
 
-	public void execute(final JobExecutionContext jobCtx)
-			throws JobExecutionException {
-		Connection conn = null;
+    public void execute(final JobExecutionContext jobCtx)
+            throws JobExecutionException {
+        Connection conn = null;
 
-		Session sess = null;
+        Session sess = null;
 
-		MessageProducer producer = null;
+        MessageProducer producer = null;
 
-		try {
-			final JobDetail detail = jobCtx.getJobDetail();
+        try {
+            final JobDetail detail = jobCtx.getJobDetail();
 
-			final JobDataMap dataMap = detail.getJobDataMap();
+            final JobDataMap dataMap = detail.getJobDataMap();
 
-			final Context namingCtx = JmsHelper.getInitialContext(dataMap);
+            final Context namingCtx = JmsHelper.getInitialContext(dataMap);
 
-			final ConnectionFactory factory = (ConnectionFactory) namingCtx
-					.lookup(JmsHelper.JMS_CONNECTION_FACTORY_JNDI);
+            final ConnectionFactory connFactory = (ConnectionFactory) namingCtx
+                    .lookup(dataMap
+                            .getString(JmsHelper.JMS_CONNECTION_FACTORY_JNDI));
 
-			if (!JmsHelper.isDestinationSecure(dataMap)) {
-				conn = factory.createConnection();
-			} else {
-				final String user = dataMap.getString(JmsHelper.JMS_USER);
+            if (!JmsHelper.isDestinationSecure(dataMap)) {
+                conn = connFactory.createConnection();
+            } else {
+                final String user = dataMap.getString(JmsHelper.JMS_USER);
 
-				final String password = dataMap
-						.getString(JmsHelper.JMS_PASSWORD);
+                final String password = dataMap
+                        .getString(JmsHelper.JMS_PASSWORD);
 
-				conn = factory.createConnection(user, password);
-			}
+                conn = connFactory.createConnection(user, password);
+            }
 
-			final boolean useTransaction = JmsHelper.useTransaction(dataMap);
+            final boolean useTransaction = JmsHelper.useTransaction(dataMap);
 
-			final int ackMode = dataMap.getInt(JmsHelper.JMS_ACK_MODE);
+            final int ackMode = dataMap.getInt(JmsHelper.JMS_ACK_MODE);
 
-			sess = conn.createSession(useTransaction, ackMode);
+            sess = conn.createSession(useTransaction, ackMode);
 
-			final Destination destination = (Destination) namingCtx
-					.lookup(JmsHelper.JMS_DESTINATION_JNDI);
+            final Destination destination = (Destination) namingCtx
+                    .lookup(dataMap.getString(JmsHelper.JMS_DESTINATION_JNDI));
 
-			producer = sess.createProducer(destination);
+            producer = sess.createProducer(destination);
 
-			final String msgFactoryClassName = dataMap
-					.getString(JmsHelper.JMS_MSG_FACTORY_CLASS_NAME);
+            final String msgFactoryClassName = dataMap
+                    .getString(JmsHelper.JMS_MSG_FACTORY_CLASS_NAME);
 
-			final JmsMessageFactory messageFactory = JmsHelper
-					.getMessageFactory(msgFactoryClassName);
+            final JmsMessageFactory messageFactory = JmsHelper
+                    .getMessageFactory(msgFactoryClassName);
 
-			final Message msg = messageFactory.createMessage(dataMap, sess);
+            final Message msg = messageFactory.createMessage(dataMap, sess);
 
-			producer.send(msg);
-		} catch (final Exception e) {
-			throw new JobExecutionException(e);
-		} finally {
-			JmsHelper.closeResource(producer);
+            producer.send(msg);
+        } catch (final Exception e) {
+            throw new JobExecutionException(e);
+        } finally {
+            JmsHelper.closeResource(producer);
 
-			JmsHelper.closeResource(sess);
+            JmsHelper.closeResource(sess);
 
-			JmsHelper.closeResource(conn);
-		}
+            JmsHelper.closeResource(conn);
+        }
 
-	}
+    }
 
 }

src/java/org/quartz/jobs/ee/jms/SendTopicMessageJob.java

 /* 
- * Copyright 2001-2009 James House 
+ * Copyright 2004-2009  James House 
  * 
  * Licensed 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 
  * 
  */
 
-/*
- * Previously Copyright (c) 2001-2004 James House
- */
 package org.quartz.jobs.ee.jms;
 
-import javax.jms.JMSException;
+import javax.jms.Connection;
 import javax.jms.Message;
-import javax.jms.Session;
 import javax.jms.Topic;
-import javax.jms.TopicConnection;
 import javax.jms.TopicConnectionFactory;
 import javax.jms.TopicPublisher;
 import javax.jms.TopicSession;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
+import javax.naming.Context;
 
 import org.quartz.Job;
 import org.quartz.JobDataMap;
 import org.quartz.JobExecutionException;
 
 /**
-* <p>
-* A <code>Job</code> that sends a <code>javax.jms.Message</code> to a 
-* <code>javax.jms.Topic</code>.
-* 
-* <p>
-* The following properties are expected to be provided in the <code>JobDataMap</code>:
-* 
-* <ul>
-* <li><code>JMS_CONNECTION_FACTORY_JNDI</code> - The JNDI name of the JMS Connection Factory.</li>
-* <li><code>JMS_DESTINATION_JNDI</code> - The JNDI name of the JMS destination.</li>
-* <li><code>JMS_USE_TXN</code> - Whether or not to use a transacted <code>javax.jms.Session</code>.</li>
-* <li><code>JMS_ACK_MODE</code> - The acknowledgement mode for the <code>javax.jms.Session</code>.</li>
-* <li><code>JMS_MSG_FACTORY_CLASS_NAME</code> - The implementation class name for the <code>JmsMessageFactory</code>.</li>
-* </ul>
-* 
-* <p>
-* The following properties are optional
-* 
-* <ul>
-* <li><code>JMS_USER</code> - The JMS user for secure destinations.
-* <li><code>JMS_PASSWORD</code> - The JMS password for secure destinations.
-* </ul>
-* 
-* <p>
-* The following properties can be used for JNDI support:
-* <ul>
-* <li><code>INITIAL_CONTEXT_FACTORY</code> - The java.naming.factory.initial setting for JNDI.
-* <li><code>PROVIDER_URL</code> - The java.naming.provider.url for JNDI.
-* </ul>
-* 
-* 
-* @see JmsMessageFactory
-* 
-* @author Weston M. Price 
-* 
-*
-*/
-public class SendTopicMessageJob implements Job {
-
-    public void execute(JobExecutionContext context)
-        throws JobExecutionException {
-
-        TopicConnectionFactory tcf = null;
-        TopicConnection connection = null;
-        TopicSession session = null;
-        Topic topic = null;
-        TopicPublisher publisher = null;
-        InitialContext ctx = null;
-        String user = null;
-        String pw = null;
-
-        final JobDetail detail = context.getJobDetail();
-        final JobDataMap jobDataMap = detail.getJobDataMap();
-
-        try {
-
-            ctx = JmsHelper.getInitialContext(jobDataMap);
-
-            tcf = (TopicConnectionFactory) ctx
-                    .lookup(JmsHelper.JMS_CONNECTION_FACTORY_JNDI);
-
-            if (JmsHelper.isDestinationSecure(jobDataMap)) {
-
-                user = jobDataMap.getString(JmsHelper.JMS_USER);
-                pw = jobDataMap.getString(JmsHelper.JMS_PASSWORD);
-                connection = tcf.createTopicConnection(user, pw);
-
-            } else {
-    
-                connection = tcf.createTopicConnection();
-
-            }
-
-            session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
-            topic = (Topic) ctx.lookup(JmsHelper.JMS_DESTINATION_JNDI);
-            publisher = session.createPublisher(topic);
-            String factoryClassName = jobDataMap.getString(JmsHelper.JMS_MSG_FACTORY_CLASS_NAME);
-            JmsMessageFactory factory = JmsHelper.getMessageFactory(factoryClassName);
-            Message m = factory.createMessage(jobDataMap, session);
-            publisher.publish(m);
-
-        } catch (NamingException e) {
-
-            throw new JobExecutionException(e);
-
-        } catch (JMSException e) {
-
-            throw new JobExecutionException(e);
-
-        } catch (JmsJobException e) {
-
-            throw new JobExecutionException(e);
-
-        } finally {
-
-            JmsHelper.closeResource(publisher);
-            JmsHelper.closeResource(session);
-            JmsHelper.closeResource(connection);
-
-        }
-
-    }
-
-}
+ * <p>
+ * A <code>Job</code> that sends a <code>javax.jms.Message</code> to a
+ * <code>javax.jms.Topic</code>.
+ * 
+ * <p>
+ * The following properties are expected to be provided in the
+ * <code>JobDataMap</code>:
+ * 
+ * <ul>
+ * <li><code>JMS_CONNECTION_FACTORY_JNDI</code> - The JNDI name of the JMS
+ * Connection Factory.</li>
+ * <li><code>JMS_DESTINATION_JNDI</code> - The JNDI name of the JMS
+ * destination.</li>
+ * <li><code>JMS_USE_TXN</code> - Whether or not to use a transacted
+ * <code>javax.jms.Session</code>.</li>
+ * <li><code>JMS_ACK_MODE</code> - The acknowledgement mode for the
+ * <code>javax.jms.Session</code>.</li>
+ * <li><code>JMS_MSG_FACTORY_CLASS_NAME</code> - The implementation class
+ * name for the <code>JmsMessageFactory</code>.</li>
+ * </ul>
+ * 
+ * <p>
+ * The following properties are optional
+ * 
+ * <ul>
+ * <li><code>JMS_USER</code> - The JMS user for secure destinations.
+ * <li><code>JMS_PASSWORD</code> - The JMS password for secure destinations.
+ * </ul>
+ * 
+ * <p>
+ * The following properties can be used for JNDI support:
+ * 
+ * <ul>
+ * <li><code>INITIAL_CONTEXT_FACTORY</code> - The java.naming.factory.initial
+ * setting for JNDI.
+ * <li><code>PROVIDER_URL</code> - The java.naming.provider.url for JNDI.
+ * </ul>
+ * 
+ * @see JmsMessageFactory
+ * 
+ * @author Fernando Ribeiro
+ * @author Weston M. Price
+ */
+public final class SendTopicMessageJob implements Job {
+
+	public void execute(final JobExecutionContext jobCtx)
+			throws JobExecutionException {
+		Connection conn = null;
+
+		TopicSession sess = null;
+
+		TopicPublisher publisher = null;
+
+		try {
+			final JobDetail detail = jobCtx.getJobDetail();
+
+			final JobDataMap dataMap = detail.getJobDataMap();
+
+			final Context namingCtx = JmsHelper.getInitialContext(dataMap);
+
+			final TopicConnectionFactory connFactory = (TopicConnectionFactory) namingCtx
+					.lookup(dataMap
+							.getString(JmsHelper.JMS_CONNECTION_FACTORY_JNDI));
+
+			if (!JmsHelper.isDestinationSecure(dataMap)) {
+				conn = connFactory.createTopicConnection();
+			} else {
+				final String user = dataMap.getString(JmsHelper.JMS_USER);
+
+				final String password = dataMap
+						.getString(JmsHelper.JMS_PASSWORD);
+
+				conn = connFactory.createTopicConnection(user, password);
+			}
+
+			final boolean useTransaction = JmsHelper.useTransaction(dataMap);
+
+			final int ackMode = dataMap.getInt(JmsHelper.JMS_ACK_MODE);
+
+			sess = (TopicSession) conn.createSession(useTransaction, ackMode);
+
+			final Topic topic = (Topic) namingCtx.lookup(dataMap
+					.getString(JmsHelper.JMS_DESTINATION_JNDI));
+
+			publisher = sess.createPublisher(topic);
+
+			final String msgFactoryClassName = dataMap
+					.getString(JmsHelper.JMS_MSG_FACTORY_CLASS_NAME);
+
+			final JmsMessageFactory messageFactory = JmsHelper
+					.getMessageFactory(msgFactoryClassName);
+
+			final Message msg = messageFactory.createMessage(dataMap, sess);
+
+			publisher.publish(msg);
+		} catch (final Exception e) {
+			throw new JobExecutionException(e);
+		} finally {
+			JmsHelper.closeResource(publisher);
+
+			JmsHelper.closeResource(sess);
+
+			JmsHelper.closeResource(conn);
+		}
+
+	}
+
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.