From e36dcc866563aefaca7edff0f894860f3f27a31b Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Wed, 12 Sep 2018 16:44:44 -0400 Subject: Fix threading problems in requestdbclient Disable Flakey tests, that do not run well Resolve bean conflict, move to common project Fix port in properties file for replacement Fix threading problems in requestdbclient Change-Id: I12d145863152d302da4fa0854db1c85286266e02 Issue-ID: SO-1034 Signed-off-by: Benjamin, Max (mb388a) --- .../so/db/request/client/RequestsDbClient.java | 43 ++++++++++++---------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'mso-api-handlers/mso-requests-db/src') diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java index 2a61a319f3..5eb2addc0a 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java @@ -33,15 +33,19 @@ import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus; import org.onap.so.db.request.beans.WatchdogDistributionStatus; import org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup; import org.onap.so.db.request.data.controller.InstanceNameDuplicateCheckRequest; +import org.onap.so.logging.jaxrs.filter.SpringClientFilter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Primary; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpRequest; +import org.springframework.http.client.BufferingClientHttpRequestFactory; import org.springframework.http.client.ClientHttpRequestExecution; +import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.ClientHttpRequestInterceptor; import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; @@ -116,8 +120,8 @@ public class RequestsDbClient { private String findBySoRequestIdOrderByGroupingIdDesc = "/requestProcessingData/search/findBySoRequestIdOrderByGroupingIdDesc/"; - protected HttpHeaders headers; + @Autowired protected RestTemplate restTemplate; @Autowired @@ -135,26 +139,19 @@ public class RequestsDbClient { operationalEnvDistributionStatusURI = endpoint + operationalEnvDistributionStatusURI; findOneByOperationalEnvIdAndServiceModelVersionIdURI = endpoint + OPERATIONAL_ENV_SERVICE_MODEL_STATUS_SEARCH + findOneByOperationalEnvIdAndServiceModelVersionIdURI; findAllByOperationalEnvIdAndRequestIdURI = endpoint + OPERATIONAL_ENV_SERVICE_MODEL_STATUS_SEARCH + findAllByOperationalEnvIdAndRequestIdURI; - headers = new HttpHeaders(); - headers.set("Authorization", msoAdaptersAuth); - restTemplate = restTemplate(); } public RequestsDbClient() { - ClientFactory clientFactory = Configuration.builder().setRestTemplateConfigurer(new RestTemplateConfigurer() { - - public void configure(RestTemplate restTemplate) { + ClientHttpRequestFactory factory = new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory()); - restTemplate.getInterceptors().add(new ClientHttpRequestInterceptor() { + ClientFactory clientFactory = Configuration.builder().setClientHttpRequestFactory(factory).setRestTemplateConfigurer(restTemplate -> { + restTemplate.getInterceptors().add((new SpringClientFilter())); - public ClientHttpResponse intercept(HttpRequest request, byte[] body, - ClientHttpRequestExecution execution) throws IOException { + restTemplate.getInterceptors().add((request, body, execution) -> { - request.getHeaders().add("Authorization", msoAdaptersAuth); - return execution.execute(request, body); - } - }); - } + request.getHeaders().add(HttpHeaders.AUTHORIZATION, msoAdaptersAuth); + return execution.execute(request, body); + }); }).build().buildClientFactory(); infraActiveRequestClient = clientFactory.create(InfraActiveRequests.class); requestProcessingDataClient = clientFactory.create(RequestProcessingData.class); @@ -164,6 +161,8 @@ public class RequestsDbClient { public List getCloudOrchestrationFiltersFromInfraActive(Map orchestrationMap){ URI uri = getUri(cloudOrchestrationFiltersFromInfraActive); + HttpHeaders headers = new HttpHeaders(); + headers.set("Authorization", msoAdaptersAuth); HttpEntity entity = new HttpEntity<>(orchestrationMap, headers); try{ return restTemplate.exchange(uri, HttpMethod.POST, entity, new ParameterizedTypeReference>() {}).getBody(); @@ -191,6 +190,8 @@ public class RequestsDbClient { } public List getOrchestrationFiltersFromInfraActive(Map> orchestrationMap) { + HttpHeaders headers = new HttpHeaders(); + headers.set("Authorization", msoAdaptersAuth); URI uri = getUri(getOrchestrationFilterURI); HttpEntity>> entity = new HttpEntity<>(orchestrationMap, headers); return restTemplate.exchange(uri, HttpMethod.POST, entity, new ParameterizedTypeReference>() {}).getBody(); @@ -201,6 +202,8 @@ public class RequestsDbClient { return restTemplate.exchange(uri, HttpMethod.GET, HttpEntity.EMPTY, InfraActiveRequests.class).getBody(); } public InfraActiveRequests checkInstanceNameDuplicate(HashMap instanceIdMap, String instanceName, String requestScope) { + HttpHeaders headers = new HttpHeaders(); + headers.set("Authorization", msoAdaptersAuth); URI uri = getUri(checkInstanceNameDuplicate); HttpEntity entity = new HttpEntity<>(new InstanceNameDuplicateCheckRequest(instanceIdMap, instanceName, requestScope), headers); try{ @@ -265,12 +268,16 @@ public class RequestsDbClient { } public void save(InfraActiveRequests infraActiveRequests) { + HttpHeaders headers = new HttpHeaders(); + headers.set("Authorization", msoAdaptersAuth); URI uri = getUri(infraActiveRequestURI); HttpEntity entity = new HttpEntity<>(infraActiveRequests, headers); restTemplate.postForLocation(uri, entity); } public void save(T object){ + HttpHeaders headers = new HttpHeaders(); + headers.set("Authorization", msoAdaptersAuth); URI uri = getUri(endpoint+classURLMapper.getURI(object.getClass())); HttpEntity entity = new HttpEntity<>(object, headers); restTemplate.postForLocation(uri, entity); @@ -289,6 +296,8 @@ public class RequestsDbClient { } public void saveRequestProcessingData(RequestProcessingData requestProcessingData) { + HttpHeaders headers = new HttpHeaders(); + headers.set("Authorization", msoAdaptersAuth); URI uri = getUri(endpoint + requestProcessingDataURI); HttpEntity entity = new HttpEntity<>(requestProcessingData, headers); restTemplate.postForLocation(uri, entity); @@ -330,10 +339,6 @@ public class RequestsDbClient { return requestProcessingDataClient.getAll(uri); } - public RestTemplate restTemplate() { - return new RestTemplate( new HttpComponentsClientHttpRequestFactory()); - } - @Component static class ClassURLMapper { private static final Map classURLMap = new HashMap<>(); -- cgit 1.2.3-korg