Search in sources :

Example 1 with TinyBundle

use of org.ops4j.pax.swissbox.tinybundles.core.TinyBundle in project camel by apache.

the class CamelBlueprintHelper method createBundleContext.

public static BundleContext createBundleContext(String name, String descriptors, boolean includeTestBundle, String bundleFilter, String testBundleVersion, String testBundleDirectives, ClassLoader loader, String[]... configAdminPidFiles) throws Exception {
    TinyBundle bundle = null;
    TinyBundle configAdminInitBundle = null;
    if (includeTestBundle) {
        // add ourselves as a bundle
        bundle = createTestBundle(testBundleDirectives == null ? name : name + ';' + testBundleDirectives, testBundleVersion, descriptors);
    }
    if (configAdminPidFiles != null) {
        configAdminInitBundle = createConfigAdminInitBundle(configAdminPidFiles);
    }
    return createBundleContext(name, bundleFilter, bundle, configAdminInitBundle, loader);
}
Also used : TinyBundle(org.ops4j.pax.swissbox.tinybundles.core.TinyBundle)

Example 2 with TinyBundle

use of org.ops4j.pax.swissbox.tinybundles.core.TinyBundle in project camel by apache.

the class MainTest method testMainWithoutIncludingTestBundle.

@Test
public void testMainWithoutIncludingTestBundle() throws Exception {
    TinyBundle bundle = TinyBundles.newBundle();
    bundle.add("OSGI-INF/blueprint/camel.xml", getClass().getResourceAsStream("main-loadfile.xml"));
    bundle.set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", SYMBOLIC_NAME).set("Bundle-Version", "1.0.0");
    File tb = File.createTempFile(SYMBOLIC_NAME + "-", ".jar", new File("target"));
    FileOutputStream out = new FileOutputStream(tb);
    IOUtils.copy(bundle.build(), out);
    out.close();
    // simulate `camel:run` which is run after packaging the artifact, so a "bundle" (location with
    // META-INF/MANIFEST.MF) is detected in target/classes
    URLClassLoader loader = new URLClassLoader(new URL[] { tb.toURI().toURL() }, getClass().getClassLoader());
    Main main = new Main();
    main.setLoader(loader);
    // bundle name will be used as filter for blueprint container filter
    main.setBundleName(SYMBOLIC_NAME);
    // don't include test bundle (which is what `mvn camel:run` actually does)
    main.setIncludeSelfAsBundle(false);
    // don't setup the blueprint file here - it'll be picked up from a bundle on classpath
    //main.setDescriptors("none!");
    // set the configAdmin persistent id
    main.setConfigAdminPid("stuff");
    // set the configAdmin persistent file name
    main.setConfigAdminFileName("src/test/resources/etc/stuff.cfg");
    main.doStart();
    ProducerTemplate template = main.getCamelTemplate();
    assertNotNull("We should get the template here", template);
    String result = template.requestBody("direct:start", "hello", String.class);
    assertEquals("Get a wrong response", "Bye hello", result);
    main.stop();
}
Also used : TinyBundle(org.ops4j.pax.swissbox.tinybundles.core.TinyBundle) ProducerTemplate(org.apache.camel.ProducerTemplate) FileOutputStream(java.io.FileOutputStream) URLClassLoader(java.net.URLClassLoader) File(java.io.File) Test(org.junit.Test)

Example 3 with TinyBundle

use of org.ops4j.pax.swissbox.tinybundles.core.TinyBundle in project aries by apache.

the class Helper method createTestBundle.

protected static TinyBundle createTestBundle(String name, String version, String descriptors) throws FileNotFoundException, MalformedURLException {
    TinyBundle bundle = TinyBundles.newBundle();
    for (URL url : getBlueprintDescriptors(descriptors)) {
        LOG.info("Using Blueprint XML file: " + url.getFile());
        bundle.add("OSGI-INF/blueprint/blueprint-" + url.getFile().replace("/", "-"), url);
    }
    bundle.set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", name).set("Bundle-Version", version);
    return bundle;
}
Also used : TinyBundle(org.ops4j.pax.swissbox.tinybundles.core.TinyBundle) URL(java.net.URL)

Example 4 with TinyBundle

use of org.ops4j.pax.swissbox.tinybundles.core.TinyBundle in project camel by apache.

the class CamelBlueprintHelper method createConfigAdminInitBundle.

protected static TinyBundle createConfigAdminInitBundle(String[]... configAdminPidFiles) throws IOException {
    TinyBundle bundle = TinyBundles.newBundle();
    StringWriter configAdminInit = null;
    for (String[] configAdminPidFile : configAdminPidFiles) {
        if (configAdminPidFile == null) {
            continue;
        }
        if (configAdminInit == null) {
            configAdminInit = new StringWriter();
        } else {
            configAdminInit.append(',');
        }
        configAdminInit.append(configAdminPidFile[1]).append("=");
        configAdminInit.append(new File(configAdminPidFile[0]).toURI().toString());
    }
    bundle.add(TestBundleActivator.class);
    bundle.add(Util.class);
    bundle.set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", "ConfigAdminInit").set("Bundle-Version", BUNDLE_VERSION).set("Bundle-Activator", TestBundleActivator.class.getName());
    if (configAdminInit != null) {
        bundle.set("X-Camel-Blueprint-ConfigAdmin-Init", configAdminInit.toString());
    }
    return bundle;
}
Also used : TinyBundle(org.ops4j.pax.swissbox.tinybundles.core.TinyBundle) StringWriter(java.io.StringWriter) File(java.io.File)

Example 5 with TinyBundle

use of org.ops4j.pax.swissbox.tinybundles.core.TinyBundle in project camel by apache.

the class CamelBlueprintHelper method createTestBundle.

protected static TinyBundle createTestBundle(String name, String version, String descriptors) throws IOException {
    TinyBundle bundle = TinyBundles.newBundle();
    for (URL url : getBlueprintDescriptors(descriptors)) {
        LOG.info("Using Blueprint XML file: " + url.getFile());
        bundle.add("OSGI-INF/blueprint/blueprint-" + url.getFile().replace("/", "-"), url);
    }
    bundle.set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", name).set("Bundle-Version", version);
    return bundle;
}
Also used : TinyBundle(org.ops4j.pax.swissbox.tinybundles.core.TinyBundle) URL(java.net.URL)

Aggregations

TinyBundle (org.ops4j.pax.swissbox.tinybundles.core.TinyBundle)6 File (java.io.File)3 URL (java.net.URL)2 PojoServiceRegistryFactoryImpl (de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl)1 BundleDescriptor (de.kalpatec.pojosr.framework.launch.BundleDescriptor)1 PojoServiceRegistry (de.kalpatec.pojosr.framework.launch.PojoServiceRegistry)1 FileOutputStream (java.io.FileOutputStream)1 StringWriter (java.io.StringWriter)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ProducerTemplate (org.apache.camel.ProducerTemplate)1 Test (org.junit.Test)1 NodeList (org.w3c.dom.NodeList)1