2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 Nordix Foundation
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===================================
21 package org.oransc.enrichment;
23 import com.fasterxml.jackson.databind.ObjectMapper;
25 import java.lang.invoke.MethodHandles;
27 import org.apache.catalina.connector.Connector;
28 import org.oransc.enrichment.configuration.ApplicationConfig;
29 import org.oransc.enrichment.repository.EiJobs;
30 import org.oransc.enrichment.repository.EiProducers;
31 import org.oransc.enrichment.repository.EiTypes;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.springframework.beans.factory.annotation.Value;
35 import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
36 import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
37 import org.springframework.context.annotation.Bean;
38 import org.springframework.context.annotation.Configuration;
43 @Value("${server.http-port}")
44 private int httpPort = 0;
46 private final ApplicationConfig applicationConfig = new ApplicationConfig();
47 private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
50 public ObjectMapper mapper() {
51 return new ObjectMapper();
55 public ServletWebServerFactory servletContainer() {
56 TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
58 tomcat.addAdditionalTomcatConnectors(getHttpConnector(httpPort));
64 public EiJobs eiJobs() {
65 EiJobs jobs = new EiJobs(getApplicationConfig());
67 jobs.restoreJobsFromDatabase();
68 } catch (Exception e) {
69 logger.error("Could not restore jobs from database: {}", e.getMessage());
75 public EiTypes eiTypes() {
80 public EiProducers eiProducers() {
81 return new EiProducers();
85 public ApplicationConfig getApplicationConfig() {
86 return this.applicationConfig;
89 private static Connector getHttpConnector(int httpPort) {
90 Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
91 connector.setScheme("http");
92 connector.setPort(httpPort);
93 connector.setSecure(false);