From be4c967659e73814dc14d9c144b8ad4156af4aca Mon Sep 17 00:00:00 2001 From: Fiete Ostkamp Date: Thu, 19 Oct 2023 11:54:55 +0200 Subject: Upgrade spring-boot to 2.4 - update spring-boot to latest available 2.4.X release - Content-Type's on GET requests now result in 415 (instead of being ignored) which necessitates changes to the ConfigurationTest Issue-ID: AAI-3667 Change-Id: If6cbce8185b443a79b5e3b32fa3ffede5cabee60 Signed-off-by: Fiete Ostkamp --- aai-resources/pom.xml | 13 ++--- .../interceptors/post/InvalidResponseStatus.java | 5 +- .../pre/RequestTransactionLogging.java | 2 +- .../java/org/onap/aai/rest/LegacyMoxyConsumer.java | 1 - .../src/main/resources/application.properties | 4 +- .../java/org/onap/aai/rest/ConfigurationTest.java | 63 +++++++++++----------- .../org/onap/aai/rest/ExceptionHandlerTest.java | 2 +- .../src/test/resources/application-test.properties | 4 +- 8 files changed, 48 insertions(+), 46 deletions(-) diff --git a/aai-resources/pom.xml b/aai-resources/pom.xml index 51c7e55..4336d67 100644 --- a/aai-resources/pom.xml +++ b/aai-resources/pom.xml @@ -32,10 +32,6 @@ 1.8 - 2.3.12.RELEASE - 5.2.15.RELEASE - ${spring.version} - ${spring.version} org.onap.aai.ResourcesApp @@ -85,13 +81,18 @@ ${project.basedir}/src/main/resources/application.properties + 2.4.13 + 5.3.13 + 4.0.1 + ${spring.version} + ${spring.version} 11.0.2 1.3.19 1.6.6 1.6.6 1.6.6 1.6.1 - 2.4.0 + 3.4.0 @@ -379,7 +380,7 @@ io.swagger - swagger-jersey-jaxrs + swagger-jersey2-jaxrs ${swagger.version} diff --git a/aai-resources/src/main/java/org/onap/aai/interceptors/post/InvalidResponseStatus.java b/aai-resources/src/main/java/org/onap/aai/interceptors/post/InvalidResponseStatus.java index 61ada79..1d20744 100644 --- a/aai-resources/src/main/java/org/onap/aai/interceptors/post/InvalidResponseStatus.java +++ b/aai-resources/src/main/java/org/onap/aai/interceptors/post/InvalidResponseStatus.java @@ -33,6 +33,7 @@ import javax.ws.rs.core.MediaType; import org.onap.aai.exceptions.AAIException; import org.onap.aai.interceptors.AAIContainerFilter; import org.onap.aai.logging.ErrorLogHelper; +import org.springframework.http.HttpStatus; @Priority(AAIResponseFilterPriority.INVALID_RESPONSE_STATUS) public class InvalidResponseStatus extends AAIContainerFilter implements ContainerResponseFilter { @@ -41,9 +42,9 @@ public class InvalidResponseStatus extends AAIContainerFilter implements Contain public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { - if (responseContext.getStatus() == 405) { + if (responseContext.getStatus() == HttpStatus.METHOD_NOT_ALLOWED.value()) { - responseContext.setStatus(400); + responseContext.setStatus(HttpStatus.BAD_REQUEST.value()); AAIException e = new AAIException("AAI_3012"); ArrayList templateVars = new ArrayList<>(); diff --git a/aai-resources/src/main/java/org/onap/aai/interceptors/pre/RequestTransactionLogging.java b/aai-resources/src/main/java/org/onap/aai/interceptors/pre/RequestTransactionLogging.java index 14c1f01..2d0dcdc 100644 --- a/aai-resources/src/main/java/org/onap/aai/interceptors/pre/RequestTransactionLogging.java +++ b/aai-resources/src/main/java/org/onap/aai/interceptors/pre/RequestTransactionLogging.java @@ -91,7 +91,7 @@ public class RequestTransactionLogging extends AAIContainerFilter implements Con requestContext.getHeaders().putSingle(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } - if (WILDCARD.equals(acceptType) || StringUtils.isEmpty(acceptType) || acceptType.contains(TEXT_PLAIN)) { + if (WILDCARD.equals(acceptType) || acceptType.isEmpty() || !StringUtils.hasLength(acceptType) || acceptType.contains(TEXT_PLAIN)) { UriInfo uriInfo = requestContext.getUriInfo(); if (uriInfo != null) { MultivaluedMap queryParameters = uriInfo.getQueryParameters(); diff --git a/aai-resources/src/main/java/org/onap/aai/rest/LegacyMoxyConsumer.java b/aai-resources/src/main/java/org/onap/aai/rest/LegacyMoxyConsumer.java index 5208726..c685071 100644 --- a/aai-resources/src/main/java/org/onap/aai/rest/LegacyMoxyConsumer.java +++ b/aai-resources/src/main/java/org/onap/aai/rest/LegacyMoxyConsumer.java @@ -21,7 +21,6 @@ package org.onap.aai.rest; import io.micrometer.core.annotation.Timed; -import io.swagger.jaxrs.PATCH; import java.io.UnsupportedEncodingException; import java.net.URI; diff --git a/aai-resources/src/main/resources/application.properties b/aai-resources/src/main/resources/application.properties index 3905dd8..66a8e53 100644 --- a/aai-resources/src/main/resources/application.properties +++ b/aai-resources/src/main/resources/application.properties @@ -20,9 +20,9 @@ spring.jersey.application-path=${schema.uri.base.path} spring.profiles.active=production,one-way-ssl,dmaap #The max number of active threads in this pool -jetty.threadPool.maxThreads=200 +server.jetty.threads.max=200 #The minimum number of threads always kept alive -jetty.threadPool.minThreads=8 +server.jetty.threads.min=8 #The number of milliseconds before an idle thread shutsdown, unless the number of active threads are less or equal to minSpareThreads server.tomcat.max-idle-time=60000 diff --git a/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java b/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java index 357ea41..8cc28fc 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java @@ -27,7 +27,6 @@ import com.jayway.jsonpath.JsonPath; import java.io.UnsupportedEncodingException; import java.util.Arrays; -import java.util.Base64; import java.util.Collections; import java.util.UUID; @@ -72,28 +71,29 @@ public class ConfigurationTest extends AbstractSpringRestTest { @Value("${local.management.port}") private int mgtPort; - private HttpEntity httpEntity; + private HttpEntity httpEntityGet; private HttpEntity httpEntityPut; private HttpEntity httpEntityPatch; private String baseUrl; private String actuatorurl; - private HttpHeaders headers; + private HttpHeaders headersGet; + private HttpHeaders headersPutPatch; @Before public void setup() throws UnsupportedEncodingException { - headers = new HttpHeaders(); + headersGet = new HttpHeaders(); + headersGet.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headersGet.add("Real-Time", "true"); + headersGet.add("X-FromAppId", "JUNIT"); + headersGet.add("X-TransactionId", "JUNIT"); - headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); - headers.setContentType(MediaType.APPLICATION_JSON); - headers.add("Real-Time", "true"); - headers.add("X-FromAppId", "JUNIT"); - headers.add("X-TransactionId", "JUNIT"); + headersGet.setBasicAuth("AAI","AAI"); - String authorization = Base64.getEncoder().encodeToString("AAI:AAI".getBytes("UTF-8")); - headers.add("Authorization", "Basic " + authorization); - - httpEntity = new HttpEntity(headers); + headersPutPatch = new HttpHeaders(); + headersPutPatch.putAll(headersGet); + headersPutPatch.setContentType(MediaType.APPLICATION_JSON); + httpEntityGet = new HttpEntity(headersGet); baseUrl = "http://localhost:" + randomPort; actuatorurl = "http://localhost:" + mgtPort; } @@ -105,7 +105,7 @@ public class ConfigurationTest extends AbstractSpringRestTest { ResponseEntity responseEntity = null; - responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.GET, httpEntity, String.class); + responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.GET, httpEntityGet, String.class); assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); // String putBody = " configuration-id, configuration-type configuration-sub-type"; @@ -113,31 +113,31 @@ public class ConfigurationTest extends AbstractSpringRestTest { + "\"configuration-sub-type\": \"subtype1\", " + "\"operational-status\": \"example1\", " + "\"orchestration-status\": \"example1\", " + "\"configuration-selflink\": \"example1\", " + "\"model-customization-id\": \"example1\" " + "}"; - httpEntityPut = new HttpEntity(putBody, headers); + httpEntityPut = new HttpEntity(putBody, headersPutPatch); responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntityPut, String.class); assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode()); String vertexId = responseEntity.getHeaders().getFirst("vertex-id"); responseEntity = restTemplate.exchange(baseUrl + "/aai/v12/resources/id/" + vertexId, HttpMethod.GET, - httpEntity, String.class); + httpEntityGet, String.class); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); - responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.GET, httpEntity, String.class); + responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.GET, httpEntityGet, String.class); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); String patchBody = "{" + "\"configuration-id\": \"" + cid + "\"," + "\"configuration-type\": \"type2\"," + "\"configuration-sub-type\": \"subtype2\", " + "\"operational-status\": \"example1\", " + "\"orchestration-status\": \"example1\", " + "\"configuration-selflink\": \"example1\", " + "\"model-customization-id\": \"example1\" " + "}"; - headers.put("Content-Type", Arrays.asList("application/merge-patch+json")); - headers.add("X-HTTP-Method-Override", "PATCH"); + headersPutPatch.put("Content-Type", Arrays.asList("application/merge-patch+json")); + headersPutPatch.add("X-HTTP-Method-Override", "PATCH"); - httpEntityPatch = new HttpEntity(patchBody, headers); + httpEntityPatch = new HttpEntity(patchBody, headersPutPatch); responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.POST, httpEntityPatch, String.class); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); - responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.GET, httpEntity, String.class); + responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.GET, httpEntityGet, String.class); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); String body = responseEntity.getBody().toString(); @@ -148,11 +148,11 @@ public class ConfigurationTest extends AbstractSpringRestTest { patchBody = "{" + "\"configuration-id\": \"" + cid + "\"," + "\"configuration-type\": \"type3\"," + "\"configuration-sub-type\": \"subtype3\" " + "}"; - httpEntityPatch = new HttpEntity(patchBody, headers); + httpEntityPatch = new HttpEntity(patchBody, headersPutPatch); responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PATCH, httpEntityPatch, String.class); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); - responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.GET, httpEntity, String.class); + responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.GET, httpEntityGet, String.class); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); body = responseEntity.getBody().toString(); @@ -163,15 +163,16 @@ public class ConfigurationTest extends AbstractSpringRestTest { } @Test - public void TestManagementEndpointConfiguration() { + public void testManagementEndpointConfiguration() { ResponseEntity responseEntity = null; String responseBody = null; // set Accept as text/plain in order to get access of endpoint "/actuator/prometheus" - headers.set("Accept", "text/plain"); - httpEntity = new HttpEntity(headers); + headersGet.set("Accept", "text/plain"); + headersGet.setAccept(Arrays.asList(MediaType.TEXT_PLAIN)); + httpEntityGet = new HttpEntity(headersGet); responseEntity = - restTemplate.exchange(actuatorurl + "/actuator/prometheus", HttpMethod.GET, httpEntity, String.class); + restTemplate.exchange(actuatorurl + "/actuator/prometheus", HttpMethod.GET, httpEntityGet, String.class); responseBody = (String) responseEntity.getBody(); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertTrue(responseBody.contains("group_id")); @@ -179,16 +180,16 @@ public class ConfigurationTest extends AbstractSpringRestTest { // Set Accept as MediaType.APPLICATION_JSON in order to get access of endpoint "/actuator/info" and // "/actuator/health" - headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); - httpEntity = new HttpEntity(headers); + headersGet.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + httpEntityGet = new HttpEntity(headersGet); responseEntity = - restTemplate.exchange(actuatorurl + "/actuator/info", HttpMethod.GET, httpEntity, String.class); + restTemplate.exchange(actuatorurl + "/actuator/info", HttpMethod.GET, httpEntityGet, String.class); responseBody = (String) responseEntity.getBody(); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertTrue(responseBody.contains("aai-resources")); responseEntity = - restTemplate.exchange(actuatorurl + "/actuator/health", HttpMethod.GET, httpEntity, String.class); + restTemplate.exchange(actuatorurl + "/actuator/health", HttpMethod.GET, httpEntityGet, String.class); responseBody = (String) responseEntity.getBody(); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertTrue(responseBody.contains("UP")); diff --git a/aai-resources/src/test/java/org/onap/aai/rest/ExceptionHandlerTest.java b/aai-resources/src/test/java/org/onap/aai/rest/ExceptionHandlerTest.java index a804ee5..27f702f 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/ExceptionHandlerTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/ExceptionHandlerTest.java @@ -65,7 +65,7 @@ public class ExceptionHandlerTest extends AAISetup { @Before public void setup() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); MultivaluedHashMap headersMultiMap = new MultivaluedHashMap<>(); diff --git a/aai-resources/src/test/resources/application-test.properties b/aai-resources/src/test/resources/application-test.properties index 4c2b8d0..21e4ca7 100644 --- a/aai-resources/src/test/resources/application-test.properties +++ b/aai-resources/src/test/resources/application-test.properties @@ -20,9 +20,9 @@ spring.autoconfigure.exclude=\ spring.profiles.active=production #The max number of active threads in this pool -server.tomcat.max-threads=200 +server.tomcat.threads.max=200 #The minimum number of threads always kept alive -server.tomcat.min-Spare-Threads=25 +server.tomcat.threads.min-spare=25 #The number of milliseconds before an idle thread shutsdown, unless the number of active threads are less or equal to minSpareThreads server.tomcat.max-idle-time=60000 -- cgit 1.2.3-korg