You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ps...@apache.org on 2004/06/09 11:31:33 UTC
cvs commit: logging-log4j/src/java/org/apache/log4j/net JMSReceiver.java
psmith 2004/06/09 02:31:33
Modified: src/java/org/apache/log4j/net JMSReceiver.java
Log:
Applied a patch supplied by Stephen Pain that allows for a property
that is used to load a jndi.properties file, which is required for some
J2EE servers such as weblogic.
This is not the most ideal change, but will work in the Web start environment, I hope...
Revision Changes Path
1.6 +39 -5 logging-log4j/src/java/org/apache/log4j/net/JMSReceiver.java
Index: JMSReceiver.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/net/JMSReceiver.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- JMSReceiver.java 20 Oct 2003 05:27:15 -0000 1.5
+++ JMSReceiver.java 9 Jun 2004 09:31:33 -0000 1.6
@@ -7,6 +7,9 @@
package org.apache.log4j.net;
+import java.io.FileInputStream;
+import java.util.Properties;
+
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TopicConnection;
@@ -40,6 +43,8 @@
implementation.
@author Mark Womack
+ @author Paul Smith
+ @author Stephen Pain
@since 1.3
*/
public class JMSReceiver extends Receiver implements MessageListener {
@@ -53,21 +58,39 @@
protected String userId;
protected String password;
protected TopicConnection topicConnection;
+ protected String jndiPath;
private String remoteInfo;
+ private String providerUrl;
public JMSReceiver() { }
public JMSReceiver(String _topicFactoryName, String _topicName,
- String _userId, String _password) {
-
+ String _userId, String _password, String _jndiPath) {
topicFactoryName = _topicFactoryName;
topicName = _topicName;
userId = _userId;
password = _password;
+ jndiPath = _jndiPath;
}
/**
+ * Sets the path to a properties file containing
+ * the initial context and jndi provider url
+ */
+ public void setJndiPath(String _jndiPath) {
+ jndiPath = _jndiPath;
+ }
+
+ /**
+ * Gets the path to a properties file containing
+ * the initial context and jndi provider url
+ */
+ public String getJndiPath() {
+ return jndiPath;
+ }
+
+ /**
Sets the JMS topic factory name to use when creating the
JMS connection. */
public void setTopicFactoryName(String _topicFactoryName) {
@@ -165,8 +188,18 @@
if (!isActive()) {
try {
remoteInfo = topicFactoryName + ":" + topicName;
-
- Context ctx = new InitialContext();
+
+ Context ctx = null;
+ if (jndiPath == null || jndiPath.equals("")) {
+ ctx = new InitialContext();
+ } else {
+ Properties p = new Properties();
+ p.load(new FileInputStream(jndiPath));
+ ctx = new InitialContext(p);
+ }
+
+ // give some more flexibility about the choice of a tab name
+ providerUrl = (String)ctx.getEnvironment().get(Context.PROVIDER_URL);
TopicConnectionFactory topicConnectionFactory;
topicConnectionFactory =
(TopicConnectionFactory) lookup(ctx, topicFactoryName);
@@ -233,7 +266,8 @@
// store the known remote info in an event property
event.setProperty("log4j.remoteSourceInfo", remoteInfo);
-
+ event.setProperty("log4j.jmsProviderUrl", providerUrl);
+
doPost(event);
} else {
logger.warn("Received message is of type "+message.getJMSType()
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org