2 * ============LICENSE_START=======================================================
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
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=========================================================
20 package org.onap.aai.schemaservice;
22 import com.att.eelf.configuration.EELFLogger;
23 import com.att.eelf.configuration.EELFManager;
24 import org.onap.aai.exceptions.AAIException;
25 import org.onap.aai.logging.LoggingContext;
26 import org.onap.aai.logging.LoggingContext.StatusCode;
27 import org.onap.aai.schemaservice.config.PropertyPasswordConfiguration;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.boot.SpringApplication;
31 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
32 import org.springframework.boot.autoconfigure.SpringBootApplication;
33 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
34 import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
35 import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
36 import org.springframework.core.env.Environment;
38 import javax.annotation.PostConstruct;
39 import javax.annotation.PreDestroy;
41 import java.util.UUID;
43 @SpringBootApplication
44 // Component Scan provides a way to look for spring beans
45 // It only searches beans in the following packages
46 // Any method annotated with @Bean annotation or any class
47 // with @Component, @Configuration, @Service will be picked up
48 @EnableAutoConfiguration(exclude = {
49 DataSourceAutoConfiguration.class,
50 DataSourceTransactionManagerAutoConfiguration.class,
51 HibernateJpaAutoConfiguration.class
53 public class SchemaServiceApp {
55 private static final EELFLogger logger = EELFManager.getInstance().getLogger(SchemaServiceApp.class.getName());
57 private static final String APP_NAME = "aai-schema-service";
58 private static Map<String, String> contextMap;
61 private Environment env;
63 public static void main(String[] args) throws AAIException {
67 LoggingContext.save();
68 LoggingContext.component("init");
69 LoggingContext.partnerName("NA");
70 LoggingContext.targetEntity(APP_NAME);
71 LoggingContext.requestId(UUID.randomUUID().toString());
72 LoggingContext.serviceName(APP_NAME);
73 LoggingContext.targetServiceName("contextInitialized");
74 LoggingContext.statusCode(StatusCode.COMPLETE);
77 SpringApplication app = new SpringApplication(SchemaServiceApp.class);
78 app.setLogStartupInfo(false);
79 app.setRegisterShutdownHook(true);
80 app.addInitializers(new PropertyPasswordConfiguration());
81 Environment env = app.run(args).getEnvironment();
82 MDC.setContextMap(contextMap);
85 "Application '{}' is running on {}!",
86 env.getProperty("spring.application.name"),
87 env.getProperty("server.port")
90 logger.info("SchemaService MicroService Started");
92 System.out.println("SchemaService Microservice Started");
94 LoggingContext.restoreIfPossible();
97 public static void setDefaultProps() {
99 if (System.getProperty("file.separator") == null) {
100 System.setProperty("file.separator", "/");
103 String currentDirectory = System.getProperty("user.dir");
105 if (System.getProperty("AJSC_HOME") == null) {
106 System.setProperty("AJSC_HOME", ".");
109 if (currentDirectory.contains(APP_NAME)) {
110 if (System.getProperty("BUNDLECONFIG_DIR") == null) {
111 System.setProperty("BUNDLECONFIG_DIR", "src/main/resources");
114 if (System.getProperty("BUNDLECONFIG_DIR") == null) {
115 System.setProperty("BUNDLECONFIG_DIR", "aai-schema-service/src/main/resources");
121 private void init() throws AAIException {
122 System.setProperty("org.onap.aai.serverStarted", "false");
125 LoggingContext.save();
126 LoggingContext.component("init");
127 LoggingContext.partnerName("NA");
128 LoggingContext.targetEntity(APP_NAME);
129 LoggingContext.requestId(UUID.randomUUID().toString());
130 LoggingContext.serviceName(APP_NAME);
131 LoggingContext.targetServiceName("contextInitialized");
132 LoggingContext.statusCode(StatusCode.COMPLETE);
134 contextMap = MDC.getCopyOfContextMap();
135 logger.info("SchemaService initialization started...");
137 // Setting this property to allow for encoded slash (/) in the path parameter
138 // This is only needed for tomcat keeping this as temporary
139 System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true");
142 if (env.acceptsProfiles(Profiles.TWO_WAY_SSL) && env.acceptsProfiles(Profiles.ONE_WAY_SSL)) {
143 logger.warn("You have seriously misconfigured your application");
146 LoggingContext.restoreIfPossible();
150 public void cleanup() {
151 logger.info("SchemaService shutting down");