Skip to content

Commit 9c00554

Browse files
Discarded unnecessary changes
issue 100577
1 parent f6c26c9 commit 9c00554

File tree

4 files changed

+14
-45
lines changed

4 files changed

+14
-45
lines changed

common/src/main/java/com/genexus/IHttpContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@ public interface IHttpContext {
6363
boolean isHttpContextNull();
6464
boolean isHttpContextWeb();
6565

66-
66+
String getContextPath();
6767
}

java/src/main/java/com/genexus/GxImageUtil.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ private static InputStream getInputStream(String filePathOrUrl) throws IOExcepti
2323

2424
private static BufferedImage createBufferedImageFromURI(String filePathOrUrl) throws IOException
2525
{
26-
if (PrivateUtilities.isValidURL(filePathOrUrl)){
27-
try (InputStream is = new URL(filePathOrUrl).openStream();) {
26+
if (filePathOrUrl.toLowerCase().startsWith("http://") || filePathOrUrl.toLowerCase().startsWith("https://") ||
27+
(com.genexus.ModelContext.getModelContext().getHttpContext().isHttpContextWeb() && filePathOrUrl.startsWith(com.genexus.ModelContext.getModelContext().getHttpContext().getContextPath()))){
28+
try (InputStream is = new URL(GXDbFile.pathToUrl( filePathOrUrl, com.genexus.ModelContext.getModelContext().getHttpContext())).openStream();) {
2829
return ImageIO.read(is);
2930
} catch (IOException | IllegalArgumentException e) {
3031
log.error("Failed to read image stream: " + filePathOrUrl);
@@ -40,13 +41,8 @@ private static BufferedImage createBufferedImageFromURI(String filePathOrUrl) th
4041
}
4142
}
4243

43-
4444
private static GXFile getGXFile(String filePathOrUrl) {
4545
String basePath = (com.genexus.ModelContext.getModelContext() != null) ? com.genexus.ModelContext.getModelContext().getHttpContext().getDefaultPath(): "";
46-
String environmentName = basePath.substring(basePath.lastIndexOf("\\") + 1);
47-
if (filePathOrUrl.substring(1).startsWith(environmentName)) {
48-
filePathOrUrl = filePathOrUrl.substring(environmentName.length() + 2);
49-
}
5046
return new GXFile(basePath, filePathOrUrl, ResourceAccessControlList.Default, GxFileInfoSourceType.Unknown);
5147
}
5248

java/src/main/java/com/genexus/PrivateUtilities.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.io.PushbackInputStream;
1919
import java.lang.reflect.Field;
2020
import java.net.HttpURLConnection;
21-
import java.net.MalformedURLException;
2221
import java.net.URL;
2322
import java.nio.file.InvalidPathException;
2423
import java.nio.file.Paths;
@@ -626,27 +625,6 @@ public static boolean isAbsoluteFilePath(String path) {
626625
}
627626
}
628627

629-
630-
/**
631-
* <pre>
632-
* Checks if a string has valid URL syntax and points to a valid resource on the web.
633-
* Null safe.
634-
* </pre>
635-
*/
636-
public static boolean isValidURL(String urlString) {
637-
try {
638-
URL url = new URL(urlString);
639-
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
640-
connection.setRequestMethod("HEAD");
641-
int responseCode = connection.getResponseCode();
642-
return (responseCode == HttpURLConnection.HTTP_OK);
643-
} catch (MalformedURLException e) {
644-
return false;
645-
} catch (IOException | NullPointerException e) {
646-
return false;
647-
}
648-
}
649-
650628
public static String addLastPathSeparator(String dir)
651629
{
652630
return addLastChar(dir, File.separator);

java/src/main/java/com/genexus/util/GXFile.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public class GXFile extends AbstractGXFile {
3232
private boolean ret;
3333
private boolean isExternal = false;
3434
private String uploadFileId;
35-
35+
3636
public static ICleanupFile CleanUp;
37-
37+
3838
public GXFile() {
3939
}
4040

@@ -51,7 +51,7 @@ public GXFile(String fileName, boolean isPrivate) {
5151
public GXFile(String fileName, ResourceAccessControlList fileAcl) {
5252
this(fileName, fileAcl, GxFileInfoSourceType.Unknown);
5353
}
54-
54+
5555
public GXFile(String fileName, ResourceAccessControlList fileAcl, GxFileInfoSourceType sourceType) {
5656
this("", fileName, fileAcl, sourceType);
5757
}
@@ -87,14 +87,9 @@ public GXFile(String baseDirectoryPath, String fileName, ResourceAccessControlLi
8787
}
8888

8989
private void createFileSourceLocal(String baseDirectoryPath, String fileName) {
90-
if (PrivateUtilities.isValidURL(fileName)){
91-
String absoluteOrRelativePath = Paths.get(baseDirectoryPath, fileName.substring(fileName.lastIndexOf("/") + 1)).toString(); //BaseDirectory could be empty.
92-
FileSource = new GXFileInfo(new File(absoluteOrRelativePath));
93-
} else {
94-
boolean isAbsolutePath = PrivateUtilities.isAbsoluteFilePath(fileName);
95-
String absoluteOrRelativePath = (isAbsolutePath) ? fileName : Paths.get(baseDirectoryPath, fileName).toString(); //BaseDirectory could be empty.
96-
FileSource = new GXFileInfo(new File(absoluteOrRelativePath));
97-
}
90+
boolean isAbsolutePath = PrivateUtilities.isAbsoluteFilePath(fileName);
91+
String absoluteOrRelativePath = (isAbsolutePath)? fileName : Paths.get(baseDirectoryPath, fileName).toString(); //BaseDirectory could be empty.
92+
FileSource = new GXFileInfo(new File(absoluteOrRelativePath));
9893
}
9994

10095
public GXFile(IGXFileInfo fileInfo) {
@@ -126,7 +121,7 @@ public void setFileInfo(IGXFileInfo fileInfo) {
126121

127122
public void setExternal(boolean isExternal) {
128123
this.isExternal = isExternal;
129-
}
124+
}
130125

131126
public void setSource(String FileName) {
132127
boolean isUpload = com.genexus.CommonUtil.isUploadPrefix(FileName);
@@ -187,7 +182,7 @@ public void create() {
187182
public boolean create(InputStream input) {
188183
return create(input, false);
189184
}
190-
185+
191186
public boolean create(InputStream input, boolean overwrite) {
192187
resetErrors();
193188
try {
@@ -466,7 +461,7 @@ public Date getLastModified() {
466461
calendar.set(0, 0, 0);
467462
return calendar.getTime();
468463
}
469-
464+
470465
public InputStream getStream() {
471466
if (sourceSeted()) {
472467
resetErrors();
@@ -587,7 +582,7 @@ public String toBase64() {
587582
public Boolean fromBytes(byte[] data) {
588583
if (FileSource == null) {
589584
return false;
590-
}
585+
}
591586
try {
592587
FileSource.fromBytes(data);
593588
} catch (IOException e) {

0 commit comments

Comments
 (0)