@@ -75,6 +75,7 @@ public final T get(long id) {
75
75
76
76
final var url = this .config .getUrl () + API_PREFIX + this .getUrlPath () + "/" + id ;
77
77
log .debug ("Requesting URL: {}" , url );
78
+
78
79
try {
79
80
ResponseEntity <T > response = restTemplate .exchange (
80
81
url ,
@@ -85,8 +86,8 @@ public final T get(long id) {
85
86
86
87
return response .getBody ();
87
88
} catch (RestClientException e ) {
88
- log .error ("Exception while getting data : {}" , e .getMessage ());
89
- throw new PersistenceException ("Failed to get data. " , e );
89
+ log .error ("Exception while doing a GET request to DefectDojo API : {}" , e .getMessage ());
90
+ throw new PersistenceException ("Failed to do a GET to DefectDojo API! " , e );
90
91
}
91
92
}
92
93
@@ -140,27 +141,53 @@ public final T create(@NonNull T object) {
140
141
var restTemplate = this .getRestTemplate ();
141
142
HttpEntity <T > payload = new HttpEntity <>(object , getDefectDojoAuthorizationHeaders ());
142
143
143
- ResponseEntity <T > response = restTemplate .exchange (this .config .getUrl () + API_PREFIX + getUrlPath () + "/" , HttpMethod .POST , payload , getModelClass ());
144
- return response .getBody ();
144
+ try {
145
+ ResponseEntity <T > response = restTemplate .exchange (
146
+ this .config .getUrl () + API_PREFIX + getUrlPath () + "/" ,
147
+ HttpMethod .POST ,
148
+ payload ,
149
+ getModelClass ());
150
+ return response .getBody ();
151
+ } catch (RestClientException e ) {
152
+ log .error ("Exception while doing a POST request to DefectDojo API: {}" , e .getMessage ());
153
+ throw new PersistenceException ("Failed to do a POST to DefectDojo API!" , e );
154
+ }
145
155
}
146
156
147
157
@ Override
148
158
public final void delete (long id ) {
149
159
var restTemplate = this .getRestTemplate ();
150
160
HttpEntity <String > payload = new HttpEntity <>(getDefectDojoAuthorizationHeaders ());
151
161
152
- restTemplate .exchange (this .config .getUrl () + API_PREFIX + getUrlPath () + "/" + id + "/" , HttpMethod .DELETE , payload , String .class );
162
+ try {
163
+ restTemplate .exchange (
164
+ this .config .getUrl () + API_PREFIX + getUrlPath () + "/" + id + "/" ,
165
+ HttpMethod .DELETE ,
166
+ payload ,
167
+ String .class );
168
+ } catch (RestClientException e ) {
169
+ log .error ("Exception while doing a DELETE request to DefectDojo API: {}" , e .getMessage ());
170
+ throw new PersistenceException ("Failed to do a DELETE to DefectDojo API!" , e );
171
+ }
153
172
}
154
173
155
174
@ Override
156
175
public final T update (@ NonNull T object , long id ) {
157
176
var restTemplate = this .getRestTemplate ();
158
177
HttpEntity <T > payload = new HttpEntity <>(object , getDefectDojoAuthorizationHeaders ());
159
178
160
- ResponseEntity <T > response = restTemplate .exchange (this .config .getUrl () + API_PREFIX + getUrlPath () + "/" + id + "/" , HttpMethod .PUT , payload , getModelClass ());
161
- return response .getBody ();
179
+ try {
180
+ ResponseEntity <T > response = restTemplate .exchange (this .config .getUrl () + API_PREFIX + getUrlPath () + "/" + id + "/" ,
181
+ HttpMethod .PUT ,
182
+ payload ,
183
+ getModelClass ());
184
+ return response .getBody ();
185
+ } catch (RestClientException e ) {
186
+ log .error ("Exception while doing a PUT request to DefectDojo API: {}" , e .getMessage ());
187
+ throw new PersistenceException ("Failed to do a PUT to DefectDojo API!" , e );
188
+ }
162
189
}
163
-
190
+
164
191
/**
165
192
* Get the URL path for the REST endpoint relative to {@link #API_PREFIX}
166
193
*
@@ -222,13 +249,18 @@ protected PaginatedResult<T> internalSearch(Map<String, Object> queryParams, lon
222
249
log .debug ("Requesting URL: {}" , url );
223
250
var uriBuilder = UriComponentsBuilder .fromUri (url ).queryParams (multiValueMap );
224
251
225
- ResponseEntity <String > responseString = restTemplate .exchange (
226
- uriBuilder .build (mutableQueryParams ),
227
- HttpMethod .GET ,
228
- payload ,
229
- String .class
230
- );
252
+ try {
253
+ ResponseEntity <String > responseString = restTemplate .exchange (
254
+ uriBuilder .build (mutableQueryParams ),
255
+ HttpMethod .GET ,
256
+ payload ,
257
+ String .class
258
+ );
231
259
232
- return deserializeList (responseString .getBody ());
260
+ return deserializeList (responseString .getBody ());
261
+ } catch (RestClientException e ) {
262
+ log .error ("Exception while doing a GET request to DefectDojo API: {}" , e .getMessage ());
263
+ throw new PersistenceException ("Failed to do a GET to DefectDojo API!" , e );
264
+ }
233
265
}
234
266
}
0 commit comments