You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2015/03/31 16:49:22 UTC

[3/3] qpid-jms git commit: QPIDJMS-34: reduce severity of logging about server mechanisms we dont support, dont catch Errors

QPIDJMS-34: reduce severity of logging about server mechanisms we dont support, dont catch Errors


Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/9db79b95
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/9db79b95
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/9db79b95

Branch: refs/heads/master
Commit: 9db79b9544777dfd2df2935623a2fccc4184b12a
Parents: 475a644
Author: Robert Gemmell <ro...@apache.org>
Authored: Tue Mar 31 15:28:43 2015 +0100
Committer: Robert Gemmell <ro...@apache.org>
Committed: Tue Mar 31 15:28:43 2015 +0100

----------------------------------------------------------------------
 .../qpid/jms/sasl/SaslMechanismFinder.java      | 25 +++++++++----------
 .../org/apache/qpid/jms/util/FactoryFinder.java | 12 +++++----
 .../jms/util/ResourceNotFoundException.java     | 26 ++++++++++++++++++++
 3 files changed, 45 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/9db79b95/qpid-jms-client/src/main/java/org/apache/qpid/jms/sasl/SaslMechanismFinder.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/sasl/SaslMechanismFinder.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/sasl/SaslMechanismFinder.java
index 30557c2..ef2a64e 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/sasl/SaslMechanismFinder.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/sasl/SaslMechanismFinder.java
@@ -16,12 +16,12 @@
  */
 package org.apache.qpid.jms.sasl;
 
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
 import org.apache.qpid.jms.util.FactoryFinder;
+import org.apache.qpid.jms.util.ResourceNotFoundException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -58,11 +58,9 @@ public class SaslMechanismFinder {
         List<Mechanism> found = new ArrayList<Mechanism>();
 
         for (String remoteMechanism : remoteMechanisms) {
-            try {
-                MechanismFactory factory = findMechanismFactory(remoteMechanism);
+            MechanismFactory factory = findMechanismFactory(remoteMechanism);
+            if (factory != null) {
                 found.add(factory.createMechanism());
-            } catch (IOException e) {
-                LOG.warn("Caught exception while searching for SASL mechanisms: {}", e.getMessage());
             }
         }
 
@@ -85,22 +83,23 @@ public class SaslMechanismFinder {
      * to search in the classpath.
      *
      * @param name
-     *        The name of the authentication mechanism to search for..
+     *        The name of the authentication mechanism to search for.
      *
-     * @return a mechanism factory instance matching the URI's scheme.
-     *
-     * @throws IOException if an error occurs while locating the factory.
+     * @return a mechanism factory instance matching the name, or null if none was created.
      */
-    protected static MechanismFactory findMechanismFactory(String name) throws IOException {
+    protected static MechanismFactory findMechanismFactory(String name) {
         if (name == null || name.isEmpty()) {
-            throw new IOException("No Mechanism name specified.");
+            LOG.warn("No SASL mechanism name was specified");
+            return null;
         }
 
         MechanismFactory factory = null;
         try {
             factory = MECHANISM_FACTORY_FINDER.newInstance(name);
-        } catch (Throwable e) {
-            throw new IOException("Mechanism scheme NOT recognized: [" + name + "]", e);
+        } catch (ResourceNotFoundException rnfe) {
+            LOG.debug("Unknown SASL mechanism: [" + name + "]");
+        } catch (Exception e) {
+            LOG.warn("Caught exception while finding factory for SASL mechanism {}: {}", name, e.getMessage());
         }
 
         return factory;

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/9db79b95/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/FactoryFinder.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/FactoryFinder.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/FactoryFinder.java
index 3c26559..de4a3ef 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/FactoryFinder.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/FactoryFinder.java
@@ -51,10 +51,11 @@ public class FactoryFinder<T extends Object> {
          *
          * @throws IllegalAccessException if an error occurs while accessing the search path.
          * @throws InstantiationException if the factory object fails on create.
+         * @throws ResourceNotFoundException if the path does not exist.
          * @throws IOException if the search encounter an IO error.
          * @throws ClassNotFoundException if the class that is to be loaded cannot be found.
          */
-        public Object create(String path) throws IllegalAccessException, InstantiationException, IOException, ClassNotFoundException;
+        public Object create(String path) throws IllegalAccessException, InstantiationException, IOException, ClassNotFoundException, ResourceNotFoundException;
 
     }
 
@@ -106,11 +107,12 @@ public class FactoryFinder<T extends Object> {
      *
      * @throws IllegalAccessException if an error occurs while accessing the search path.
      * @throws InstantiationException if the factory object fails on create.
+     * @throws ResourceNotFoundException if the resource with the given key does not exist.
      * @throws IOException if the search encounter an IO error.
      * @throws ClassNotFoundException if the class that is to be loaded cannot be found.
      * @throws ClassCastException if the found object is not assignable to the request factory type.
      */
-    public T newInstance(String key) throws IllegalAccessException, InstantiationException, IOException, ClassNotFoundException, ClassCastException {
+    public T newInstance(String key) throws IllegalAccessException, InstantiationException, IOException, ClassNotFoundException, ClassCastException, ResourceNotFoundException {
         T factory = cachedFactories.get(key);
         if (factory == null) {
             Object found = objectFactory.create(path + key);
@@ -150,7 +152,7 @@ public class FactoryFinder<T extends Object> {
         final ConcurrentHashMap<String, Properties> propertiesMap = new ConcurrentHashMap<String, Properties>();
 
         @Override
-        public Object create(final String path) throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException {
+        public Object create(final String path) throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException, ResourceNotFoundException {
             Class<?> clazz = classMap.get(path);
             Properties properties = propertiesMap.get(path);
 
@@ -204,7 +206,7 @@ public class FactoryFinder<T extends Object> {
             return clazz;
         }
 
-        static public Properties loadProperties(String uri) throws IOException {
+        static public Properties loadProperties(String uri) throws IOException, ResourceNotFoundException {
             // lets try the thread context class loader first
             ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
             if (classLoader == null) {
@@ -214,7 +216,7 @@ public class FactoryFinder<T extends Object> {
             if (in == null) {
                 in = FactoryFinder.class.getClassLoader().getResourceAsStream(uri);
                 if (in == null) {
-                    throw new IOException("Could not find factory class for resource: " + uri);
+                    throw new ResourceNotFoundException("Could not find factory resource: " + uri);
                 }
             }
 

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/9db79b95/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/ResourceNotFoundException.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/ResourceNotFoundException.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/ResourceNotFoundException.java
new file mode 100644
index 0000000..4288731
--- /dev/null
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/ResourceNotFoundException.java
@@ -0,0 +1,26 @@
+/*
+ * 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.qpid.jms.util;
+
+public class ResourceNotFoundException extends Exception {
+
+    private static final long serialVersionUID = -4410424250899087436L;
+
+    public ResourceNotFoundException(String cause) {
+        super(cause);
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org