eb2e122bdf7af796704bb87817bc17abc4a461d8
[vfc/nfvo/wfengine.git] / common-util / src / main / java / org / openo / baseservice / bus / util / RegisterServiceListener.java
1 /*
2  * Copyright 2016 Huawei Technologies Co., Ltd.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.openo.baseservice.bus.util;
18
19 import java.io.File;
20
21 import javax.servlet.ServletContextEvent;
22 import javax.servlet.ServletContextListener;
23
24 import org.openo.baseservice.util.impl.SystemEnvVariablesFactory;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 /**
29  * Initialize the service register listener.
30  * <br/>
31  * <p>  
32  * </p>
33  * 
34  * @author
35  * @version  
36  */
37 public class RegisterServiceListener implements ServletContextListener {
38
39     private static final Logger LOGGER = LoggerFactory.getLogger(RegisterServiceListener.class);
40     
41     private static final String JSON = "json";
42
43     @Override
44     public void contextInitialized(ServletContextEvent sce) {
45
46         String servicePath = SystemEnvVariablesFactory.getInstance().getAppRoot() + "/etc/microservice";
47         LOGGER.info("microservices json file path is" + servicePath);
48
49         File file = new File(servicePath);
50
51         File[] fileList = file.listFiles();
52
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());
57                 
58                 /** now because ZTE do not provide the service bus.commont this code first.
59                 try {
60                     RegisterService.registerService(tempFile.getAbsolutePath(), true);
61                 } catch(IOException e) {
62                     LOGGER.error("Faile to register the service file :" + tempFile.getPath() + ", exception:" + e);
63                 }
64                 */
65             }
66         }
67     }
68
69     @Override
70     public void contextDestroyed(ServletContextEvent sce) {
71         // TODO Auto-generated method stub
72
73     }
74 }