aboutsummaryrefslogtreecommitdiffstats
path: root/aai-schema-service/src/main/java/org/onap
diff options
context:
space:
mode:
authorIgor Dysko <igor1.dysko@orange.com>2020-06-27 23:42:28 +0200
committerIgor Dysko <igor1.dysko@orange.com>2020-07-06 14:46:52 +0200
commit37a8cab63cef498490f50c0b0262bf0696cabf85 (patch)
treec09ac4528d76546ea21d3ddaa70e06fb0f07dcf2 /aai-schema-service/src/main/java/org/onap
parent95dadba8706ede75a0b39127b40b6430031fa1d3 (diff)
Update to spring boot 2
Update of code and dependencies, no changes in functionality Issue-ID: AAI-2529 Signed-off-by: Igor Dysko <igor1.dysko@orange.com> Change-Id: Ia43601c2990a67c0e8afefa1d54c53d7e606b886
Diffstat (limited to 'aai-schema-service/src/main/java/org/onap')
-rw-r--r--aai-schema-service/src/main/java/org/onap/aai/schemaservice/SchemaServiceApp.java4
-rw-r--r--aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/PropertyPasswordConfiguration.java16
-rw-r--r--aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/SchemaConfiguration.java6
-rw-r--r--aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/ResponseTransactionLogging.java38
-rw-r--r--aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/RequestTransactionLogging.java38
-rw-r--r--aai-schema-service/src/main/java/org/onap/aai/schemaservice/logging/LocalHostAccessLog.java10
-rw-r--r--aai-schema-service/src/main/java/org/onap/aai/schemaservice/web/JerseyConfiguration.java17
7 files changed, 71 insertions, 58 deletions
diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/SchemaServiceApp.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/SchemaServiceApp.java
index 4e5bea5..66718dd 100644
--- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/SchemaServiceApp.java
+++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/SchemaServiceApp.java
@@ -39,6 +39,7 @@ import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.Map;
import java.util.UUID;
+import org.springframework.web.context.request.RequestContextListener;
@SpringBootApplication
// Component Scan provides a way to look for spring beans
@@ -71,12 +72,11 @@ public class SchemaServiceApp {
setDefaultProps();
-
-
SpringApplication app = new SpringApplication(SchemaServiceApp.class);
app.setLogStartupInfo(false);
app.setRegisterShutdownHook(true);
app.addInitializers(new PropertyPasswordConfiguration());
+
Environment env = app.run(args).getEnvironment();
logger.debug(
diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/PropertyPasswordConfiguration.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/PropertyPasswordConfiguration.java
index db67ac6..df1d91c 100644
--- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/PropertyPasswordConfiguration.java
+++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/PropertyPasswordConfiguration.java
@@ -19,13 +19,6 @@
*/
package org.onap.aai.schemaservice.config;
-import org.springframework.context.ApplicationContextInitializer;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.core.env.ConfigurableEnvironment;
-import org.springframework.core.env.EnumerablePropertySource;
-import org.springframework.core.env.MapPropertySource;
-import org.springframework.core.env.PropertySource;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -35,13 +28,15 @@ import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
+import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.commons.io.IOUtils;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.core.env.*;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.EnumerablePropertySource;
+import org.springframework.core.env.MapPropertySource;
+import org.springframework.core.env.PropertySource;
public class PropertyPasswordConfiguration implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@@ -51,6 +46,7 @@ public class PropertyPasswordConfiguration implements ApplicationContextInitiali
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
+
ConfigurableEnvironment environment = applicationContext.getEnvironment();
String certPath = environment.getProperty("server.certs.location");
File passwordFile = null;
diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/SchemaConfiguration.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/SchemaConfiguration.java
index 390525b..28f6bc1 100644
--- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/SchemaConfiguration.java
+++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/SchemaConfiguration.java
@@ -21,7 +21,11 @@ package org.onap.aai.schemaservice.config;
import org.onap.aai.schemaservice.nodeschema.NodeIngestor;
import org.onap.aai.schemaservice.nodeschema.SchemaVersions;
-import org.onap.aai.schemaservice.nodeschema.validation.*;
+import org.onap.aai.schemaservice.nodeschema.validation.CheckEverythingStrategy;
+import org.onap.aai.schemaservice.nodeschema.validation.DefaultDuplicateNodeDefinitionValidationModule;
+import org.onap.aai.schemaservice.nodeschema.validation.DuplicateNodeDefinitionValidationModule;
+import org.onap.aai.schemaservice.nodeschema.validation.NodeValidator;
+import org.onap.aai.schemaservice.nodeschema.validation.SchemaErrorStrategy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/ResponseTransactionLogging.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/ResponseTransactionLogging.java
index bc42d0f..10f0e61 100644
--- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/ResponseTransactionLogging.java
+++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/ResponseTransactionLogging.java
@@ -19,34 +19,31 @@
*/
package org.onap.aai.schemaservice.interceptors.post;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.gson.JsonObject;
-import org.onap.aai.exceptions.AAIException;
-import org.onap.aai.logging.ErrorLogHelper;
-import org.onap.aai.schemaservice.interceptors.AAIContainerFilter;
-import org.onap.aai.schemaservice.interceptors.AAIHeaderProperties;
-import org.onap.aai.util.AAIConfig;
-import org.springframework.beans.factory.annotation.Autowired;
-
+import java.io.IOException;
+import java.util.Objects;
+import java.util.Optional;
import javax.annotation.Priority;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
-import java.io.IOException;
-import java.util.Objects;
-import java.util.Optional;
+import org.onap.aai.logging.ErrorLogHelper;
+import org.onap.aai.schemaservice.interceptors.AAIContainerFilter;
+import org.onap.aai.schemaservice.interceptors.AAIHeaderProperties;
+import org.onap.aai.util.AAIConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.request.RequestAttributes;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
@Priority(AAIResponseFilterPriority.RESPONSE_TRANS_LOGGING)
public class ResponseTransactionLogging extends AAIContainerFilter implements ContainerResponseFilter {
private static final Logger TRANSACTION_LOGGER = LoggerFactory.getLogger(ResponseTransactionLogging.class);
- @Autowired
- private HttpServletResponse httpServletResponse;
-
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException {
@@ -97,10 +94,19 @@ public class ResponseTransactionLogging extends AAIContainerFilter implements Co
}
}
+ private String getHttpServletResponseContentType() {
+ final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
+ if (requestAttributes != null) {
+ HttpServletResponse response = ((ServletRequestAttributes) requestAttributes).getResponse();
+ return response.getContentType();
+ }
+ return null;
+ }
+
private String getResponseString(ContainerResponseContext responseContext) {
JsonObject response = new JsonObject();
response.addProperty("ID", responseContext.getHeaderString(AAIHeaderProperties.AAI_TX_ID));
- response.addProperty("Content-Type", this.httpServletResponse.getContentType());
+ response.addProperty("Content-Type", getHttpServletResponseContentType());
response.addProperty("Response-Code", responseContext.getStatus());
response.addProperty("Headers", responseContext.getHeaders().toString());
Optional<Object> entityOptional = Optional.ofNullable(responseContext.getEntity());
diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/RequestTransactionLogging.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/RequestTransactionLogging.java
index 4208649..fbf9fbe 100644
--- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/RequestTransactionLogging.java
+++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/RequestTransactionLogging.java
@@ -20,24 +20,25 @@
package org.onap.aai.schemaservice.interceptors.pre;
import com.google.gson.JsonObject;
-import org.glassfish.jersey.message.internal.ReaderWriter;
-import org.glassfish.jersey.server.ContainerException;
-import org.onap.aai.schemaservice.interceptors.AAIContainerFilter;
-import org.onap.aai.schemaservice.interceptors.AAIHeaderProperties;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.util.StringUtils;
-
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.UUID;
import javax.annotation.Priority;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.container.PreMatching;
import javax.ws.rs.core.MediaType;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.UUID;
+import org.glassfish.jersey.message.internal.ReaderWriter;
+import org.glassfish.jersey.server.ContainerException;
+import org.onap.aai.schemaservice.interceptors.AAIContainerFilter;
+import org.onap.aai.schemaservice.interceptors.AAIHeaderProperties;
+import org.springframework.util.StringUtils;
+import org.springframework.web.context.request.RequestAttributes;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
@PreMatching
@Priority(AAIRequestFilterPriority.REQUEST_TRANS_LOGGING)
@@ -48,8 +49,6 @@ public class RequestTransactionLogging extends AAIContainerFilter implements Con
private static final String CONTENT_TYPE = "Content-Type";
private static final String ACCEPT = "Accept";
private static final String TEXT_PLAIN = "text/plain";
- @Autowired
- private HttpServletRequest httpServletRequest;
@Override
public void filter(ContainerRequestContext requestContext) {
@@ -85,12 +84,21 @@ public class RequestTransactionLogging extends AAIContainerFilter implements Con
return txId;
}
+ private String getHttpServletRequestContentType() {
+ final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
+ if (requestAttributes != null) {
+ HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
+ return request.getContentType();
+ }
+ return null;
+ }
+
private String getRequest(ContainerRequestContext requestContext, String fullId) {
JsonObject request = new JsonObject();
request.addProperty("ID", fullId);
request.addProperty("Http-Method", requestContext.getMethod());
- request.addProperty(CONTENT_TYPE, httpServletRequest.getContentType());
+ request.addProperty(CONTENT_TYPE, getHttpServletRequestContentType());
request.addProperty("Headers", requestContext.getHeaders().toString());
ByteArrayOutputStream out = new ByteArrayOutputStream();
diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/logging/LocalHostAccessLog.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/logging/LocalHostAccessLog.java
index 4da1122..9ff3cb2 100644
--- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/logging/LocalHostAccessLog.java
+++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/logging/LocalHostAccessLog.java
@@ -24,9 +24,9 @@ import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.RequestLogHandler;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
-import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
-import org.springframework.boot.context.embedded.jetty.JettyServerCustomizer;
+import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer;
+import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
+import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -36,12 +36,12 @@ import java.util.Arrays;
public class LocalHostAccessLog {
@Bean
- public EmbeddedServletContainerFactory jettyConfigBean(
+ public AbstractServletWebServerFactory jettyConfigBean(
@Value("${jetty.threadPool.maxThreads:200}") final String maxThreads,
@Value("${jetty.threadPool.minThreads:8}") final String minThreads
) {
- JettyEmbeddedServletContainerFactory jef = new JettyEmbeddedServletContainerFactory();
+ JettyServletWebServerFactory jef = new JettyServletWebServerFactory();
jef.addServerCustomizers((JettyServerCustomizer) server -> {
HandlerCollection handlers = new HandlerCollection();
diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/web/JerseyConfiguration.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/web/JerseyConfiguration.java
index 3023fab..182203d 100644
--- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/web/JerseyConfiguration.java
+++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/web/JerseyConfiguration.java
@@ -19,27 +19,26 @@
*/
package org.onap.aai.schemaservice.web;
+import java.util.List;
+import java.util.Set;
+import java.util.logging.Logger;
+import java.util.stream.Collectors;
+import javax.annotation.Priority;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.container.ContainerResponseFilter;
import org.glassfish.jersey.server.ResourceConfig;
import org.onap.aai.schemaservice.edges.EdgeResource;
import org.onap.aai.schemaservice.healthcheck.EchoResource;
import org.onap.aai.schemaservice.nodeschema.NodeSchemaResource;
import org.onap.aai.schemaservice.query.QueryResource;
import org.onap.aai.schemaservice.versions.VersionResource;
+import org.onap.logging.filter.base.AuditLogContainerFilter;
import org.reflections.Reflections;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
-import javax.annotation.Priority;
-import javax.ws.rs.container.ContainerRequestFilter;
-import javax.ws.rs.container.ContainerResponseFilter;
-import java.util.List;
-import java.util.Set;
-import java.util.logging.Logger;
-import java.util.stream.Collectors;
-import org.onap.logging.filter.base.AuditLogContainerFilter;
-
@Component
public class JerseyConfiguration extends ResourceConfig {