Use a dependency-injected RestTemplateBuilder to create RestTemplates 17/141517/2
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>
Fri, 11 Jul 2025 10:51:16 +0000 (12:51 +0200)
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>
Sat, 12 Jul 2025 07:33:11 +0000 (09:33 +0200)
- RestTemplate t = new RestTemplate() breaks tracing
- use dependency-injected RestTemplateBuilder to create RestTemplate

Issue-ID: SO-4194
Change-Id: I7fc30acfc07565f2468275062a128108e4c4b8c0
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
common/src/main/java/org/onap/so/client/RestTemplateConfig.java
mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java

index f8587ff..e378a4e 100644 (file)
@@ -7,9 +7,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://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.
@@ -25,6 +25,7 @@ import org.onap.so.configuration.rest.HttpComponentsClientConfiguration;
 import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.web.client.RestTemplateBuilder;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Primary;
@@ -42,8 +43,8 @@ public class RestTemplateConfig {
 
     @Bean
     @Primary
-    public RestTemplate restTemplate() {
-        final RestTemplate restTemplate = new RestTemplate();
+    public RestTemplate restTemplate(RestTemplateBuilder builder) {
+        final RestTemplate restTemplate = builder.build();
         restTemplate
                 .setRequestFactory(new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory()));
         restTemplate.getInterceptors().add(new SOSpringClientFilter());
index cc721d3..c20458d 100644 (file)
@@ -40,6 +40,8 @@ import javax.persistence.TemporalType;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.onap.so.requestsdb.TimestampXMLAdapter;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.deser.std.DateDeserializers.TimestampDeserializer;
 
 @MappedSuperclass
 public abstract class InfraRequests implements java.io.Serializable {
@@ -67,7 +69,9 @@ public abstract class InfraRequests implements java.io.Serializable {
     private Long progress;
 
     @Column(name = "START_TIME")
+    @JsonDeserialize(using = TimestampDeserializer.class)
     private Timestamp startTime;
+    @JsonDeserialize(using = TimestampDeserializer.class)
     @Column(name = "END_TIME")
     private Timestamp endTime;
     @Column(name = "SOURCE", length = 45)