[logback-dev] svn commit: r1198 - in logback/trunk: logback-classic/src/main/java/ch/qos/logback/classic/net logback-classic/src/test/java/ch/qos/logback/classic/net logback-core/src/main/java/ch/qos/logback/core/net
noreply.seb at qos.ch
noreply.seb at qos.ch
Thu Jan 11 15:22:15 CET 2007
Author: seb
Date: Thu Jan 11 15:22:14 2007
New Revision: 1198
Added:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/JMSAppenderBase.java
Removed:
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTestApp.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTestApp.java
Modified:
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueAppender.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicAppender.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java
Log:
Refactored JMS**Appender.
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueAppender.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueAppender.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueAppender.java Thu Jan 11 15:22:14 2007
@@ -10,9 +10,6 @@
package ch.qos.logback.classic.net;
-import java.util.Hashtable;
-import java.util.Properties;
-
import javax.jms.ObjectMessage;
import javax.jms.Queue;
import javax.jms.QueueConnection;
@@ -22,11 +19,9 @@
import javax.jms.Session;
import javax.naming.Context;
import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
import ch.qos.logback.classic.spi.LoggingEvent;
-import ch.qos.logback.core.AppenderBase;
+import ch.qos.logback.core.net.JMSAppenderBase;
/**
* A simple appender that publishes events to a JMS Queue. The events are
@@ -98,19 +93,12 @@
*
* @author Ceki Gülcü
*/
-public class JMSQueueAppender extends AppenderBase<LoggingEvent> {
+public class JMSQueueAppender extends JMSAppenderBase<LoggingEvent> {
static int SUCCESSIVE_FAILURE_LIMIT = 3;
- String securityPrincipalName;
- String securityCredentials;
- String initialContextFactoryName;
- String urlPkgPrefixes;
- String providerURL;
String queueBindingName;
String qcfBindingName;
- String userName;
- String password;
QueueConnection queueConnection;
QueueSession queueSession;
QueueSender queueSender;
@@ -198,53 +186,6 @@
}
}
- public Context buildJNDIContext() throws NamingException {
- Context jndi = null;
-
- // addInfo("Getting initial context.");
- if (initialContextFactoryName != null) {
- Properties env = buildEnvProperties();
- jndi = new InitialContext(env);
- } else {
- jndi = new InitialContext();
- }
- return jndi;
- }
-
- public Properties buildEnvProperties() {
- Properties env = new Properties();
- env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryName);
- if (providerURL != null) {
- env.put(Context.PROVIDER_URL, providerURL);
- } else {
- addWarn("You have set InitialContextFactoryName option but not the "
- + "ProviderURL. This is likely to cause problems.");
- }
- if (urlPkgPrefixes != null) {
- env.put(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
- }
-
- if (securityPrincipalName != null) {
- env.put(Context.SECURITY_PRINCIPAL, securityPrincipalName);
- if (securityCredentials != null) {
- env.put(Context.SECURITY_CREDENTIALS, securityCredentials);
- } else {
- addWarn("You have set SecurityPrincipalName option but not the "
- + "SecurityCredentials. This is likely to cause problems.");
- }
- }
- return env;
- }
-
- protected Object lookup(Context ctx, String name) throws NamingException {
- try {
- return ctx.lookup(name);
- } catch (NameNotFoundException e) {
- addError("Could not find name [" + name + "].");
- throw e;
- }
- }
-
/**
* Close this JMSAppender. Closing releases all resources used by the
* appender. A closed appender cannot be re-opened.
@@ -293,92 +234,12 @@
if (successiveFailureCount > SUCCESSIVE_FAILURE_LIMIT) {
stop();
}
- addError("Could not send message in JMSAppender [" + name + "].", e);
+ addError("Could not send message in JMSQueueAppender [" + name + "].", e);
}
}
/**
- * Returns the value of the <b>InitialContextFactoryName</b> option. See
- * {@link #setInitialContextFactoryName} for more details on the meaning of
- * this option.
- */
- public String getInitialContextFactoryName() {
- return initialContextFactoryName;
- }
-
- /**
- * Setting the <b>InitialContextFactoryName</b> method will cause this
- * <code>JMSAppender</code> instance to use the {@link
- * InitialContext#InitialContext(Hashtable)} method instead of the no-argument
- * constructor. If you set this option, you should also at least set the
- * <b>ProviderURL</b> option.
- *
- * <p>
- * See also {@link #setProviderURL(String)}.
- */
- public void setInitialContextFactoryName(String initialContextFactoryName) {
- this.initialContextFactoryName = initialContextFactoryName;
- }
-
- public String getProviderURL() {
- return providerURL;
- }
-
- public void setProviderURL(String providerURL) {
- this.providerURL = providerURL;
- }
-
- String getURLPkgPrefixes() {
- return urlPkgPrefixes;
- }
-
- public void setURLPkgPrefixes(String urlPkgPrefixes) {
- this.urlPkgPrefixes = urlPkgPrefixes;
- }
-
- public String getSecurityCredentials() {
- return securityCredentials;
- }
-
- public void setSecurityCredentials(String securityCredentials) {
- this.securityCredentials = securityCredentials;
- }
-
- public String getSecurityPrincipalName() {
- return securityPrincipalName;
- }
-
- public void setSecurityPrincipalName(String securityPrincipalName) {
- this.securityPrincipalName = securityPrincipalName;
- }
-
- public String getUserName() {
- return userName;
- }
-
- /**
- * The user name to use when {@link
- * javax.jms.TopicConnectionFactory#createTopicConnection(String, String)}
- * creating a topic session}. If you set this option, you should also set the
- * <b>Password</b> option. See {@link #setPassword(String)}.
- */
- public void setUserName(String userName) {
- this.userName = userName;
- }
-
- public String getPassword() {
- return password;
- }
-
- /**
- * The paswword to use when creating a topic session.
- */
- public void setPassword(String password) {
- this.password = password;
- }
-
- /**
* Returns the QueueConnection used for this appender. Only valid after
* start() method has been invoked.
*/
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicAppender.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicAppender.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicAppender.java Thu Jan 11 15:22:14 2007
@@ -10,9 +10,6 @@
package ch.qos.logback.classic.net;
-import java.util.Hashtable;
-import java.util.Properties;
-
import javax.jms.ObjectMessage;
import javax.jms.Session;
import javax.jms.Topic;
@@ -22,11 +19,9 @@
import javax.jms.TopicSession;
import javax.naming.Context;
import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
import ch.qos.logback.classic.spi.LoggingEvent;
-import ch.qos.logback.core.AppenderBase;
+import ch.qos.logback.core.net.JMSAppenderBase;
/**
* A simple appender that publishes events to a JMS Topic. The events are
@@ -98,19 +93,12 @@
*
* @author Ceki Gülcü
*/
-public class JMSTopicAppender extends AppenderBase<LoggingEvent> {
+public class JMSTopicAppender extends JMSAppenderBase<LoggingEvent> {
static int SUCCESSIVE_FAILURE_LIMIT = 3;
- String securityPrincipalName;
- String securityCredentials;
- String initialContextFactoryName;
- String urlPkgPrefixes;
- String providerURL;
String topicBindingName;
String tcfBindingName;
- String userName;
- String password;
TopicConnection topicConnection;
TopicSession topicSession;
TopicPublisher topicPublisher;
@@ -198,53 +186,6 @@
}
}
- public Context buildJNDIContext() throws NamingException {
- Context jndi = null;
-
- // addInfo("Getting initial context.");
- if (initialContextFactoryName != null) {
- Properties env = buildEnvProperties();
- jndi = new InitialContext(env);
- } else {
- jndi = new InitialContext();
- }
- return jndi;
- }
-
- public Properties buildEnvProperties() {
- Properties env = new Properties();
- env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryName);
- if (providerURL != null) {
- env.put(Context.PROVIDER_URL, providerURL);
- } else {
- addWarn("You have set InitialContextFactoryName option but not the "
- + "ProviderURL. This is likely to cause problems.");
- }
- if (urlPkgPrefixes != null) {
- env.put(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
- }
-
- if (securityPrincipalName != null) {
- env.put(Context.SECURITY_PRINCIPAL, securityPrincipalName);
- if (securityCredentials != null) {
- env.put(Context.SECURITY_CREDENTIALS, securityCredentials);
- } else {
- addWarn("You have set SecurityPrincipalName option but not the "
- + "SecurityCredentials. This is likely to cause problems.");
- }
- }
- return env;
- }
-
- protected Object lookup(Context ctx, String name) throws NamingException {
- try {
- return ctx.lookup(name);
- } catch (NameNotFoundException e) {
- addError("Could not find name [" + name + "].");
- throw e;
- }
- }
-
/**
* Close this JMSAppender. Closing releases all resources used by the
* appender. A closed appender cannot be re-opened.
@@ -300,86 +241,6 @@
}
/**
- * Returns the value of the <b>InitialContextFactoryName</b> option. See
- * {@link #setInitialContextFactoryName} for more details on the meaning of
- * this option.
- */
- public String getInitialContextFactoryName() {
- return initialContextFactoryName;
- }
-
- /**
- * Setting the <b>InitialContextFactoryName</b> method will cause this
- * <code>JMSAppender</code> instance to use the {@link
- * InitialContext#InitialContext(Hashtable)} method instead of the no-argument
- * constructor. If you set this option, you should also at least set the
- * <b>ProviderURL</b> option.
- *
- * <p>
- * See also {@link #setProviderURL(String)}.
- */
- public void setInitialContextFactoryName(String initialContextFactoryName) {
- this.initialContextFactoryName = initialContextFactoryName;
- }
-
- public String getProviderURL() {
- return providerURL;
- }
-
- public void setProviderURL(String providerURL) {
- this.providerURL = providerURL;
- }
-
- String getURLPkgPrefixes() {
- return urlPkgPrefixes;
- }
-
- public void setURLPkgPrefixes(String urlPkgPrefixes) {
- this.urlPkgPrefixes = urlPkgPrefixes;
- }
-
- public String getSecurityCredentials() {
- return securityCredentials;
- }
-
- public void setSecurityCredentials(String securityCredentials) {
- this.securityCredentials = securityCredentials;
- }
-
- public String getSecurityPrincipalName() {
- return securityPrincipalName;
- }
-
- public void setSecurityPrincipalName(String securityPrincipalName) {
- this.securityPrincipalName = securityPrincipalName;
- }
-
- public String getUserName() {
- return userName;
- }
-
- /**
- * The user name to use when {@link
- * javax.jms.TopicConnectionFactory#createTopicConnection(String, String)}
- * creating a topic session}. If you set this option, you should also set the
- * <b>Password</b> option. See {@link #setPassword(String)}.
- */
- public void setUserName(String userName) {
- this.userName = userName;
- }
-
- public String getPassword() {
- return password;
- }
-
- /**
- * The paswword to use when creating a topic session.
- */
- public void setPassword(String password) {
- this.password = password;
- }
-
- /**
* Returns the TopicConnection used for this appender. Only valid after
* start() method has been invoked.
*/
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTest.java Thu Jan 11 15:22:14 2007
@@ -1,9 +1,6 @@
package ch.qos.logback.classic.net;
-import java.util.Properties;
-
import javax.jms.ObjectMessage;
-import javax.naming.Context;
import junit.framework.TestCase;
import ch.qos.logback.classic.Level;
@@ -28,8 +25,8 @@
appender.setName("jmsQueue");
appender.qcfBindingName = "queueCnxFactory";
appender.queueBindingName = "testQueue";
- appender.providerURL = "url";
- appender.initialContextFactoryName = MockInitialContextFactory.class.getName();
+ appender.setProviderURL("url");
+ appender.setInitialContextFactoryName(MockInitialContextFactory.class.getName());
MockInitialContext mic = MockInitialContextFactory.getContext();
mic.map.put(appender.qcfBindingName, new MockQueueConnectionFactory());
@@ -78,96 +75,10 @@
assertFalse(appender.isStarted());
}
- public void testBuildEnvProperties() {
- appender.initialContextFactoryName = "icfn";
- appender.providerURL = "url";
- appender.urlPkgPrefixes = "pkgPref";
- appender.securityPrincipalName = "user";
- appender.securityCredentials = "cred";
-
- Properties props = appender.buildEnvProperties();
- assertEquals(5, props.size());
- assertEquals(appender.initialContextFactoryName, props
- .getProperty(Context.INITIAL_CONTEXT_FACTORY));
- assertEquals(appender.providerURL, props.getProperty(Context.PROVIDER_URL));
- assertEquals(appender.urlPkgPrefixes, props
- .getProperty(Context.URL_PKG_PREFIXES));
- assertEquals(appender.securityPrincipalName, props
- .getProperty(Context.SECURITY_PRINCIPAL));
- assertEquals(appender.securityCredentials, props
- .getProperty(Context.SECURITY_CREDENTIALS));
- }
-
- public void testBuildEnvPropertiesWithNullProviderURL() {
- appender.initialContextFactoryName = "icfn";
- appender.providerURL = null;
- appender.urlPkgPrefixes = "pkgPref";
- appender.securityPrincipalName = "user";
- appender.securityCredentials = "cred";
-
- Properties props = appender.buildEnvProperties();
- assertEquals(4, props.size());
- assertEquals(appender.initialContextFactoryName, props
- .getProperty(Context.INITIAL_CONTEXT_FACTORY));
- assertEquals(null, props.getProperty(Context.PROVIDER_URL));
- assertEquals(appender.urlPkgPrefixes, props
- .getProperty(Context.URL_PKG_PREFIXES));
- assertEquals(appender.securityPrincipalName, props
- .getProperty(Context.SECURITY_PRINCIPAL));
- assertEquals(appender.securityCredentials, props
- .getProperty(Context.SECURITY_CREDENTIALS));
-
- assertEquals(1, context.getStatusManager().getCount());
- }
-
- public void testBuildEnvPropertiesWithNullCredentials() {
- appender.initialContextFactoryName = "icfn";
- appender.providerURL = "url";
- appender.urlPkgPrefixes = "pkgPref";
- appender.securityPrincipalName = "user";
- appender.securityCredentials = null;
-
- Properties props = appender.buildEnvProperties();
- assertEquals(4, props.size());
- assertEquals(appender.initialContextFactoryName, props
- .getProperty(Context.INITIAL_CONTEXT_FACTORY));
- assertEquals(appender.providerURL, props.getProperty(Context.PROVIDER_URL));
- assertEquals(appender.urlPkgPrefixes, props
- .getProperty(Context.URL_PKG_PREFIXES));
- assertEquals(appender.securityPrincipalName, props
- .getProperty(Context.SECURITY_PRINCIPAL));
- assertEquals(null, props
- .getProperty(Context.SECURITY_CREDENTIALS));
-
- assertEquals(1, context.getStatusManager().getCount());
- }
-
- public void testBuildEnvPropertiesWithPkgNull() {
- appender.initialContextFactoryName = "icfn";
- appender.providerURL = "url";
- appender.urlPkgPrefixes = null;
- appender.securityPrincipalName = "user";
- appender.securityCredentials = "cred";
-
- Properties props = appender.buildEnvProperties();
- assertEquals(4, props.size());
- assertEquals(appender.initialContextFactoryName, props
- .getProperty(Context.INITIAL_CONTEXT_FACTORY));
- assertEquals(appender.providerURL, props.getProperty(Context.PROVIDER_URL));
- assertEquals(null, props
- .getProperty(Context.URL_PKG_PREFIXES));
- assertEquals(appender.securityPrincipalName, props
- .getProperty(Context.SECURITY_PRINCIPAL));
- assertEquals(appender.securityCredentials, props
- .getProperty(Context.SECURITY_CREDENTIALS));
-
- assertEquals(0, context.getStatusManager().getCount());
- }
-
public void testStartMinimalInfo() {
//let's leave only what's in the setup()
//method, minus the providerURL
- appender.providerURL = null;
+ appender.setProviderURL(null);
appender.start();
assertTrue(appender.isStarted());
@@ -180,8 +91,8 @@
}
public void testStartUserPass() {
- appender.userName = "";
- appender.password = "";
+ appender.setUserName("test");
+ appender.setPassword("test");
appender.start();
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java Thu Jan 11 15:22:14 2007
@@ -28,8 +28,8 @@
appender.setName("jmsTopic");
appender.tcfBindingName = "topicCnxFactory";
appender.topicBindingName = "testTopic";
- appender.providerURL = "url";
- appender.initialContextFactoryName = MockInitialContextFactory.class.getName();
+ appender.setProviderURL("url");
+ appender.setInitialContextFactoryName(MockInitialContextFactory.class.getName());
MockInitialContext mic = MockInitialContextFactory.getContext();
mic.map.put(appender.tcfBindingName, new MockTopicConnectionFactory());
@@ -79,62 +79,62 @@
}
public void testBuildEnvProperties() {
- appender.initialContextFactoryName = "icfn";
- appender.providerURL = "url";
- appender.urlPkgPrefixes = "pkgPref";
- appender.securityPrincipalName = "user";
- appender.securityCredentials = "cred";
+ appender.setInitialContextFactoryName("icfn");
+ appender.setProviderURL("url");
+ appender.setURLPkgPrefixes("pkgPref");
+ appender.setSecurityPrincipalName("user");
+ appender.setSecurityCredentials("cred");
Properties props = appender.buildEnvProperties();
assertEquals(5, props.size());
- assertEquals(appender.initialContextFactoryName, props
+ assertEquals(appender.getInitialContextFactoryName(), props
.getProperty(Context.INITIAL_CONTEXT_FACTORY));
- assertEquals(appender.providerURL, props.getProperty(Context.PROVIDER_URL));
- assertEquals(appender.urlPkgPrefixes, props
+ assertEquals(appender.getProviderURL(), props.getProperty(Context.PROVIDER_URL));
+ assertEquals(appender.getURLPkgPrefixes(), props
.getProperty(Context.URL_PKG_PREFIXES));
- assertEquals(appender.securityPrincipalName, props
+ assertEquals(appender.getSecurityPrincipalName(), props
.getProperty(Context.SECURITY_PRINCIPAL));
- assertEquals(appender.securityCredentials, props
+ assertEquals(appender.getSecurityCredentials(), props
.getProperty(Context.SECURITY_CREDENTIALS));
}
public void testBuildEnvPropertiesWithNullProviderURL() {
- appender.initialContextFactoryName = "icfn";
- appender.providerURL = null;
- appender.urlPkgPrefixes = "pkgPref";
- appender.securityPrincipalName = "user";
- appender.securityCredentials = "cred";
+ appender.setInitialContextFactoryName("icfn");
+ appender.setProviderURL(null);
+ appender.setURLPkgPrefixes("pkgPref");
+ appender.setSecurityPrincipalName("user");
+ appender.setSecurityCredentials("cred");
Properties props = appender.buildEnvProperties();
assertEquals(4, props.size());
- assertEquals(appender.initialContextFactoryName, props
+ assertEquals(appender.getInitialContextFactoryName(), props
.getProperty(Context.INITIAL_CONTEXT_FACTORY));
assertEquals(null, props.getProperty(Context.PROVIDER_URL));
- assertEquals(appender.urlPkgPrefixes, props
+ assertEquals(appender.getURLPkgPrefixes(), props
.getProperty(Context.URL_PKG_PREFIXES));
- assertEquals(appender.securityPrincipalName, props
+ assertEquals(appender.getSecurityPrincipalName(), props
.getProperty(Context.SECURITY_PRINCIPAL));
- assertEquals(appender.securityCredentials, props
+ assertEquals(appender.getSecurityCredentials(), props
.getProperty(Context.SECURITY_CREDENTIALS));
assertEquals(1, context.getStatusManager().getCount());
}
public void testBuildEnvPropertiesWithNullCredentials() {
- appender.initialContextFactoryName = "icfn";
- appender.providerURL = "url";
- appender.urlPkgPrefixes = "pkgPref";
- appender.securityPrincipalName = "user";
- appender.securityCredentials = null;
+ appender.setInitialContextFactoryName("icfn");
+ appender.setProviderURL("url");
+ appender.setURLPkgPrefixes("pkgPref");
+ appender.setSecurityPrincipalName("user");
+ appender.setSecurityCredentials(null);
Properties props = appender.buildEnvProperties();
assertEquals(4, props.size());
- assertEquals(appender.initialContextFactoryName, props
+ assertEquals(appender.getInitialContextFactoryName(), props
.getProperty(Context.INITIAL_CONTEXT_FACTORY));
- assertEquals(appender.providerURL, props.getProperty(Context.PROVIDER_URL));
- assertEquals(appender.urlPkgPrefixes, props
+ assertEquals(appender.getProviderURL(), props.getProperty(Context.PROVIDER_URL));
+ assertEquals(appender.getURLPkgPrefixes(), props
.getProperty(Context.URL_PKG_PREFIXES));
- assertEquals(appender.securityPrincipalName, props
+ assertEquals(appender.getSecurityPrincipalName(), props
.getProperty(Context.SECURITY_PRINCIPAL));
assertEquals(null, props
.getProperty(Context.SECURITY_CREDENTIALS));
@@ -143,22 +143,22 @@
}
public void testBuildEnvPropertiesWithPkgNull() {
- appender.initialContextFactoryName = "icfn";
- appender.providerURL = "url";
- appender.urlPkgPrefixes = null;
- appender.securityPrincipalName = "user";
- appender.securityCredentials = "cred";
+ appender.setInitialContextFactoryName("icfn");
+ appender.setProviderURL("url");
+ appender.setURLPkgPrefixes(null);
+ appender.setSecurityPrincipalName("user");
+ appender.setSecurityCredentials("cred");
Properties props = appender.buildEnvProperties();
assertEquals(4, props.size());
- assertEquals(appender.initialContextFactoryName, props
+ assertEquals(appender.getInitialContextFactoryName(), props
.getProperty(Context.INITIAL_CONTEXT_FACTORY));
- assertEquals(appender.providerURL, props.getProperty(Context.PROVIDER_URL));
+ assertEquals(appender.getProviderURL(), props.getProperty(Context.PROVIDER_URL));
assertEquals(null, props
.getProperty(Context.URL_PKG_PREFIXES));
- assertEquals(appender.securityPrincipalName, props
+ assertEquals(appender.getSecurityPrincipalName(), props
.getProperty(Context.SECURITY_PRINCIPAL));
- assertEquals(appender.securityCredentials, props
+ assertEquals(appender.getSecurityCredentials(), props
.getProperty(Context.SECURITY_CREDENTIALS));
assertEquals(0, context.getStatusManager().getCount());
@@ -167,7 +167,7 @@
public void testStartMinimalInfo() {
//let's leave only what's in the setup()
//method, minus the providerURL
- appender.providerURL = null;
+ appender.setProviderURL(null);
appender.start();
assertTrue(appender.isStarted());
@@ -180,8 +180,8 @@
}
public void testStartUserPass() {
- appender.userName = "";
- appender.password = "";
+ appender.setUserName("test");
+ appender.setPassword("test");
appender.start();
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/JMSAppenderBase.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/JMSAppenderBase.java Thu Jan 11 15:22:14 2007
@@ -0,0 +1,163 @@
+package ch.qos.logback.core.net;
+
+import java.util.Hashtable;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+import ch.qos.logback.core.AppenderBase;
+
+/**
+ * This class serves as a base class for
+ * JMSTopicAppender and JMSQueueAppender
+ *
+ * @author Ceki Gülcü
+ * @author Sébastien Pennec
+ */
+public abstract class JMSAppenderBase<E> extends AppenderBase<E> {
+
+ protected String securityPrincipalName;
+ protected String securityCredentials;
+ protected String initialContextFactoryName;
+ protected String urlPkgPrefixes;
+ protected String providerURL;
+ protected String userName;
+ protected String password;
+
+
+ protected Object lookup(Context ctx, String name) throws NamingException {
+ try {
+ return ctx.lookup(name);
+ } catch (NameNotFoundException e) {
+ addError("Could not find name [" + name + "].");
+ throw e;
+ }
+ }
+
+ public Context buildJNDIContext() throws NamingException {
+ Context jndi = null;
+
+ // addInfo("Getting initial context.");
+ if (initialContextFactoryName != null) {
+ Properties env = buildEnvProperties();
+ jndi = new InitialContext(env);
+ } else {
+ jndi = new InitialContext();
+ }
+ return jndi;
+ }
+
+ public Properties buildEnvProperties() {
+ Properties env = new Properties();
+ env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryName);
+ if (providerURL != null) {
+ env.put(Context.PROVIDER_URL, providerURL);
+ } else {
+ addWarn("You have set InitialContextFactoryName option but not the "
+ + "ProviderURL. This is likely to cause problems.");
+ }
+ if (urlPkgPrefixes != null) {
+ env.put(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
+ }
+
+ if (securityPrincipalName != null) {
+ env.put(Context.SECURITY_PRINCIPAL, securityPrincipalName);
+ if (securityCredentials != null) {
+ env.put(Context.SECURITY_CREDENTIALS, securityCredentials);
+ } else {
+ addWarn("You have set SecurityPrincipalName option but not the "
+ + "SecurityCredentials. This is likely to cause problems.");
+ }
+ }
+ return env;
+ }
+
+
+
+ /**
+ * Returns the value of the <b>InitialContextFactoryName</b> option. See
+ * {@link #setInitialContextFactoryName} for more details on the meaning of
+ * this option.
+ */
+ public String getInitialContextFactoryName() {
+ return initialContextFactoryName;
+ }
+
+ /**
+ * Setting the <b>InitialContextFactoryName</b> method will cause this
+ * <code>JMSAppender</code> instance to use the {@link
+ * InitialContext#InitialContext(Hashtable)} method instead of the no-argument
+ * constructor. If you set this option, you should also at least set the
+ * <b>ProviderURL</b> option.
+ *
+ * <p>
+ * See also {@link #setProviderURL(String)}.
+ */
+ public void setInitialContextFactoryName(String initialContextFactoryName) {
+ this.initialContextFactoryName = initialContextFactoryName;
+ }
+
+ public String getProviderURL() {
+ return providerURL;
+ }
+
+ public void setProviderURL(String providerURL) {
+ this.providerURL = providerURL;
+ }
+
+ public String getURLPkgPrefixes() {
+ return urlPkgPrefixes;
+ }
+
+ public void setURLPkgPrefixes(String urlPkgPrefixes) {
+ this.urlPkgPrefixes = urlPkgPrefixes;
+ }
+
+ public String getSecurityCredentials() {
+ return securityCredentials;
+ }
+
+ public void setSecurityCredentials(String securityCredentials) {
+ this.securityCredentials = securityCredentials;
+ }
+
+ public String getSecurityPrincipalName() {
+ return securityPrincipalName;
+ }
+
+ public void setSecurityPrincipalName(String securityPrincipalName) {
+ this.securityPrincipalName = securityPrincipalName;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ /**
+ * The user name to use when {@link
+ * javax.jms.TopicConnectionFactory#createTopicConnection(String, String)}
+ * creating a topic session}. If you set this option, you should also set the
+ * <b>Password</b> option. See {@link #setPassword(String)}.
+ */
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ /**
+ * The paswword to use when creating a topic session.
+ */
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+
+
+
+}
More information about the logback-dev
mailing list