diff options
Diffstat (limited to 'java/sca/modules')
2 files changed, 27 insertions, 19 deletions
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java index 0bcd135550..5e592ee97a 100644 --- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java +++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java @@ -57,6 +57,7 @@ public class OSGiImplementationProvider implements ImplementationProvider { ProxyFactoryExtensionPoint proxyFactoryExtensionPoint) throws BundleException { this.component = component; this.proxyFactoryExtensionPoint = proxyFactoryExtensionPoint; + this.implementation = impl; this.osgiBundle = impl.getBundle(); } @@ -71,8 +72,9 @@ public class OSGiImplementationProvider implements ImplementationProvider { JavaInterface javaInterface = (JavaInterface)interfaceContract.getInterface(); final Class<?> interfaceClass = javaInterface.getJavaClass(); - Hashtable<String, Object> targetProperties = getOSGiProperties(reference); + final Hashtable<String, Object> targetProperties = getOSGiProperties(reference); targetProperties.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE); + targetProperties.put("sca.reference", component.getURI() + "#reference(" + ref.getName() + ")"); ProxyFactory proxyService = proxyFactoryExtensionPoint.getInterfaceProxyFactory(); if (!interfaceClass.isInterface()) { @@ -81,12 +83,11 @@ public class OSGiImplementationProvider implements ImplementationProvider { for (RuntimeWire wire : reference.getRuntimeWires()) { final Object proxy = proxyService.createProxy(interfaceClass, wire); - final Hashtable<String, Object> finalTargetProperties = targetProperties; AccessController.doPrivileged(new PrivilegedAction<ServiceRegistration>() { public ServiceRegistration run() { return osgiBundle.getBundleContext().registerService(interfaceClass.getName(), proxy, - finalTargetProperties); + targetProperties); } }); } diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java index 6268b59142..52313a84e7 100644 --- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java +++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java @@ -40,15 +40,9 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; /** - * Java->OSGi references use OSGiTargetInvoker to call methods from OSGi bundles - * OSGi->Java references use JDKProxyService and invocation handler and do not use this class - * OSGi->OSGi references go through OSGi reference mechanisms when a proxy is not used - * When a proxy is used, this invoker is used to call methods from OSGi bundles - * A proxy is used for OSGi->OSGi if - * 1) target reference properties are specified OR - * 2) there are one or more non-blocking methods in the target interface OR - * 3) scope is not COMPOSITE - * + * The Invoker looks up the corresponding OSGi service from the OSGi service registry + * and delegate the call to it. + * * @version $Rev$ $Date$ */ public class OSGiTargetInvoker<T> implements Invoker { @@ -81,9 +75,10 @@ public class OSGiTargetInvoker<T> implements Invoker { JavaInterface javaInterface = (JavaInterface)op.getInterface(); // String filter = getOSGiFilter(provider.getOSGiProperties(service)); // FIXME: What is the filter? - String filter = "(sca.service=" + component.getURI() + "#service-name\\(" + service.getName() + "\\))"; - ServiceReference[] refs = bundleContext.getServiceReferences(javaInterface.getName(), filter); - Object instance = bundleContext.getService(refs[0]); + String filter = "(!(sca.reference=*))"; + // "(sca.service=" + component.getURI() + "#service-name\\(" + service.getName() + "\\))"; + ServiceReference ref = bundleContext.getServiceReferences(javaInterface.getName(), filter)[0]; + Object instance = bundleContext.getService(ref); Method m = findMethod(instance.getClass(), operation); Object ret = invokeMethod(instance, m, msg); @@ -132,16 +127,28 @@ public class OSGiTargetInvoker<T> implements Invoker { if (props != null && props.size() > 0) { int propCount = 0; for (String propName : props.keySet()) { - if (propName.equals("service.pid")) + if (propName.equals("service.pid")) { continue; - filter = filter + "(" + propName + "=" + props.get(propName) + ")"; + } + String value = String.valueOf(props.get(propName)); + StringBuffer buf = new StringBuffer(); + for (char c : value.toCharArray()) { + if (c == '(' || c == ')') { + buf.append("\\" + c); + } else { + buf.append(c); + } + } + filter = filter + "(" + propName + "=" + buf.toString() + ")"; propCount++; } - if (propCount > 1) + if (propCount > 1) { filter = "(&" + filter + ")"; - } else + } + } else { filter = null; + } return filter; } |