Examples of OsgiServiceProxyFactoryBean


Examples of org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean

   *
   * @return proxy to the found OSGi service
   */
  public static Object createServerServiceProxy(BundleContext bundleContext, Class proxyType, String serviceName) {

    OsgiServiceProxyFactoryBean proxyFB = new OsgiServiceProxyFactoryBean();
    proxyFB.setBundleContext(bundleContext);
    proxyFB.setContextClassLoader(ImportContextClassLoader.UNMANAGED);
    proxyFB.setInterfaces(new Class[] { proxyType });
    // use the spring-dm class loader to generate the proxy (since it can see all the needed server classes)
    proxyFB.setBeanClassLoader(proxyType.getClassLoader());
    // wait 5 seconds
    proxyFB.setTimeout(5 * 1000);
    if (StringUtils.hasText(serviceName))
      proxyFB.setServiceBeanName(serviceName);
    proxyFB.afterPropertiesSet();

    return proxyFB.getObject();
  }
View Full Code Here

Examples of org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean

    public void afterPropertiesSet() throws Exception {
        if (nmr == null) {
            if (bundleContext == null) {
                throw new IllegalArgumentException("nmr not set while bundleContext is null");
            }
            OsgiServiceProxyFactoryBean factory = new OsgiServiceProxyFactoryBean();
            factory.setInterfaces(new Class[] { NMR.class });
            factory.setBundleContext(getBundleContext());
            nmr = (NMR) factory.getObject();
        }
        if (name == null && itf == null && service == null) {
            throw new IllegalArgumentException("one of name, interface or service should be set");
        }
    }
View Full Code Here

Examples of org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean

            }
            String className = parts[0];
            String filter = parts.length == 2 ? parts[1] : null;
            try {
                ClassLoader classLoader = getClass().getClassLoader();
                OsgiServiceProxyFactoryBean factory = new OsgiServiceProxyFactoryBean();
                factory.setBundleContext(getBundleContext());
                factory.setBeanClassLoader(classLoader);
                factory.setFilter(filter);
                factory.setInterfaces(new Class[] { ClassUtils.resolveClassName(className, classLoader) });
                factory.afterPropertiesSet();
                return factory.getObject();
            } catch (org.springframework.osgi.service.ServiceUnavailableException e) {
                NameNotFoundException ex = new NameNotFoundException(e.getMessage());
                ex.initCause(e);
                throw ex;
            }
View Full Code Here

Examples of org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean

    }
    if (Collection.class.isAssignableFrom(params[0])) {
      return getServiceProperty(new OsgiServiceCollectionProxyFactoryBean(), s, writeMethod, beanName);
    }
    else {
      return getServiceProperty(new OsgiServiceProxyFactoryBean(), s, writeMethod, beanName);
    }
  }
View Full Code Here

Examples of org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean

                    }
                };
            }
        }
        // The bean was not found in the BeanFactory. Its time to lookup it via the OSGI-Registry
        return getResourceProperty(new OsgiServiceProxyFactoryBean(), getFilter(s), writeMethod, beanName);
    }
View Full Code Here

Examples of org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean

    public void afterPropertiesSet() throws Exception {
        if (nmr == null) {
            if (bundleContext == null) {
                throw new IllegalArgumentException("nmr not set while bundleContext is null");
            }
            OsgiServiceProxyFactoryBean factory = new OsgiServiceProxyFactoryBean();
            factory.setInterfaces(new Class[] { NMR.class });
            factory.setBundleContext(getBundleContext());
            nmr = (NMR) factory.getObject();
        }
        if (name == null && itf == null && service == null) {
            throw new IllegalArgumentException("one of name, interface or service should be set");
        }
    }
View Full Code Here

