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);
}
}
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();
}
}
Aggregations