private void setSubscriptionConfiguration() { NotificationConfig config = new NotificationConfig(); String fileName = CarbonUtils.getCarbonConfigDirPath() + File.separator + "registry.xml"; if ((new File(fileName)).exists()) { config = loadeNotificationConfig(fileName); } if (config == null) { config = new NotificationConfig(); } String serverURL = EventingDataHolder.getInstance().getDefaultEventingServiceURL(); if (serverURL != null && serverURL.indexOf("/services/RegistryEventingService") > -1) { serverURL = serverURL.substring(0, serverURL.length() - "/services/RegistryEventingService".length()); } if (config.getConfigurationClass() == null) { config.setConfigurationClass(defaultClass); } if (config.getStoreURL() == null) { config.setStoreURL(serverURL + "/store"); } if (config.getPublisherURL() == null) { config.setPublisherURL(serverURL + "/publisher"); } if (config.getConsoleURL() == null) { config.setConsoleURL(serverURL + "/carbon"); } EventingDataHolder.getInstance().setNotificationConfig(config); }
private NotificationConfig loadeNotificationConfig(String configFilename) { NotificationConfig config = new NotificationConfig(); File configFile = new File(configFilename); if (!configFile.exists()) { log.error("Configuration File is not present at: " + configFilename); return null; } try { XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(new FileInputStream(configFile)); StAXOMBuilder builder = new StAXOMBuilder(parser); OMElement documentElement = builder.getDocumentElement(); OMElement notificationConfig = documentElement.getFirstChildWithName(new QName("notificationConfiguration")); if (notificationConfig != null) { // registry.xml need an <notificationConfiguration> // </notificationConfiguration> entry to continue Iterator it = notificationConfig.getChildElements(); while (it.hasNext()) { OMElement element = (OMElement) it.next(); if ("class".equals(element.getLocalName())) { config.setConfigurationClass(element.getText()); } else if ("storeURL".equals(element.getLocalName())) { config.setStoreURL(element.getText()); } else if ("publisherURL".equals(element.getLocalName())) { config.setPublisherURL(element.getText()); } else if ("consoleURL".equals(element.getLocalName())) { config.setConsoleURL(element.getText()); } } } return config; } catch (Exception e) { String msg = "Error in loading configuration : " + configFilename + "."; log.error(msg, e); return null; } }