use of org.motechproject.osgi.web.exception.BundleConfigurationLoadingException in project motech by motech.
the class Log4JBundleLoader method loadBundle.
public void loadBundle(Bundle bundle) throws BundleConfigurationLoadingException, IOException {
String symbolicName = bundle.getSymbolicName();
LOGGER.debug("Looking for log4j config in {}", symbolicName);
URL log4jUrl = bundle.getResource(log4JConf);
if (log4jUrl != null) {
LOGGER.debug("Log4j config found in {}, loading", symbolicName);
InputStream log4jStream = null;
try {
URLConnection conn = log4jUrl.openConnection();
log4jStream = conn.getInputStream();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
db.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
return new InputSource(new StringReader(""));
}
});
Document log4jDoc = db.parse(log4jStream);
if (loggers != null && checkLogXmlConfiguration(log4jDoc)) {
PropertyConfigurator.configure(loggerProperties);
} else {
DOMConfigurator.configure(log4jDoc.getDocumentElement());
}
logService.reconfigure();
LOGGER.debug("Added log4j configuration for [" + bundle.getLocation() + "]");
} catch (ParserConfigurationException | SAXException e) {
throw new BundleConfigurationLoadingException("Error while loading log4j configuration from " + bundle, e);
} finally {
IOUtils.closeQuietly(log4jStream);
}
}
}
use of org.motechproject.osgi.web.exception.BundleConfigurationLoadingException in project motech by motech.
the class BlueprintApplicationContextTracker method addingService.
@Override
public Object addingService(ServiceReference serviceReference) {
ApplicationContext applicationContext = (ApplicationContext) super.addingService(serviceReference);
Bundle bundle = serviceReference.getBundle();
String symbolicName = nullSafeSymbolicName(bundle);
LOGGER.info("Processing context for: {}", symbolicName);
if (!isBlueprintEnabledBundle(bundle)) {
LOGGER.debug("Bundle {} is not Blueprint Enabled", symbolicName);
return applicationContext;
}
String contextServiceName = getServiceName(serviceReference);
if (!symbolicName.equals(contextServiceName)) {
LOGGER.warn("Bundle symbolic name [{}] does not match the service name of the context [{}]", symbolicName, contextServiceName);
return applicationContext;
}
if (httpServiceTrackers.isBeingTracked(bundle)) {
LOGGER.debug("Bundle {} is already tracked", symbolicName);
return applicationContext;
}
LOGGER.debug("Registering trackers for {}", symbolicName);
httpServiceTrackers.addTrackerFor(bundle);
uiServiceTrackers.addTrackerFor(bundle, applicationContext);
LOGGER.debug("Trackers registered for {}", symbolicName);
// scan for logger configuration, we don't want to do this in tests
if (!StringUtils.equalsIgnoreCase("true", System.getProperty(IGNORE_DB_VAR))) {
LOGGER.debug("Scanning bundle {} for logger configuration", symbolicName);
synchronized (this) {
if (OSGI_WEB_UTIL.equals(symbolicName)) {
logBundleLoader = applicationContext.getBean(Log4JBundleLoader.class);
}
try {
BundleRegister bundleRegister = BundleRegister.getInstance();
bundleRegister.addBundle(bundle);
if (logBundleLoader != null) {
List<Bundle> bundleList = bundleRegister.getBundleList();
for (Bundle bundleElement : bundleList) {
logBundleLoader.loadBundle(bundleElement);
}
bundleRegister.getBundleList().clear();
}
} catch (BundleConfigurationLoadingException e) {
LOGGER.error("Failed adding log4j configuration for [" + serviceReference.getBundle().getLocation() + "]\n" + e.getMessage());
} catch (IOException e) {
LOGGER.error(e.getMessage());
}
}
}
return applicationContext;
}
Aggregations