Skip to content

Commit 78ccb1e

Browse files
WeltraumschafManuelNeuer
authored andcommitted
#36 Move variable creation to place where it is used
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
1 parent f1e9177 commit 78ccb1e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/main/java/io/securecodebox/persistence/defectdojo/service/DefaultImportScanService.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,11 @@ public ImportScanResponse reimportScan(ScanFile scanFile, long testId, long lead
7979
* Before version 1.5.4. testName (in DefectDojo _test_type_) must be defectDojoScanName, afterward, you can have something else.
8080
*/
8181
private ImportScanResponse createFindings(ScanFile scanFile, String endpoint, long lead, String currentDate, ScanType scanType, long testType, MultiValueMap<String, String> options) {
82-
final var restTemplate = this.createRestTemplate();
8382
final var headers = createDefectDojoAuthorizationHeaders();
8483
// We use multipart because we send two "parts" in the request body:
8584
// 1. generic info as key=value&key=value...
8685
// 2. the raw scan result as file
8786
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
88-
restTemplate.setMessageConverters(HTTP_MESSAGE_CONVERTERS);
8987

9088
// FIXME: Why do we use a multi value map here? Do we need multiple values for any given key?
9189
final var body = new LinkedMultiValueMap<String, Object>();
@@ -123,7 +121,14 @@ public String getFilename() {
123121
// FIXME: We do not define the the type T of the body here!
124122
final var payload = new HttpEntity<MultiValueMap<String, Object>>(body, headers);
125123

126-
return restTemplate.exchange(generateApiUrl(endpoint), HttpMethod.POST, payload, ImportScanResponse.class).getBody();
124+
final var restTemplate = this.createRestTemplate();
125+
restTemplate.setMessageConverters(HTTP_MESSAGE_CONVERTERS);
126+
return restTemplate.exchange(
127+
generateApiUrl(endpoint),
128+
HttpMethod.POST,
129+
payload,
130+
ImportScanResponse.class)
131+
.getBody();
127132
} catch (HttpClientErrorException e) {
128133
throw new DefectDojoPersistenceException("Failed to attach findings to engagement.");
129134
}

0 commit comments

Comments
 (0)