Mercurial > hg > orthanc-imagej
changeset 8:1411a4ecd113
Fix issue #9 ("ImageJ - Error while importing this image: null")
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 15 Apr 2016 10:45:09 +0200 (2016-04-15) |
parents | 91734f507be7 |
children | d69b7a6d408e |
files | NEWS com/orthancserver/OrthancConnection.java com/orthancserver/PreviewPanel.java |
diffstat | 3 files changed, 24 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS Fri Apr 15 09:53:37 2016 +0200 +++ b/NEWS Fri Apr 15 10:45:09 2016 +0200 @@ -1,6 +1,7 @@ Pending changes in the mainline =============================== +* Fix issue #9 ("ImageJ - Error while importing this image: null") Version 1.0.0 (2014/12/08)
--- a/com/orthancserver/OrthancConnection.java Fri Apr 15 09:53:37 2016 +0200 +++ b/com/orthancserver/OrthancConnection.java Fri Apr 15 10:45:09 2016 +0200 @@ -47,30 +47,27 @@ } - private static InputStream OpenUrl(String urlString) throws IOException + private static InputStream OpenUrl(String urlString, + String authentication, + String accept) throws IOException { - URL url = new URL(urlString); + URL url = new URL(urlString); + + URLConnection uc = url.openConnection(); + + if (authentication != null) + { + // http://blogs.deepal.org/2008/01/sending-basic-authentication-using-url.html + uc.setRequestProperty("Authorization", "Basic " + authentication); + } + + if (accept != null) + { + uc.setRequestProperty("Accept", accept); + } try { - return url.openStream(); - } - catch (ConnectException e) - { - throw new IOException(); - } - } - - - private static InputStream OpenUrl(String urlString, - String authentication) throws IOException - { - try - { - URL url = new URL(urlString); - // http://blogs.deepal.org/2008/01/sending-basic-authentication-using-url.html - URLConnection uc = url.openConnection(); - uc.setRequestProperty("Authorization", "Basic " + authentication); return uc.getInputStream(); } catch (ConnectException e) @@ -89,10 +86,11 @@ } - public InputStream OpenStream(String uri) throws IOException + public InputStream OpenStream(String uri, + String acceptHeader) throws IOException { String url = baseUrl_ + uri; - return authentication_ == null ? OpenUrl(url) : OpenUrl(url, authentication_); + return OpenUrl(url, authentication_, acceptHeader); } @@ -121,7 +119,7 @@ public String ReadString(String uri) throws IOException { - InputStream stream = OpenStream(uri); + InputStream stream = OpenStream(uri, null); BufferedReader reader = null; try @@ -170,7 +168,8 @@ public BufferedImage ReadImage(String uri) throws IOException { - return ImageIO.read(OpenStream(uri)); + // Ask the download of "image/png", otherwise an "image/jpeg" is negociated + return ImageIO.read(OpenStream(uri, "image/png")); } public String GetName()
--- a/com/orthancserver/PreviewPanel.java Fri Apr 15 09:53:37 2016 +0200 +++ b/com/orthancserver/PreviewPanel.java Fri Apr 15 10:45:09 2016 +0200 @@ -28,7 +28,6 @@ import java.io.ByteArrayInputStream; import java.util.logging.Level; import java.util.logging.Logger; -import javax.imageio.ImageIO; import javax.swing.JPanel; public class PreviewPanel extends JPanel