diff --git a/common/src/main/java/com/genexus/util/GXFileInfo.java b/common/src/main/java/com/genexus/util/GXFileInfo.java index 439ec4908..7b5e2e2a1 100644 --- a/common/src/main/java/com/genexus/util/GXFileInfo.java +++ b/common/src/main/java/com/genexus/util/GXFileInfo.java @@ -15,12 +15,15 @@ public class GXFileInfo implements IGXFileInfo { private File fileSource; + private ClassPathResource resource; private boolean isDirectory; public GXFileInfo(File file){ this(file, false); } public GXFileInfo(File file, boolean isDirectory){ + if (ApplicationContext.getInstance().isSpringBootApp() && ! file.exists() && !file.getPath().equals("")) + resource = new ClassPathResource(file.getPath()); fileSource = file; this.isDirectory = isDirectory; } @@ -36,8 +39,8 @@ public String getPath(){ } } public boolean exists(){ - if (ApplicationContext.getInstance().isSpringBootApp() && !isDirectory) { - if (!fileSource.exists() && !new ClassPathResource(fileSource.getPath()).exists()) + if (resource != null && !isDirectory) { + if (!fileSource.exists() && !resource.exists()) return false; return true; } @@ -48,6 +51,8 @@ public boolean exists(){ return false; } public boolean isFile(){ + if (resource != null) + return true; return fileSource.isFile(); } public boolean isDirectory(){ @@ -88,6 +93,13 @@ public String getAbsolutePath(){ return fileSource.getAbsolutePath(); } public long length(){ + if (resource != null && !fileSource.exists()) + try { + return resource.contentLength(); + } + catch (IOException _) { + return 0; + } return fileSource.length(); } public Date lastModified(){ @@ -139,8 +151,8 @@ public GXDirectoryCollection listDirectories(){ public InputStream getStream(){ try { - if (ApplicationContext.getInstance().isSpringBootApp()) { - return new ClassPathResource(fileSource.getPath()).getInputStream(); + if (resource != null && !fileSource.exists()) { + return resource.getInputStream(); } return new FileInputStream(fileSource); diff --git a/gxspringboot/src/main/java/com/genexus/springboot/GXConfig.java b/gxspringboot/src/main/java/com/genexus/springboot/GXConfig.java index 02fc89f74..40b4566e3 100644 --- a/gxspringboot/src/main/java/com/genexus/springboot/GXConfig.java +++ b/gxspringboot/src/main/java/com/genexus/springboot/GXConfig.java @@ -1,14 +1,21 @@ package com.genexus.springboot; +import com.genexus.Application; +import com.genexus.common.interfaces.SpecificImplementation; +import com.genexus.diagnostics.core.ILogger; +import com.genexus.diagnostics.core.LogManager; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.util.AntPathMatcher; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; @Configuration @EnableWebMvc public class GXConfig implements WebMvcConfigurer { + public static final ILogger logger = LogManager.getLogger(GXConfig.class); @Override public void configurePathMatch(PathMatchConfigurer configurer) { @@ -16,4 +23,26 @@ public void configurePathMatch(PathMatchConfigurer configurer) { matcher.setCaseSensitive(false); configurer.setPathMatcher(matcher); } + + @Value("${server.servlet.context-parameters.gxcfg}") + private String gxConfig; + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + try { + Application.init(Class.forName(gxConfig)); + + String webImageDir = Application.getClientContext().getClientPreferences().getWEB_IMAGE_DIR(); + String blobPath = SpecificImplementation.Application.getDefaultPreferences().getBLOB_PATH().replace("\\", ""); + + registry.addResourceHandler(webImageDir + "**") + .addResourceLocations("classpath:" + webImageDir); + + registry.addResourceHandler("/" + blobPath + "/**") + .addResourceLocations("file:./" + blobPath + "/"); + } + catch (ClassNotFoundException e) { + logger.error("Error setting context folders ", e); + } + } } diff --git a/java/src/main/java/com/genexus/db/driver/GXPreparedStatement.java b/java/src/main/java/com/genexus/db/driver/GXPreparedStatement.java index 50f46d9bd..4bd757dba 100644 --- a/java/src/main/java/com/genexus/db/driver/GXPreparedStatement.java +++ b/java/src/main/java/com/genexus/db/driver/GXPreparedStatement.java @@ -9,9 +9,6 @@ import java.io.InputStreamReader; import java.io.Reader; import java.io.UnsupportedEncodingException; -import java.io.Writer; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.math.BigDecimal; import java.net.MalformedURLException; @@ -1414,7 +1411,13 @@ public void setBLOBFile(int index, String fileName, boolean isMultiMedia) throws if(webContext != null) { if (webContext instanceof com.genexus.webpanels.HttpContextWeb) { - fileName = ((com.genexus.webpanels.HttpContextWeb) webContext).getRealPath(fileName); + if (ApplicationContext.getInstance().isSpringBootApp() && ! new File(fileName).isAbsolute()) + { + if (fileName.startsWith(webContext.getContextPath())) + fileName = fileName.replaceFirst(webContext.getContextPath(), "").substring(1); + } + else + fileName = ((com.genexus.webpanels.HttpContextWeb) webContext).getRealPath(fileName); } else { @@ -1452,16 +1455,17 @@ else if(blobFiles.length < index) { if (Application.getExternalProvider() == null) { - try + GXFile file = new GXFile(fileName); + InputStream is = file.getStream(); + if (is != null) { - File file = new File(fileName); - BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file)); - setBinaryStream(index, inputStream, (int) file.length()); + BufferedInputStream inputStream = new BufferedInputStream(is); + setBinaryStream(index, inputStream, (int) file.getLength()); } - catch (IOException e) + else { throw new SQLException("The filename does not exists in url " + fileName); - } + } } else { diff --git a/java/src/main/java/com/genexus/webpanels/HttpContextWeb.java b/java/src/main/java/com/genexus/webpanels/HttpContextWeb.java index 981f09c83..d54081c8c 100644 --- a/java/src/main/java/com/genexus/webpanels/HttpContextWeb.java +++ b/java/src/main/java/com/genexus/webpanels/HttpContextWeb.java @@ -143,7 +143,7 @@ public String getResourceRelative(String path, boolean includeBasePath) { } ; String Resource = path; - String basePath = getDefaultPath(); + String basePath = getDefaultPath(true); if (Resource.startsWith(basePath) && Resource.length() >= basePath.length()) Resource = Resource.substring(basePath.length()); if (ContextPath != null && !ContextPath.equals("") && Resource.startsWith(ContextPath)) @@ -516,6 +516,9 @@ public String getContextPath() { public void setContextPath(String path) {} public String getRealPath(String path) { + if (ApplicationContext.getInstance().isSpringBootApp()) + return path; + String realPath = path; File file = new File(path); @@ -1255,8 +1258,15 @@ private boolean useCustomRedirect() { } public String getDefaultPath() { - if (ApplicationContext.getInstance().isSpringBootApp()) - return ""; + return getDefaultPath(false); + } + public String getDefaultPath(boolean useAbsolutePath) { + if (ApplicationContext.getInstance().isSpringBootApp()) { + if (useAbsolutePath) + return new File("").getAbsolutePath(); + else + return ""; + } if (servletContext == null) return "";