Search in sources :

Example 1 with BundleDescriptor

use of org.apache.felix.connect.launch.BundleDescriptor in project jackrabbit-oak by apache.

the class SpringBootSupport method processDescriptors.

public static List<BundleDescriptor> processDescriptors(List<BundleDescriptor> descriptors) throws IOException {
    List<BundleDescriptor> processed = Lists.newArrayList();
    for (BundleDescriptor desc : descriptors) {
        if (desc.getRevision() == null) {
            URL u = new URL(desc.getUrl());
            URLConnection uc = u.openConnection();
            if (uc instanceof JarURLConnection && uc.getClass().getName().startsWith(SPRING_BOOT_PACKAGE)) {
                Revision rev = new SpringBootJarRevision(((JarURLConnection) uc).getJarFile(), uc.getLastModified());
                desc = new BundleDescriptor(desc.getClassLoader(), desc.getUrl(), desc.getHeaders(), rev, desc.getServices());
            }
        }
        processed.add(desc);
    }
    return processed;
}
Also used : BundleDescriptor(org.apache.felix.connect.launch.BundleDescriptor) Revision(org.apache.felix.connect.Revision) JarURLConnection(java.net.JarURLConnection) URL(java.net.URL) URLConnection(java.net.URLConnection) JarURLConnection(java.net.JarURLConnection)

Example 2 with BundleDescriptor

use of org.apache.felix.connect.launch.BundleDescriptor 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 3 with BundleDescriptor

use of org.apache.felix.connect.launch.BundleDescriptor in project karaf by apache.

the class EncryptableConfigAdminPropertyPlaceholderTest method getBundleDescriptor.

private BundleDescriptor getBundleDescriptor(String path, TinyBundle bundle) throws Exception {
    File file = new File(path);
    FileOutputStream fos = new FileOutputStream(file);
    StreamUtils.copy(bundle.build(), fos);
    fos.close();
    JarInputStream jis = new JarInputStream(new FileInputStream(file));
    Map<String, String> headers = new HashMap<>();
    for (Map.Entry entry : jis.getManifest().getMainAttributes().entrySet()) {
        headers.put(entry.getKey().toString(), entry.getValue().toString());
    }
    return new BundleDescriptor(getClass().getClassLoader(), "jar:" + file.toURI().toString() + "!/", headers);
}
Also used : BundleDescriptor(org.apache.felix.connect.launch.BundleDescriptor) JarInputStream(java.util.jar.JarInputStream)

Example 4 with BundleDescriptor

use of org.apache.felix.connect.launch.BundleDescriptor in project karaf by apache.

the class EncryptablePropertyPlaceholderTest method getBundleDescriptor.

private BundleDescriptor getBundleDescriptor(String path, TinyBundle bundle) throws Exception {
    File file = new File(path);
    FileOutputStream fos = new FileOutputStream(file);
    StreamUtils.copy(bundle.build(), fos);
    fos.close();
    JarInputStream jis = new JarInputStream(new FileInputStream(file));
    Map<String, String> headers = new HashMap<>();
    for (Map.Entry entry : jis.getManifest().getMainAttributes().entrySet()) {
        headers.put(entry.getKey().toString(), entry.getValue().toString());
    }
    return new BundleDescriptor(getClass().getClassLoader(), "jar:" + file.toURI().toString() + "!/", headers);
}
Also used : BundleDescriptor(org.apache.felix.connect.launch.BundleDescriptor) JarInputStream(java.util.jar.JarInputStream) HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) FileInputStream(java.io.FileInputStream)

Example 5 with BundleDescriptor

use of org.apache.felix.connect.launch.BundleDescriptor in project camel by apache.

the class CamelBlueprintHelper method getBundleDescriptor.

private static BundleDescriptor getBundleDescriptor(String path, TinyBundle bundle) throws Exception {
    File file = new File(path);
    // tell the JVM its okay to delete this file on exit as its a temporary file
    // the JVM may not successfully delete the file though
    file.deleteOnExit();
    FileOutputStream fos = new FileOutputStream(file, false);
    InputStream is = bundle.build();
    try {
        IOHelper.copyAndCloseInput(is, fos);
    } finally {
        IOHelper.close(is, fos);
    }
    BundleDescriptor answer = null;
    FileInputStream fis = null;
    JarInputStream jis = null;
    try {
        fis = new FileInputStream(file);
        jis = new JarInputStream(fis);
        Map<String, String> headers = new HashMap<String, String>();
        for (Map.Entry<Object, Object> entry : jis.getManifest().getMainAttributes().entrySet()) {
            headers.put(entry.getKey().toString(), entry.getValue().toString());
        }
        answer = new BundleDescriptor(bundle.getClass().getClassLoader(), "jar:" + file.toURI().toString() + "!/", headers);
    } finally {
        IOHelper.close(jis, fis);
    }
    return answer;
}
Also used : BundleDescriptor(org.apache.felix.connect.launch.BundleDescriptor) JarInputStream(java.util.jar.JarInputStream) HashMap(java.util.HashMap) JarInputStream(java.util.jar.JarInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) FileInputStream(java.io.FileInputStream)

Aggregations

BundleDescriptor (org.apache.felix.connect.launch.BundleDescriptor)10 HashMap (java.util.HashMap)5 Map (java.util.Map)3 JarInputStream (java.util.jar.JarInputStream)3 PojoServiceRegistryFactoryImpl (org.apache.felix.connect.PojoServiceRegistryFactoryImpl)3 ClasspathScanner (org.apache.felix.connect.launch.ClasspathScanner)3 PojoServiceRegistry (org.apache.felix.connect.launch.PojoServiceRegistry)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 StandardPBEStringEncryptor (org.jasypt.encryption.pbe.StandardPBEStringEncryptor)2 EnvironmentStringPBEConfig (org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig)2 Before (org.junit.Before)2 BundleException (org.osgi.framework.BundleException)2 BundleRevision (org.osgi.framework.wiring.BundleRevision)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 JarURLConnection (java.net.JarURLConnection)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1