21
21
import com .fasterxml .jackson .core .JsonProcessingException ;
22
22
import com .fasterxml .jackson .databind .DeserializationFeature ;
23
23
import com .fasterxml .jackson .databind .ObjectMapper ;
24
+ import com .fasterxml .jackson .databind .cfg .CoercionAction ;
25
+ import com .fasterxml .jackson .databind .cfg .CoercionInputShape ;
24
26
import io .securecodebox .persistence .defectdojo .config .DefectDojoConfig ;
25
27
import io .securecodebox .persistence .defectdojo .exceptions .DefectDojoLoopException ;
26
28
import io .securecodebox .persistence .defectdojo .models .DefectDojoModel ;
27
29
import io .securecodebox .persistence .defectdojo .models .DefectDojoResponse ;
30
+ import io .securecodebox .persistence .defectdojo .models .Engagement ;
28
31
import org .apache .http .HttpHost ;
29
32
import org .apache .http .auth .AuthScope ;
30
33
import org .apache .http .auth .UsernamePasswordCredentials ;
38
41
import org .springframework .http .HttpMethod ;
39
42
import org .springframework .http .ResponseEntity ;
40
43
import org .springframework .http .client .HttpComponentsClientHttpRequestFactory ;
44
+ import org .springframework .http .converter .FormHttpMessageConverter ;
45
+ import org .springframework .http .converter .ResourceHttpMessageConverter ;
46
+ import org .springframework .http .converter .StringHttpMessageConverter ;
47
+ import org .springframework .http .converter .json .MappingJackson2HttpMessageConverter ;
41
48
import org .springframework .util .LinkedMultiValueMap ;
42
49
import org .springframework .web .client .RestTemplate ;
43
50
import org .springframework .web .util .UriComponentsBuilder ;
@@ -58,10 +65,12 @@ public GenericDefectDojoService(DefectDojoConfig config) {
58
65
59
66
this .objectMapper = new ObjectMapper ();
60
67
this .objectMapper .configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false );
68
+ this .objectMapper .coercionConfigFor (Engagement .Status .class ).setCoercion (CoercionInputShape .EmptyString , CoercionAction .AsNull );
61
69
this .objectMapper .findAndRegisterModules ();
62
70
63
71
this .searchStringMapper = new ObjectMapper ();
64
72
this .searchStringMapper .configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false );
73
+ this .searchStringMapper .coercionConfigFor (Engagement .Status .class ).setCoercion (CoercionInputShape .EmptyString , CoercionAction .AsNull );
65
74
this .searchStringMapper .setSerializationInclusion (JsonInclude .Include .NON_DEFAULT );
66
75
}
67
76
@@ -87,6 +96,8 @@ private HttpHeaders getDefectDojoAuthorizationHeaders() {
87
96
}
88
97
89
98
protected RestTemplate getRestTemplate () {
99
+ RestTemplate restTemplate ;
100
+
90
101
if (System .getProperty ("http.proxyUser" ) != null && System .getProperty ("http.proxyPassword" ) != null ) {
91
102
// Configuring Proxy Authentication explicitly as it isn't done by default for spring rest templates :(
92
103
CredentialsProvider credsProvider = new BasicCredentialsProvider ();
@@ -105,10 +116,20 @@ protected RestTemplate getRestTemplate() {
105
116
106
117
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory ();
107
118
factory .setHttpClient (client );
108
- return new RestTemplate (factory );
119
+ restTemplate = new RestTemplate (factory );
109
120
} else {
110
- return new RestTemplate ();
121
+ restTemplate = new RestTemplate ();
111
122
}
123
+
124
+ MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter ();
125
+ converter .setObjectMapper (this .objectMapper );
126
+ restTemplate .setMessageConverters (List .of (
127
+ new FormHttpMessageConverter (),
128
+ new ResourceHttpMessageConverter (),
129
+ new StringHttpMessageConverter (),
130
+ converter
131
+ ));
132
+ return restTemplate ;
112
133
}
113
134
114
135
protected abstract String getUrlPath ();
0 commit comments