From 634651ef8646b68d34ce16be3b816956db1e4a9c Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Tue, 18 Jun 2024 09:19:27 +0200 Subject: [PATCH] feature(refactoring):xxx fixed commit id on docker hub image. --- .../common/config/PolicyStartUpConfig.java | 1 + .../RequestResponseLoggingInterceptor.java | 70 ------------------- .../config/RestTemplateConfiguration.java | 16 +---- 3 files changed, 3 insertions(+), 84 deletions(-) delete mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/RequestResponseLoggingInterceptor.java diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/PolicyStartUpConfig.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/PolicyStartUpConfig.java index b945569866..67aff58f74 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/PolicyStartUpConfig.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/PolicyStartUpConfig.java @@ -75,6 +75,7 @@ public class PolicyStartUpConfig { public void registerDecentralRegistryPermissions() throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JavaTimeModule()); + mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); List acceptedPolicy = buildAcceptedPolicies(); defaultAcceptedPoliciesProvider.addAcceptedPolicies(acceptedPolicy); log.info("Successfully added permission to irs client lib provider: {}", mapper.writeValueAsString(acceptedPolicy)); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/RequestResponseLoggingInterceptor.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/RequestResponseLoggingInterceptor.java deleted file mode 100644 index f6e51b1123..0000000000 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/RequestResponseLoggingInterceptor.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - - -package org.eclipse.tractusx.traceability.common.config; - - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.jetbrains.annotations.NotNull; -import org.springframework.http.HttpRequest; -import org.springframework.http.client.ClientHttpRequestExecution; -import org.springframework.http.client.ClientHttpRequestInterceptor; -import org.springframework.http.client.ClientHttpResponse; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.stream.Collectors; - - -@RequiredArgsConstructor -@Slf4j -public class RequestResponseLoggingInterceptor implements ClientHttpRequestInterceptor { - - - @Override - @NotNull - public ClientHttpResponse intercept(final HttpRequest request, final byte[] body, - final ClientHttpRequestExecution execution) throws IOException { - ClientHttpResponse response = execution.execute(request, body); - InputStreamReader isr = null; - BufferedReader br = null; - try { - String requestBody = new String(body, StandardCharsets.UTF_8); - log.info("Request body: {}", requestBody.replaceAll("[\r\n]+", " ")); - isr = new InputStreamReader( - response.getBody(), StandardCharsets.UTF_8); - br = new BufferedReader(isr); - String bodys = br.lines() - .collect(Collectors.joining("\n")); - log.info("Response body: {}", bodys.replaceAll("[\r\n]+", " ")); - return response; - } finally { - if (isr != null) - isr.close(); - - if (br != null) - br.close(); - } - } - -} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/RestTemplateConfiguration.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/RestTemplateConfiguration.java index bfbc620adc..32b316b61e 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/RestTemplateConfiguration.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/RestTemplateConfiguration.java @@ -103,7 +103,6 @@ public RestTemplate edcRestTemplate(@Autowired EdcProperties edcProperties) { .rootUri(edcProperties.getProviderEdcUrl()) .defaultHeader(EDC_API_KEY_HEADER_NAME, edcProperties.getApiAuthKey()) .setConnectTimeout(Duration.ofSeconds(10L)) - // .additionalInterceptors(new RequestResponseLoggingInterceptor()) .setReadTimeout(Duration.ofSeconds(25L)) .build(); } @@ -116,7 +115,6 @@ public RestTemplate edcDtrAssetRestTemplate(@Autowired EdcProperties edcProperti .defaultHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) .defaultHeader(EDC_API_KEY_HEADER_NAME, edcProperties.getApiAuthKey()) .setConnectTimeout(Duration.ofSeconds(10L)) - // .additionalInterceptors(new RequestResponseLoggingInterceptor()) .setReadTimeout(Duration.ofSeconds(25L)) .build(); } @@ -132,7 +130,6 @@ public RestTemplate digitalTwinRegistryCreateShellRestTemplate() { public RestTemplate edcNotificationTemplate(@Autowired EdcProperties edcProperties) { return new RestTemplateBuilder() .defaultHeader(EDC_API_KEY_HEADER_NAME, edcProperties.getApiAuthKey()) - // .additionalInterceptors(new RequestResponseLoggingInterceptor()) .build(); } @@ -183,17 +180,8 @@ public RestTemplate digitalTwinRegistryRestTemplate( /* RestTemplate used by the edc client library*/ @Bean(EDC_CLIENT_REST_TEMPLATE) public RestTemplate edcClientRestTemplate() { - ClientHttpRequestFactory factory = new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()); - RestTemplate restTemplate = new RestTemplate(factory); - - List interceptors = restTemplate.getInterceptors(); - if (CollectionUtils.isEmpty(interceptors)) { - interceptors = new ArrayList<>(); - } - // interceptors.add(new RequestResponseLoggingInterceptor()); - restTemplate.setErrorHandler(new DefaultResponseErrorHandler()); - // restTemplate.setInterceptors(interceptors); - return restTemplate; + return new RestTemplateBuilder() + .build(); } private RestTemplateBuilder oAuthRestTemplate(final RestTemplateBuilder restTemplateBuilder,