2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.properties;
24 import javax.servlet.ServletContextEvent;
25 import javax.servlet.ServletContextListener;
26 import javax.servlet.annotation.WebListener;
28 import org.openecomp.mso.logger.MessageEnum;
29 import org.openecomp.mso.logger.MsoLogger;
32 * This class will attempt to initialize MSO Properties when part of a web application.
33 * It will look for the configuration file mso.properties in the
35 * 1. In an init-param "mso.configuration" in web.xml
36 * 2. In a system property "mso.configuration"
37 * 3. In the default location "/etc/ecomp/mso/config/mso.properties"
39 * If all else fails, the MSO Properties will go uninitialized, and will
40 * attempt to use the default constructors within the MsoProperties class.
45 public class MsoPropertyInitializer implements ServletContextListener
48 private MsoPropertiesFactory msoPropertiesFactory=new MsoPropertiesFactory();
50 public MsoPropertyInitializer () {
54 public void contextDestroyed(ServletContextEvent event) {
60 public void contextInitialized(ServletContextEvent event)
63 // Note - this logger may be before or after MSO Logging configuration applied
64 MsoLogger initLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL);
66 // Look first in the init-parameters
67 String msoPropConfigParam = event.getServletContext().getInitParameter("mso.configuration");
68 if (msoPropConfigParam != null && !msoPropConfigParam.isEmpty() ) {
69 String[] configFileSplit = msoPropConfigParam.split(",");
70 for (String msoPropConfig:configFileSplit) {
71 String[] msoPropDecoded = msoPropConfig.split("=");
74 msoPropertiesFactory.initializeMsoProperties(msoPropDecoded[0], msoPropDecoded[1]);
75 initLogger.info(MessageEnum.LOAD_PROPERTIES_SUC, msoPropDecoded[1], "", "");
76 initLogger.debug("Mso properties successfully loaded:"+msoPropDecoded[1]+",ID:"+msoPropDecoded[0]+")");
77 } catch (MsoPropertiesException e) {
78 initLogger.error(MessageEnum.LOAD_PROPERTIES_FAIL, msoPropDecoded[1] + ". MSO Properties failed due to an mso properties exception", "", "", MsoLogger.ErrorCode.DataError, "Error in contextInitialized", e);
84 initLogger.error(MessageEnum.LOAD_PROPERTIES_FAIL, "Unknown. MSO Properties failed to initialize completely", "", "", MsoLogger.ErrorCode.DataError, "", e);