diff options
Diffstat (limited to 'common-app-api/src/main/java/org/openecomp/sdc/common/listener/AppContextListener.java')
-rw-r--r-- | common-app-api/src/main/java/org/openecomp/sdc/common/listener/AppContextListener.java | 120 |
1 files changed, 60 insertions, 60 deletions
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/listener/AppContextListener.java b/common-app-api/src/main/java/org/openecomp/sdc/common/listener/AppContextListener.java index f5325a73e1..dd05ee47ae 100644 --- a/common-app-api/src/main/java/org/openecomp/sdc/common/listener/AppContextListener.java +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/listener/AppContextListener.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -39,89 +39,89 @@ import java.util.jar.Manifest; public class AppContextListener implements ServletContextListener { - private static Logger log = Logger.getLogger(AppContextListener.class.getName()); + private static Logger log = Logger.getLogger(AppContextListener.class.getName()); - public void contextInitialized(ServletContextEvent context) { + public void contextInitialized(ServletContextEvent context) { - log.debug("ServletContextListener initialized "); + log.debug("ServletContextListener initialized "); - log.debug("After read values from Manifest {}", getManifestInfo(context.getServletContext())); + log.debug("After read values from Manifest {}", getManifestInfo(context.getServletContext())); - Map<String, String> manifestAttr = getManifestInfo(context.getServletContext()); + Map<String, String> manifestAttr = getManifestInfo(context.getServletContext()); - String appName = setAndGetAttributeInContext(context, manifestAttr, Constants.APPLICATION_NAME); - String appVersion = setAndGetAttributeInContext(context, manifestAttr, Constants.APPLICATION_VERSION); + String appName = setAndGetAttributeInContext(context, manifestAttr, Constants.APPLICATION_NAME); + String appVersion = setAndGetAttributeInContext(context, manifestAttr, Constants.APPLICATION_VERSION); - ExternalConfiguration.setAppName(appName); - ExternalConfiguration.setAppVersion(appVersion); - String configHome = System.getProperty(Constants.CONFIG_HOME); - ExternalConfiguration.setConfigDir(configHome); + ExternalConfiguration.setAppName(appName); + ExternalConfiguration.setAppVersion(appVersion); + String configHome = System.getProperty(Constants.CONFIG_HOME); + ExternalConfiguration.setConfigDir(configHome); - String appConfigDir = configHome + File.separator + appName; - // ChangeListener changeListener = new ChangeListener(); - ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), - appConfigDir); + String appConfigDir = configHome + File.separator + appName; + // ChangeListener changeListener = new ChangeListener(); + ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), + appConfigDir); - context.getServletContext().setAttribute(Constants.CONFIGURATION_SOURCE_ATTR, configurationSource); + context.getServletContext().setAttribute(Constants.CONFIGURATION_SOURCE_ATTR, configurationSource); - ExternalConfiguration.setConfigurationSource(configurationSource); + ExternalConfiguration.setConfigurationSource(configurationSource); - ExternalConfiguration.listenForChanges(); + ExternalConfiguration.listenForChanges(); - } + } - public void contextDestroyed(ServletContextEvent context) { + public void contextDestroyed(ServletContextEvent context) { - log.debug("ServletContextListener destroyed"); - ExternalConfiguration.stopListenForFileChanges(); - } + log.debug("ServletContextListener destroyed"); + ExternalConfiguration.stopListenForFileChanges(); + } - private String setAndGetAttributeInContext(ServletContextEvent context, Map<String, String> manifestAttr, - String attr) { + private String setAndGetAttributeInContext(ServletContextEvent context, Map<String, String> manifestAttr, + String attr) { - String name = manifestAttr.get(attr); - if (name != null) { - context.getServletContext().setAttribute(attr, name); - } + String name = manifestAttr.get(attr); + if (name != null) { + context.getServletContext().setAttribute(attr, name); + } - return name; - } + return name; + } - public static Map<String, String> getManifestInfo(ServletContext application) { + public static Map<String, String> getManifestInfo(ServletContext application) { - Map<String, String> result = new HashMap<>(); - InputStream inputStream = null; - try { + Map<String, String> result = new HashMap<>(); + InputStream inputStream = null; + try { - inputStream = application.getResourceAsStream("/META-INF/MANIFEST.MF"); + inputStream = application.getResourceAsStream("/META-INF/MANIFEST.MF"); - Manifest manifest = new Manifest(inputStream); + Manifest manifest = new Manifest(inputStream); - Attributes attr = manifest.getMainAttributes(); - String name = attr.getValue("Implementation-Title"); - if (name != null) { - result.put(Constants.APPLICATION_NAME, name); - } + Attributes attr = manifest.getMainAttributes(); + String name = attr.getValue("Implementation-Title"); + if (name != null) { + result.put(Constants.APPLICATION_NAME, name); + } - String version = attr.getValue("Implementation-Version"); - if (version != null) { - result.put(Constants.APPLICATION_VERSION, version); - } + String version = attr.getValue("Implementation-Version"); + if (version != null) { + result.put(Constants.APPLICATION_VERSION, version); + } - } catch (IOException e) { + } catch (IOException e) { - } finally { - if (inputStream != null) { - try { - inputStream.close(); - } catch (IOException e) { - log.info("close FileOutputStream failed - {}" , e); - } - } - } + } finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + log.info("close FileOutputStream failed - {}", e); + } + } + } - return result; + return result; - } + } } |