Improve request/response holder implementation (#1790)
Make use of RequestContextHolder which provides access to request / response out of the box Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -46,9 +46,6 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi
|
||||
@Autowired
|
||||
private ArtifactManagement artifactManagement;
|
||||
|
||||
@Autowired
|
||||
private RequestResponseContextHolder requestResponseContextHolder;
|
||||
|
||||
/**
|
||||
* Handles the GET request for downloading an artifact.
|
||||
*
|
||||
@@ -74,14 +71,13 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi
|
||||
final DbArtifact file = artifactManagement
|
||||
.loadArtifactBinary(artifact.getSha1Hash(), module.getId(), module.isEncrypted())
|
||||
.orElseThrow(() -> new ArtifactBinaryNotFoundException(artifact.getSha1Hash()));
|
||||
final HttpServletRequest request = requestResponseContextHolder.getHttpServletRequest();
|
||||
final HttpServletRequest request = RequestResponseContextHolder.getHttpServletRequest();
|
||||
final String ifMatch = request.getHeader(HttpHeaders.IF_MATCH);
|
||||
if (ifMatch != null && !HttpUtil.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) {
|
||||
return new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED);
|
||||
}
|
||||
|
||||
return FileStreamingUtil.writeFileResponse(file, artifact.getFilename(), artifact.getCreatedAt(),
|
||||
requestResponseContextHolder.getHttpServletResponse(), request, null);
|
||||
RequestResponseContextHolder.getHttpServletResponse(), request, null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -39,13 +39,9 @@ public class MgmtDownloadResource implements MgmtDownloadRestApi {
|
||||
|
||||
private final DownloadIdCache downloadIdCache;
|
||||
|
||||
private final RequestResponseContextHolder requestResponseContextHolder;
|
||||
|
||||
MgmtDownloadResource(final ArtifactRepository artifactRepository, final DownloadIdCache downloadIdCache,
|
||||
final RequestResponseContextHolder requestResponseContextHolder) {
|
||||
MgmtDownloadResource(final ArtifactRepository artifactRepository, final DownloadIdCache downloadIdCache) {
|
||||
this.artifactRepository = artifactRepository;
|
||||
this.downloadIdCache = downloadIdCache;
|
||||
this.requestResponseContextHolder = requestResponseContextHolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,8 +73,8 @@ public class MgmtDownloadResource implements MgmtDownloadRestApi {
|
||||
}
|
||||
|
||||
return FileStreamingUtil.writeFileResponse(artifact, downloadId, 0L,
|
||||
requestResponseContextHolder.getHttpServletResponse(),
|
||||
requestResponseContextHolder.getHttpServletRequest(), null);
|
||||
RequestResponseContextHolder.getHttpServletResponse(),
|
||||
RequestResponseContextHolder.getHttpServletRequest(), null);
|
||||
|
||||
} finally {
|
||||
downloadIdCache.evict(downloadId);
|
||||
|
||||
Reference in New Issue
Block a user