diff --git a/common/src/main/java/com/genexus/IHttpContext.java b/common/src/main/java/com/genexus/IHttpContext.java index 97d3ddf36..e6fc5904c 100644 --- a/common/src/main/java/com/genexus/IHttpContext.java +++ b/common/src/main/java/com/genexus/IHttpContext.java @@ -63,5 +63,5 @@ public interface IHttpContext { boolean isHttpContextNull(); boolean isHttpContextWeb(); - + String getContextPath(); } diff --git a/java/src/main/java/com/genexus/GxImageUtil.java b/java/src/main/java/com/genexus/GxImageUtil.java index 297171ed8..73a23c39a 100644 --- a/java/src/main/java/com/genexus/GxImageUtil.java +++ b/java/src/main/java/com/genexus/GxImageUtil.java @@ -6,6 +6,7 @@ import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; import java.io.*; +import java.net.URL; import com.genexus.db.driver.ResourceAccessControlList; import com.genexus.util.GxFileInfoSourceType; @@ -22,13 +23,19 @@ private static InputStream getInputStream(String filePathOrUrl) throws IOExcepti private static BufferedImage createBufferedImageFromURI(String filePathOrUrl) throws IOException { - try (InputStream is = getGXFile(filePathOrUrl).getStream()) { + IHttpContext httpContext = com.genexus.ModelContext.getModelContext().getHttpContext(); + InputStream is = null; + try{ + if (filePathOrUrl.toLowerCase().startsWith("http://") || filePathOrUrl.toLowerCase().startsWith("https://") || + (httpContext.isHttpContextWeb() && filePathOrUrl.startsWith(httpContext.getContextPath()))) + is = new URL(GXDbFile.pathToUrl( filePathOrUrl, httpContext)).openStream(); + else + is = getGXFile(filePathOrUrl).getStream(); return ImageIO.read(is); - } - catch (IOException e) { + } catch (IOException e) { log.error("Failed to read image stream: " + filePathOrUrl); throw e; - } + } finally {is.close();} } private static GXFile getGXFile(String filePathOrUrl) {