Skip to content

Commit bc47f7f

Browse files
authored
Merge pull request #3444 from Peyton-Hill-CLS/fix_misisng_attachment_loading
Add explicit check for response code when downloading attachments for http olog.
2 parents 5c65dbf + 7a57690 commit bc47f7f

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

app/logbook/olog/client-es/src/main/java/org/phoebus/olog/es/api/OlogHttpClient.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,10 @@ public InputStream getAttachment(Long logId, String attachmentName) {
469469
.GET()
470470
.build();
471471
HttpResponse<InputStream> response = httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream());
472+
if(response.statusCode() >= 300) {
473+
LOGGER.log(Level.WARNING, "failed to obtain attachment: " + new String(response.body().readAllBytes()));
474+
return null;
475+
}
472476
return response.body();
473477
} catch (Exception e) {
474478
LOGGER.log(Level.WARNING, "failed to obtain attachment", e);

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/AttachmentsViewController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ private void showPreview(Attachment attachment) {
278278
* @param attachment The image {@link Attachment} selected by user.
279279
*/
280280
private void showImagePreview(Attachment attachment) {
281-
if (attachment.getFile() != null) {
281+
if (attachment.getFile() != null && attachment.getFile().exists()) {
282282
// Load image data off UI thread...
283283
JobManager.schedule("Show image attachment", monitor -> {
284284
try {

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/SingleLogEntryDisplayController.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.phoebus.ui.web.HyperLinkRedirectListener;
3434

3535
import java.io.File;
36+
import java.io.InputStream;
3637
import java.nio.file.Files;
3738
import java.nio.file.StandardCopyOption;
3839
import java.text.MessageFormat;
@@ -260,8 +261,11 @@ private void fetchAndSetAttachments() {
260261

261262
File attachmentFile = new File(attachmentsDirectory, attachment.getId() + fileExtension);
262263
if (!attachmentFile.exists()) {
263-
Files.copy(logClient.getAttachment(logEntry.getId(), attachment.getName()), attachmentFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
264-
attachmentFile.deleteOnExit();
264+
InputStream stream = logClient.getAttachment(logEntry.getId(), attachment.getName());
265+
if(stream != null) {
266+
Files.copy(stream, attachmentFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
267+
attachmentFile.deleteOnExit();
268+
}
265269
}
266270
fileAttachment.setFile(attachmentFile);
267271
attachmentList.add(fileAttachment);

0 commit comments

Comments
 (0)