Examples of org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean

  /**
   * Disabled since it doesn't work as we can't proxy final classes.
   */
  public void tstGetServicePropertySetters() throws Exception {
    OsgiServiceProxyFactoryBean pfb = new OsgiServiceProxyFactoryBean();
    Method setter = AnnotatedBean.class.getMethod("setStringType", new Class[] { String.class });
    ServiceReference ref = AnnotationUtils.getAnnotation(setter, ServiceReference.class);

    processor.getServiceProperty(pfb, ref, setter, null);
    Class[] intfs = (Class[]) getPrivateProperty(pfb, "serviceTypes");
    assertEquals(intfs[0], String.class);

    setter = AnnotatedBean.class.getMethod("setIntType", new Class[] { Integer.TYPE });
    ref = AnnotationUtils.getAnnotation(setter, ServiceReference.class);

    pfb = new OsgiServiceProxyFactoryBean();
    processor.getServiceProperty(pfb, ref, setter, null);
    intfs = (Class[]) getPrivateProperty(pfb, "serviceTypes");
    assertEquals(intfs[0], Integer.TYPE);

  }
View Full Code Here

Examples of org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean

    assertEquals(intfs[0], Integer.TYPE);

  }

  public void testGetServicePropertyCardinality() throws Exception {
    OsgiServiceProxyFactoryBean pfb = new OsgiServiceProxyFactoryBean();
    Method setter = AnnotatedBean.class.getMethod("setAnnotatedBeanTypeWithCardinality1_1",
      new Class[] { AnnotatedBean.class });
    ServiceReference ref = AnnotationUtils.getAnnotation(setter, ServiceReference.class);
    processor.getServiceProperty(pfb, ref, setter, null);
    assertTrue(pfb.getCardinality().isMandatory());

    setter = AnnotatedBean.class.getMethod("setAnnotatedBeanTypeWithCardinality0_1",
      new Class[] { AnnotatedBean.class });
    ref = AnnotationUtils.getAnnotation(setter, ServiceReference.class);
    pfb = new OsgiServiceProxyFactoryBean();
    processor.getServiceProperty(pfb, ref, setter, null);
    assertFalse(pfb.getCardinality().isMandatory());
  }
View Full Code Here

Examples of org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean

    catch (Exception e) {
    }
  }

  public void testGetServicePropertyClassloader() throws Exception {
    OsgiServiceProxyFactoryBean pfb = new OsgiServiceProxyFactoryBean();
    Method setter = AnnotatedBean.class.getMethod("setAnnotatedBeanTypeWithClassLoaderClient",
      new Class[] { AnnotatedBean.class });
    ServiceReference ref = AnnotationUtils.getAnnotation(setter, ServiceReference.class);
    processor.getServiceProperty(pfb, ref, setter, null);
    assertEquals(pfb.getContextClassLoader(), ImportContextClassLoader.CLIENT);

    pfb = new OsgiServiceProxyFactoryBean();
    setter = AnnotatedBean.class.getMethod("setAnnotatedBeanTypeWithClassLoaderUmanaged",
      new Class[] { AnnotatedBean.class });
    ref = AnnotationUtils.getAnnotation(setter, ServiceReference.class);
    processor.getServiceProperty(pfb, ref, setter, null);

    assertEquals(pfb.getContextClassLoader(), ImportContextClassLoader.UNMANAGED);

    pfb = new OsgiServiceProxyFactoryBean();
    setter = AnnotatedBean.class.getMethod("setAnnotatedBeanTypeWithClassLoaderServiceProvider",
      new Class[] { AnnotatedBean.class });
    ref = AnnotationUtils.getAnnotation(setter, ServiceReference.class);
    processor.getServiceProperty(pfb, ref, setter, null);
    assertEquals(pfb.getContextClassLoader(), ImportContextClassLoader.SERVICE_PROVIDER);
  }
View Full Code Here

Examples of org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean

    processor.getServiceProperty(pfb, ref, setter, null);
    assertEquals(pfb.getContextClassLoader(), ImportContextClassLoader.SERVICE_PROVIDER);
  }

  public void testGetServicePropertyBeanName() throws Exception {
    OsgiServiceProxyFactoryBean pfb = new OsgiServiceProxyFactoryBean();
    Method setter = AnnotatedBean.class.getMethod("setAnnotatedBeanTypeWithBeanName",
      new Class[] { AnnotatedBean.class });
    ServiceReference ref = AnnotationUtils.getAnnotation(setter, ServiceReference.class);
    processor.getServiceProperty(pfb, ref, setter, null);
    String beanName = (String) getPrivateProperty(pfb, "serviceBeanName");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.