Skip to content

Commit

Permalink
Don't crash if device icon response is missing content type header
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Bauer committed Mar 13, 2014
1 parent e3485ab commit 1b60a22
Showing 1 changed file with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,31 @@ public void onRemoteDeviceComplete(@Observes @Phase.Complete RemoteDeviceDiscove

if (responseMsg != null && !responseMsg.getOperation().isFailed()) {

MimeType contentType =
responseMsg.getHeaders().getFirstHeader(UpnpHeader.Type.CONTENT_TYPE, ContentTypeHeader.class).getValue();

if (isUsableImageType(contentType)) {
byte[] imageBody = (byte[]) responseMsg.getBody();
if (imageBody != null) {
ImageIcon imageIcon = new ImageIcon(imageBody);
deviceItem.setIcon(imageIcon);
ContentTypeHeader ctHeader =
responseMsg.getHeaders().getFirstHeader(UpnpHeader.Type.CONTENT_TYPE, ContentTypeHeader.class);

if (ctHeader != null) {
// TODO: We could guess the content type without the header, depending on file extension
MimeType contentType = ctHeader.getValue();

if (isUsableImageType(contentType)) {
byte[] imageBody = (byte[]) responseMsg.getBody();
if (imageBody != null) {
ImageIcon imageIcon = new ImageIcon(imageBody);
deviceItem.setIcon(imageIcon);
} else {
Workbench.Log.MAIN.warning(
"Icon request did not return with response body '" + contentType + "': " + iconRetrievalMsg.getUri()
);
}
} else {
Workbench.Log.MAIN.warning(
"Icon request did not return with response body '" + contentType + "': " + iconRetrievalMsg.getUri()
"Icon was delivered with unsupported content type '" + contentType + "': " + iconRetrievalMsg.getUri()
);
}
} else {
Workbench.Log.MAIN.warning(
"Icon was delivered with unsupported content type '" + contentType + "': " + iconRetrievalMsg.getUri()
"Icon was delivered without content type header in HTTP response': " + iconRetrievalMsg.getUri()
);
}

Expand Down

0 comments on commit 1b60a22

Please sign in to comment.