Repository: camel
Updated Branches:
  refs/heads/master fd1c7beeb -> 81ea4398c


CAMEL-10169: log DEBUG if OSGi filter is invalid


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/81ea4398
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/81ea4398
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/81ea4398

Branch: refs/heads/master
Commit: 81ea4398caf120ab400e686782ebb3e47353b511
Parents: 12224bd
Author: Börcsök József <[email protected]>
Authored: Tue Jul 26 10:45:05 2016 +0200
Committer: Claus Ibsen <[email protected]>
Committed: Tue Jul 26 10:51:03 2016 +0200

----------------------------------------------------------------------
 .../camel/core/osgi/OsgiServiceRegistry.java    | 22 +++++++++++---------
 1 file changed, 12 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/81ea4398/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiServiceRegistry.java
----------------------------------------------------------------------
diff --git 
a/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiServiceRegistry.java
 
b/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiServiceRegistry.java
index e6712d6..337061b 100644
--- 
a/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiServiceRegistry.java
+++ 
b/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiServiceRegistry.java
@@ -72,25 +72,27 @@ public class OsgiServiceRegistry extends 
LifecycleStrategySupport implements Reg
     public Object lookupByName(String name) {
         Object service = null;
         ServiceReference<?> sr = bundleContext.getServiceReference(name);
-        if (sr != null) {
-            // Need to keep the track of Service
-            // and call ungetService when the camel context is closed 
-            serviceReferenceQueue.add(sr);
-            service = bundleContext.getService(sr);
-        } else {
+        if (sr == null) {
             // trying to lookup service by PID if not found by name
+            String filterExpression = "(" + Constants.SERVICE_PID + "=" + name 
+ ")";
             try {
-                ServiceReference<?>[] refs = 
bundleContext.getServiceReferences((String)null, "(" + Constants.SERVICE_PID + 
"=" + name + ")");
+                ServiceReference<?>[] refs = 
bundleContext.getServiceReferences((String)null, filterExpression);
                 if (refs != null && refs.length > 0) {
                     // just return the first one
                     sr = refs[0];
-                    serviceReferenceQueue.add(sr);
-                    service = bundleContext.getService(sr);
                 }
             } catch (InvalidSyntaxException ex) {
-                LOG.error("Invalid filter to lookup bean", ex);
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Invalid OSGi service reference filter, skipped 
lookup by service.pid. Filter expression: " + filterExpression, ex);
+                }
             }
         }
+        if (sr != null) {
+            // Need to keep the track of Service
+            // and call ungetService when the camel context is closed 
+            serviceReferenceQueue.add(sr);
+            service = bundleContext.getService(sr);
+        }
         return service;
     }
 

Reply via email to