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;
21 import javax.servlet.ServletContextEvent;
22 import javax.servlet.ServletContextListener;
24 import org.openo.baseservice.util.impl.SystemEnvVariablesFactory;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * Initialize the service register listener.
37 public class RegisterServiceListener implements ServletContextListener {
39 private static final Logger LOGGER = LoggerFactory.getLogger(RegisterServiceListener.class);
41 private static final String JSON = "json";
44 public void contextInitialized(ServletContextEvent sce) {
46 String servicePath = SystemEnvVariablesFactory.getInstance().getAppRoot() + "/etc/microservice";
47 LOGGER.info("microservices json file path is" + servicePath);
49 File file = new File(servicePath);
51 File[] fileList = file.listFiles();
53 for(File tempFile : fileList) {
54 String fileName = tempFile.getName();
55 if (fileName.substring(fileName.lastIndexOf('.') + 1).equalsIgnoreCase(JSON)) {
56 LOGGER.info("begin to initialize the service file" + tempFile.getAbsolutePath());
58 /** now because ZTE do not provide the service bus.commont this code first.
60 RegisterService.registerService(tempFile.getAbsolutePath(), true);
61 } catch(IOException e) {
62 LOGGER.error("Faile to register the service file :" + tempFile.getPath() + ", exception:" + e);
70 public void contextDestroyed(ServletContextEvent sce) {
71 // TODO Auto-generated method stub