Search in sources :

Example 1 with PojoServiceRegistryFactoryImpl

use of org.apache.felix.connect.PojoServiceRegistryFactoryImpl in project karaf by apache.

the class EncryptableConfigAdminPropertyPlaceholderTest method setUp.

@Before
public void setUp() throws Exception {
    // Configure Jasypt
    enc = new StandardPBEStringEncryptor();
    env = new EnvironmentStringPBEConfig();
    env.setAlgorithm("PBEWithMD5AndDES");
    env.setPassword("password");
    enc.setConfig(env);
    System.setProperty("org.osgi.framework.storage", "target/osgi/" + System.currentTimeMillis());
    System.setProperty("karaf.name", "root");
    List<BundleDescriptor> bundles = new ClasspathScanner().scanForBundles("(Bundle-SymbolicName=*)");
    bundles.add(getBundleDescriptor("target/jasypt2.jar", bundle().add("OSGI-INF/blueprint/karaf-jaas-jasypt.xml", getClass().getResource("/OSGI-INF/blueprint/karaf-jaas-jasypt.xml")).set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", "jasypt").set("Bundle-Version", "0.0.0")));
    bundles.add(getBundleDescriptor("target/test2.jar", bundle().add("OSGI-INF/blueprint/configadmin-test.xml", getClass().getResource("configadmin-test.xml")).set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", "configtest").set("Bundle-Version", "0.0.0")));
    Map config = new HashMap();
    config.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, bundles);
    PojoServiceRegistry reg = new PojoServiceRegistryFactoryImpl().newPojoServiceRegistry(config);
    bundleContext = reg.getBundleContext();
}
Also used : PojoServiceRegistry(org.apache.felix.connect.launch.PojoServiceRegistry) StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor) BundleDescriptor(org.apache.felix.connect.launch.BundleDescriptor) PojoServiceRegistryFactoryImpl(org.apache.felix.connect.PojoServiceRegistryFactoryImpl) EnvironmentStringPBEConfig(org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig) ClasspathScanner(org.apache.felix.connect.launch.ClasspathScanner) Before(org.junit.Before)

Example 2 with PojoServiceRegistryFactoryImpl

use of org.apache.felix.connect.PojoServiceRegistryFactoryImpl in project camel by apache.

the class CamelBlueprintHelper method createBundleContext.

public static BundleContext createBundleContext(String name, String bundleFilter, TinyBundle bundle, TinyBundle configAdminInitBundle, ClassLoader loader) throws Exception {
    // ensure felix-connect stores bundles in an unique target directory
    String uid = "" + System.currentTimeMillis();
    String tempDir = "target/bundles/" + uid;
    System.setProperty("org.osgi.framework.storage", tempDir);
    createDirectory(tempDir);
    // use another directory for the jar of the bundle as it cannot be in the same directory
    // as it has a file lock during running the tests which will cause the temp dir to not be
    // fully deleted between tests
    createDirectory("target/test-bundles");
    List<BundleDescriptor> bundles = new LinkedList<>();
    if (configAdminInitBundle != null) {
        String jarName = "configAdminInitBundle-" + uid + ".jar";
        bundles.add(getBundleDescriptor("target/test-bundles/" + jarName, configAdminInitBundle));
    }
    if (bundle != null) {
        String jarName = name.toLowerCase(Locale.ENGLISH) + "-" + uid + ".jar";
        bundles.add(getBundleDescriptor("target/test-bundles/" + jarName, bundle));
    }
    List<BundleDescriptor> bundleDescriptors = getBundleDescriptors(bundleFilter, loader);
    // let's put configadmin before blueprint.core
    int idx1 = -1;
    int idx2 = -1;
    for (int i = 0; i < bundleDescriptors.size(); i++) {
        BundleDescriptor bd = bundleDescriptors.get(i);
        if ("org.apache.felix.configadmin".equals(bd.getHeaders().get("Bundle-SymbolicName"))) {
            idx1 = i;
        }
        if ("org.apache.aries.blueprint.core".equals(bd.getHeaders().get("Bundle-SymbolicName"))) {
            idx2 = i;
        }
    }
    if (idx1 >= 0 && idx2 >= 0 && idx1 > idx2) {
        bundleDescriptors.add(idx2, bundleDescriptors.remove(idx1));
    }
    // get the bundles
    bundles.addAll(bundleDescriptors);
    if (LOG.isDebugEnabled()) {
        for (int i = 0; i < bundles.size(); i++) {
            BundleDescriptor desc = bundles.get(i);
            LOG.debug("Bundle #{} -> {}", i, desc);
        }
    }
    // setup felix-connect to use our bundles
    Map<String, Object> config = new HashMap<String, Object>();
    config.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, bundles);
    // create pojorsr osgi service registry
    PojoServiceRegistry reg = new PojoServiceRegistryFactoryImpl().newPojoServiceRegistry(config);
    return reg.getBundleContext();
}
Also used : PojoServiceRegistry(org.apache.felix.connect.launch.PojoServiceRegistry) BundleDescriptor(org.apache.felix.connect.launch.BundleDescriptor) HashMap(java.util.HashMap) PojoServiceRegistryFactoryImpl(org.apache.felix.connect.PojoServiceRegistryFactoryImpl) LinkedList(java.util.LinkedList)

Example 3 with PojoServiceRegistryFactoryImpl

use of org.apache.felix.connect.PojoServiceRegistryFactoryImpl in project karaf by apache.

the class EncryptablePropertyPlaceholderTest method setUp.

@Before
public void setUp() throws Exception {
    StandardPBEStringEncryptor enc = new StandardPBEStringEncryptor();
    EnvironmentStringPBEConfig env = new EnvironmentStringPBEConfig();
    env.setAlgorithm("PBEWithMD5AndDES");
    env.setPassword("password");
    enc.setConfig(env);
    String val = enc.encrypt("bar");
    System.setProperty("foo", val);
    System.setProperty("org.bundles.framework.storage", "target/bundles/" + System.currentTimeMillis());
    System.setProperty("karaf.name", "root");
    List<BundleDescriptor> bundles = new ClasspathScanner().scanForBundles("(Bundle-SymbolicName=*)");
    bundles.add(getBundleDescriptor("target/jasypt.jar", bundle().add("OSGI-INF/blueprint/karaf-jaas-jasypt.xml", getClass().getResource("/OSGI-INF/blueprint/karaf-jaas-jasypt.xml")).set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", "jasypt").set("Bundle-Version", "0.0.0")));
    bundles.add(getBundleDescriptor("target/test.jar", bundle().add("OSGI-INF/blueprint/test.xml", getClass().getResource("test.xml")).set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", "test").set("Bundle-Version", "0.0.0")));
    Map config = new HashMap();
    config.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, bundles);
    PojoServiceRegistry reg = new PojoServiceRegistryFactoryImpl().newPojoServiceRegistry(config);
    bundleContext = reg.getBundleContext();
}
Also used : PojoServiceRegistry(org.apache.felix.connect.launch.PojoServiceRegistry) StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor) BundleDescriptor(org.apache.felix.connect.launch.BundleDescriptor) HashMap(java.util.HashMap) PojoServiceRegistryFactoryImpl(org.apache.felix.connect.PojoServiceRegistryFactoryImpl) EnvironmentStringPBEConfig(org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig) HashMap(java.util.HashMap) Map(java.util.Map) ClasspathScanner(org.apache.felix.connect.launch.ClasspathScanner) Before(org.junit.Before)

Aggregations

PojoServiceRegistryFactoryImpl (org.apache.felix.connect.PojoServiceRegistryFactoryImpl)3 BundleDescriptor (org.apache.felix.connect.launch.BundleDescriptor)3 PojoServiceRegistry (org.apache.felix.connect.launch.PojoServiceRegistry)3 HashMap (java.util.HashMap)2 ClasspathScanner (org.apache.felix.connect.launch.ClasspathScanner)2 StandardPBEStringEncryptor (org.jasypt.encryption.pbe.StandardPBEStringEncryptor)2 EnvironmentStringPBEConfig (org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig)2 Before (org.junit.Before)2 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1