2 * Copyright 2016 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openo.baseservice.bus.util;
20 import java.io.IOException;
22 import javax.servlet.ServletContextEvent;
23 import javax.servlet.ServletContextListener;
25 import org.openo.baseservice.util.impl.SystemEnvVariablesFactory;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
30 * Initialize the service register listener. <br/>
37 public class RegisterServiceListener implements ServletContextListener {
39 private static final Logger LOGGER = LoggerFactory.getLogger(RegisterServiceListener.class);
42 public void contextInitialized(ServletContextEvent sce) {
44 String servicePath = SystemEnvVariablesFactory.getInstance().getAppRoot() + BusConstant.MICROSERVICE_PATH;
45 LOGGER.info("microservices json file path is" + servicePath);
47 File file = new File(servicePath);
49 File[] fileList = file.listFiles();
51 for (File tempFile : fileList) {
52 String fileName = tempFile.getName();
53 if (fileName.substring(fileName.lastIndexOf('.') + 1).equalsIgnoreCase(BusConstant.JSON)) {
54 LOGGER.info("begin to initialize the service file" + tempFile.getAbsolutePath());
57 RegisterService.registerService(tempFile.getAbsolutePath(), true);
58 } catch (IOException e) {
59 LOGGER.error("Faile to register the service file :" + tempFile.getPath() + ", exception:" + e);
66 public void contextDestroyed(ServletContextEvent sce) {
67 // TODO Auto-generated method stub