[AAI] Release docker artifact 1.12.4
[aai/schema-service.git] / aai-schema-service / src / main / java / org / onap / aai / schemaservice / SchemaServiceApp.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.aai.schemaservice;
22
23 import javax.annotation.PostConstruct;
24 import javax.annotation.PreDestroy;
25
26 import org.onap.aai.aailog.logs.AaiDebugLog;
27 import org.onap.aai.exceptions.AAIException;
28 import org.onap.aai.schemaservice.config.PropertyPasswordConfiguration;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.boot.SpringApplication;
33 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
34 import org.springframework.boot.autoconfigure.SpringBootApplication;
35 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
36 import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
37 import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
38 import org.springframework.context.annotation.ComponentScan;
39 import org.springframework.core.env.Environment;
40
41 @SpringBootApplication
42 // Component Scan provides a way to look for spring beans
43 // It only searches beans in the following packages
44 // Any method annotated with @Bean annotation or any class
45 // with @Component, @Configuration, @Service will be picked up
46 @EnableAutoConfiguration(
47     exclude = {DataSourceAutoConfiguration.class,
48         DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
49 @ComponentScan(basePackages = {"org.onap.aai.schemaservice", "org.onap.aai.aaf"})
50 public class SchemaServiceApp {
51
52     private static final Logger logger = LoggerFactory.getLogger(SchemaServiceApp.class.getName());
53
54     private static final String APP_NAME = "aai-schema-service";
55     private static AaiDebugLog debugLog = new AaiDebugLog();
56     static {
57         debugLog.setupMDC();
58     }
59
60     @Autowired
61     private Environment env;
62
63     public static void main(String[] args) throws AAIException {
64
65         setDefaultProps();
66
67         SpringApplication app = new SpringApplication(SchemaServiceApp.class);
68         app.setLogStartupInfo(false);
69         app.setRegisterShutdownHook(true);
70         app.addInitializers(new PropertyPasswordConfiguration());
71
72         Environment env = app.run(args).getEnvironment();
73
74         logger.debug("Application '{}' is running on {}!",
75             env.getProperty("spring.application.name"), env.getProperty("server.port"));
76
77         logger.debug("SchemaService MicroService Started");
78
79         System.out.println("SchemaService Microservice Started");
80
81     }
82
83     public static void setDefaultProps() {
84
85         if (System.getProperty("file.separator") == null) {
86             System.setProperty("file.separator", "/");
87         }
88
89         String currentDirectory = System.getProperty("user.dir");
90
91         if (System.getProperty("AJSC_HOME") == null) {
92             System.setProperty("AJSC_HOME", ".");
93         }
94
95         if (currentDirectory.contains(APP_NAME)) {
96             if (System.getProperty("BUNDLECONFIG_DIR") == null) {
97                 System.setProperty("BUNDLECONFIG_DIR", "src/main/resources");
98             }
99         } else {
100             if (System.getProperty("BUNDLECONFIG_DIR") == null) {
101                 System.setProperty("BUNDLECONFIG_DIR", "aai-schema-service/src/main/resources");
102             }
103         }
104     }
105
106     @PostConstruct
107     private void init() throws AAIException {
108         System.setProperty("org.onap.aai.serverStarted", "false");
109         setDefaultProps();
110
111         logger.debug("SchemaService initialization started...");
112
113         // Setting this property to allow for encoded slash (/) in the path parameter
114         // This is only needed for tomcat keeping this as temporary
115         System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true");
116
117         if (env.acceptsProfiles(Profiles.TWO_WAY_SSL)
118             && env.acceptsProfiles(Profiles.ONE_WAY_SSL)) {
119             logger.warn("You have seriously misconfigured your application");
120         }
121
122     }
123
124     @PreDestroy
125     public void cleanup() {
126
127         logger.debug("SchemaService shutting down");
128     }
129 }