use of org.motechproject.server.ex.BundleLoadingException in project motech by motech.
the class JspBundleLoader method loadBundle.
@SuppressWarnings("unchecked")
@Override
public void loadBundle(Bundle bundle) throws BundleLoadingException {
// we want to build and unpack jar files in application temporary directory
// if we found jsp file then we will copy it to destination directory
File tempRoot = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
File destRoot = new File(servletContext.getRealPath("/"));
try {
if (tempRoot != null) {
tempDir = new File(tempRoot, String.valueOf(bundle.getBundleId()));
destDir = new File(destRoot, String.valueOf(bundle.getBundleId()));
// search for jars in bundle
Enumeration<URL> jars = bundle.findEntries("/", "*.jar", true);
if (jars != null) {
while (jars.hasMoreElements()) {
URL jarUrl = jars.nextElement();
// build jar file
File tempJarFile = new File(tempDir, jarUrl.getFile());
// This is why this step must be synchronized.
synchronized (JspBundleLoader.class) {
FileUtils.copyURLToFile(jarUrl, tempJarFile);
}
JarFile jarFile = new JarFile(tempJarFile);
searchForJspFilesInJarFile(jarFile);
tempJarFile.delete();
}
}
tempDir.delete();
// Search for *.jsp files in bundle
Enumeration<URL> jsps = bundle.findEntries("/webapp", "*.jsp", true);
if (jsps != null) {
while (jsps.hasMoreElements()) {
URL jspUrl = jsps.nextElement();
File destFile = new File(destDir, jspUrl.getFile());
FileUtils.copyURLToFile(jspUrl, destFile);
LOGGER.debug("Loaded " + jspUrl.getFile() + " from [" + bundle.getLocation() + "]");
}
}
// Search for *.properties files in bundle
for (String path : Arrays.asList("/webapp/resources/messages", "/webapp/messages", "/webapp/messages")) {
loadBundleMessageFilesFromBundle(bundle, destRoot, path);
}
}
} catch (IOException e) {
throw new BundleLoadingException("IO Error when laoding bundle " + bundle, e);
} catch (InvocationTargetException | NoSuchMethodException | NoSuchFieldException | IllegalAccessException e) {
throw new BundleLoadingException(e);
}
}
use of org.motechproject.server.ex.BundleLoadingException in project motech by motech.
the class OsgiFrameworkService method init.
public void init(BootstrapConfig bootstrapConfig) {
try (InputStream is = getClass().getResourceAsStream("/osgi.properties")) {
Properties properties = readOSGiProperties(bootstrapConfig, is);
this.setOsgiFramework(new Felix(properties));
} catch (IOException e) {
throw new OsgiException("Cannot read OSGi properties", e);
}
try {
LOGGER.info("Initializing OSGi framework");
ServletContext servletContext = ((WebApplicationContext) applicationContext).getServletContext();
osgiFramework.init();
BundleContext bundleContext = osgiFramework.getBundleContext();
// This is mandatory for Felix http servlet bridge
servletContext.setAttribute(BundleContext.class.getName(), bundleContext);
if (bootstrapConfig != null) {
LOGGER.info("Installing all available bundles");
installAllBundles(servletContext, bundleContext);
registerBundleLoaderExecutor();
}
platformStatusProxy = new PlatformStatusProxy(bundleContext);
LOGGER.info("OSGi framework initialization finished");
} catch (BundleLoadingException e) {
throw new OsgiException("Failed to start the OSGi framework, unable to load bundles", e);
} catch (BundleException e) {
throw new OsgiException("Failed to start the OSGi framework, error processing bundles", e);
} catch (IOException e) {
throw new OsgiException("Failed to start the OSGi framework, IO Error", e);
}
}
use of org.motechproject.server.ex.BundleLoadingException in project motech by motech.
the class OsgiFrameworkService method installAllBundles.
private void installAllBundles(ServletContext servletContext, BundleContext bundleContext) throws IOException, BundleLoadingException {
for (URL url : findBundles(servletContext)) {
LOGGER.debug("Installing bundle [" + url + "]");
try {
Bundle bundle = bundleContext.installBundle(url.toExternalForm());
bundleLocationMapping.put(bundle.getBundleId() + ".0", bundle.getLocation());
} catch (BundleException e) {
throw new BundleLoadingException("Failed to install bundle from " + url, e);
}
}
}
Aggregations