Search in sources :

Example 6 with ContentHandler

use of org.apache.aries.subsystem.ContentHandler in project aries by apache.

the class CustomResourceInstaller method install.

@Override
public Resource install() throws Exception {
    try {
        ContentHandler handler = subsystem.getBundleContext().getService(handlerRef);
        if (handler != null) {
            InputStream is = ((RepositoryContent) resource).getContent();
            handler.install(is, ResourceHelper.getSymbolicNameAttribute(resource), type, subsystem, coordination);
            addReference(resource);
            return resource;
        } else {
            throw new Exception("Custom content handler not found: " + handlerRef);
        }
    } finally {
        subsystem.getBundleContext().ungetService(handlerRef);
    }
}
Also used : InputStream(java.io.InputStream) RepositoryContent(org.osgi.service.repository.RepositoryContent) ContentHandler(org.apache.aries.subsystem.ContentHandler)

Example 7 with ContentHandler

use of org.apache.aries.subsystem.ContentHandler in project aries by apache.

the class CustomContentHandlerTest method testCustomContentStartException.

@Test
@Ignore("This test currently doesn't pass, the bundle moves to the active state, while it shouldn't")
public void testCustomContentStartException() throws Exception {
    for (Bundle b : bundleContext.getBundles()) {
        if ("org.apache.aries.subsystem.itests.customcontent.bundleC".equals(b.getSymbolicName())) {
            fail("Precondition");
        }
    }
    SausagesContentHandler handler = new SausagesContentHandler(true, "start");
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(ContentHandler.CONTENT_TYPE_PROPERTY, "foo.sausages");
    ServiceRegistration<ContentHandler> reg = bundleContext.registerService(ContentHandler.class, handler, props);
    assertEquals("Precondition", 0, handler.calls.size());
    Subsystem subsystem = installSubsystemFromFile("customContent2.esa");
    try {
        assertEquals(Arrays.asList("install:customContent3 sausages = 3"), handler.calls);
        try {
            Bundle theBundle = null;
            for (Bundle b : bundleContext.getBundles()) {
                if ("org.apache.aries.subsystem.itests.customcontent.bundleC".equals(b.getSymbolicName())) {
                    assertEquals(Bundle.INSTALLED, b.getState());
                    theBundle = b;
                }
            }
            assertNotNull(theBundle);
            try {
                subsystem.start();
            } catch (Exception ex) {
            // good
            }
            assertEquals("There was an exception during start, so the bundle should not be started", Bundle.INSTALLED, theBundle.getState());
        } finally {
            subsystem.uninstall();
        }
    } finally {
        reg.unregister();
    }
}
Also used : Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) Subsystem(org.osgi.service.subsystem.Subsystem) ContentHandler(org.apache.aries.subsystem.ContentHandler) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ContentHandler (org.apache.aries.subsystem.ContentHandler)7 Hashtable (java.util.Hashtable)6 Test (org.junit.Test)6 Bundle (org.osgi.framework.Bundle)6 Subsystem (org.osgi.service.subsystem.Subsystem)4 Ignore (org.junit.Ignore)3 InputStream (java.io.InputStream)1 Capability (org.osgi.resource.Capability)1 Resource (org.osgi.resource.Resource)1 RepositoryContent (org.osgi.service.repository.RepositoryContent)1