You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2017/06/24 01:54:08 UTC
logging-log4j2 git commit: Add toString() for ease of debugging.
Repository: logging-log4j2
Updated Branches:
refs/heads/master 425420b0e -> 9fd6c395f
Add toString() for ease of debugging.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/9fd6c395
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/9fd6c395
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/9fd6c395
Branch: refs/heads/master
Commit: 9fd6c395f905ecfbc4872609bb5b7c43ddb74230
Parents: 425420b
Author: Gary Gregory <gg...@apache.org>
Authored: Fri Jun 23 18:54:06 2017 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Fri Jun 23 18:54:06 2017 -0700
----------------------------------------------------------------------
.../logging/log4j/core/net/JndiManager.java | 293 ++++++++++---------
1 file changed, 149 insertions(+), 144 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9fd6c395/log4j-core/src/main/java/org/apache/logging/log4j/core/net/JndiManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/JndiManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/JndiManager.java
index abeb5ee..7923190 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/JndiManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/JndiManager.java
@@ -1,144 +1,149 @@
-/*
- * 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.logging.log4j.core.net;
-
-import java.util.Properties;
-import java.util.concurrent.TimeUnit;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
-import org.apache.logging.log4j.core.appender.AbstractManager;
-import org.apache.logging.log4j.core.appender.ManagerFactory;
-import org.apache.logging.log4j.core.util.JndiCloser;
-
-/**
- * JNDI {@link javax.naming.Context} manager.
- *
- * @since 2.1
- */
-public class JndiManager extends AbstractManager {
-
- private static final JndiManagerFactory FACTORY = new JndiManagerFactory();
-
- private final Context context;
-
- private JndiManager(final String name, final Context context) {
- super(null, name);
- this.context = context;
- }
-
- /**
- * Gets the default JndiManager using the default {@link javax.naming.InitialContext}.
- *
- * @return the default JndiManager
- */
- public static JndiManager getDefaultManager() {
- return getManager(JndiManager.class.getName(), FACTORY, null);
- }
-
- /**
- * Gets a named JndiManager using the default {@link javax.naming.InitialContext}.
- * @param name the name of the JndiManager instance to create or use if available
- * @return a default JndiManager
- */
- public static JndiManager getDefaultManager(final String name) {
- return getManager(name, FACTORY, null);
- }
-
- /**
- * Gets a JndiManager with the provided configuration information.
- *
- * @param initialContextFactoryName Fully qualified class name of an implementation of
- * {@link javax.naming.spi.InitialContextFactory}.
- * @param providerURL The provider URL to use for the JNDI connection (specific to the above factory).
- * @param urlPkgPrefixes A colon-separated list of package prefixes for the class name of the factory
- * class that will create a URL context factory
- * @param securityPrincipal The name of the identity of the Principal.
- * @param securityCredentials The security credentials of the Principal.
- * @param additionalProperties Any additional JNDI environment properties to set or {@code null} for none.
- * @return the JndiManager for the provided parameters.
- */
- public static JndiManager getJndiManager(final String initialContextFactoryName,
- final String providerURL,
- final String urlPkgPrefixes,
- final String securityPrincipal,
- final String securityCredentials,
- final Properties additionalProperties) {
- final String name = JndiManager.class.getName() + '@' + JndiManager.class.hashCode();
- if (initialContextFactoryName == null) {
- return getManager(name, FACTORY, null);
- }
- final Properties properties = new Properties();
- properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryName);
- if (providerURL != null) {
- properties.setProperty(Context.PROVIDER_URL, providerURL);
- } else {
- LOGGER.warn("The JNDI InitialContextFactory class name [{}] was provided, but there was no associated " +
- "provider URL. This is likely to cause problems.", initialContextFactoryName);
- }
- if (urlPkgPrefixes != null) {
- properties.setProperty(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
- }
- if (securityPrincipal != null) {
- properties.setProperty(Context.SECURITY_PRINCIPAL, securityPrincipal);
- if (securityCredentials != null) {
- properties.setProperty(Context.SECURITY_CREDENTIALS, securityCredentials);
- } else {
- LOGGER.warn("A security principal [{}] was provided, but with no corresponding security credentials.",
- securityPrincipal);
- }
- }
- if (additionalProperties != null) {
- properties.putAll(additionalProperties);
- }
- return getManager(name, FACTORY, properties);
- }
-
- @Override
- protected boolean releaseSub(final long timeout, final TimeUnit timeUnit) {
- return JndiCloser.closeSilently(this.context);
- }
-
- /**
- * Looks up a named object through this JNDI context.
- *
- * @param name name of the object to look up.
- * @param <T> the type of the object.
- * @return the named object if it could be located.
- * @throws NamingException
- */
- @SuppressWarnings("unchecked")
- public <T> T lookup(final String name) throws NamingException {
- return (T) this.context.lookup(name);
- }
-
- private static class JndiManagerFactory implements ManagerFactory<JndiManager, Properties> {
-
- @Override
- public JndiManager createManager(final String name, final Properties data) {
- try {
- return new JndiManager(name, new InitialContext(data));
- } catch (final NamingException e) {
- LOGGER.error("Error creating JNDI InitialContext.", e);
- return null;
- }
- }
- }
-}
+/*
+ * 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.logging.log4j.core.net;
+
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.logging.log4j.core.appender.AbstractManager;
+import org.apache.logging.log4j.core.appender.ManagerFactory;
+import org.apache.logging.log4j.core.util.JndiCloser;
+
+/**
+ * JNDI {@link javax.naming.Context} manager.
+ *
+ * @since 2.1
+ */
+public class JndiManager extends AbstractManager {
+
+ private static final JndiManagerFactory FACTORY = new JndiManagerFactory();
+
+ private final Context context;
+
+ private JndiManager(final String name, final Context context) {
+ super(null, name);
+ this.context = context;
+ }
+
+ /**
+ * Gets the default JndiManager using the default {@link javax.naming.InitialContext}.
+ *
+ * @return the default JndiManager
+ */
+ public static JndiManager getDefaultManager() {
+ return getManager(JndiManager.class.getName(), FACTORY, null);
+ }
+
+ /**
+ * Gets a named JndiManager using the default {@link javax.naming.InitialContext}.
+ * @param name the name of the JndiManager instance to create or use if available
+ * @return a default JndiManager
+ */
+ public static JndiManager getDefaultManager(final String name) {
+ return getManager(name, FACTORY, null);
+ }
+
+ /**
+ * Gets a JndiManager with the provided configuration information.
+ *
+ * @param initialContextFactoryName Fully qualified class name of an implementation of
+ * {@link javax.naming.spi.InitialContextFactory}.
+ * @param providerURL The provider URL to use for the JNDI connection (specific to the above factory).
+ * @param urlPkgPrefixes A colon-separated list of package prefixes for the class name of the factory
+ * class that will create a URL context factory
+ * @param securityPrincipal The name of the identity of the Principal.
+ * @param securityCredentials The security credentials of the Principal.
+ * @param additionalProperties Any additional JNDI environment properties to set or {@code null} for none.
+ * @return the JndiManager for the provided parameters.
+ */
+ public static JndiManager getJndiManager(final String initialContextFactoryName,
+ final String providerURL,
+ final String urlPkgPrefixes,
+ final String securityPrincipal,
+ final String securityCredentials,
+ final Properties additionalProperties) {
+ final String name = JndiManager.class.getName() + '@' + JndiManager.class.hashCode();
+ if (initialContextFactoryName == null) {
+ return getManager(name, FACTORY, null);
+ }
+ final Properties properties = new Properties();
+ properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryName);
+ if (providerURL != null) {
+ properties.setProperty(Context.PROVIDER_URL, providerURL);
+ } else {
+ LOGGER.warn("The JNDI InitialContextFactory class name [{}] was provided, but there was no associated " +
+ "provider URL. This is likely to cause problems.", initialContextFactoryName);
+ }
+ if (urlPkgPrefixes != null) {
+ properties.setProperty(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
+ }
+ if (securityPrincipal != null) {
+ properties.setProperty(Context.SECURITY_PRINCIPAL, securityPrincipal);
+ if (securityCredentials != null) {
+ properties.setProperty(Context.SECURITY_CREDENTIALS, securityCredentials);
+ } else {
+ LOGGER.warn("A security principal [{}] was provided, but with no corresponding security credentials.",
+ securityPrincipal);
+ }
+ }
+ if (additionalProperties != null) {
+ properties.putAll(additionalProperties);
+ }
+ return getManager(name, FACTORY, properties);
+ }
+
+ @Override
+ protected boolean releaseSub(final long timeout, final TimeUnit timeUnit) {
+ return JndiCloser.closeSilently(this.context);
+ }
+
+ /**
+ * Looks up a named object through this JNDI context.
+ *
+ * @param name name of the object to look up.
+ * @param <T> the type of the object.
+ * @return the named object if it could be located.
+ * @throws NamingException
+ */
+ @SuppressWarnings("unchecked")
+ public <T> T lookup(final String name) throws NamingException {
+ return (T) this.context.lookup(name);
+ }
+
+ private static class JndiManagerFactory implements ManagerFactory<JndiManager, Properties> {
+
+ @Override
+ public JndiManager createManager(final String name, final Properties data) {
+ try {
+ return new JndiManager(name, new InitialContext(data));
+ } catch (final NamingException e) {
+ LOGGER.error("Error creating JNDI InitialContext.", e);
+ return null;
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "JndiManager [context=" + context + "]";
+ }
+}