diff --git a/common/src/main/java/com/genexus/URLRouter.java b/common/src/main/java/com/genexus/URLRouter.java
index 6b9d83af0..90541190d 100644
--- a/common/src/main/java/com/genexus/URLRouter.java
+++ b/common/src/main/java/com/genexus/URLRouter.java
@@ -12,6 +12,8 @@
import java.io.*;
import java.util.regex.Pattern;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
public class URLRouter
@@ -120,14 +122,33 @@ private static String convertParmsToQueryString(boolean useNamedParameters, Stri
return queryString;
}
- private static void load()
- {
- String line;
- InputStream is = null;
- String defaultPath = SpecificImplementation.Application.getModelContext().getHttpContext().getDefaultPath();
+ private static void load() {
+ if (com.genexus.ApplicationContext.getInstance().isSpringBootApp())
+ loadRewriteFilesSB();
+ else
+ loadRewriteFiles();
+ }
+
+ private static void loadRewriteFilesSB() {
+ PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
+ try {
+ Resource[] resources = resolver.getResources("./*.rewrite");
+ for (Resource resource : resources) {
+ loadRewriteInputStream(resource.getInputStream());
+ }
+ }
+ catch (IOException e)
+ {
+ logger.error(e.toString(), e);
+ }
+ }
+
+ private static void loadRewriteFiles() {
String appPackage = SpecificImplementation.Application.getClientPreferences().getPACKAGE();
- if (!appPackage.equals(""))
+ if (!appPackage.equals(""))
appPackage = File.separatorChar + appPackage.replace('.', File.separatorChar);
+ InputStream is;
+ String defaultPath = SpecificImplementation.Application.getModelContext().getHttpContext().getDefaultPath();
String classesDirectoryPath = defaultPath + File.separator + "WEB-INF" + File.separatorChar + "classes" + appPackage;
GXDirectory classesDirectory = new GXDirectory(classesDirectoryPath);
GXFileCollection rewriteFiles = classesDirectory.getFiles(".rewrite");
@@ -137,37 +158,39 @@ private static void load()
{
serverRelative = true;
AbstractGXFile rewriteFile = rewriteFiles.item(i);
- try
- {
- is = SpecificImplementation.Messages.getInputStream(rewriteFile.getName());
+ is = SpecificImplementation.Messages.getInputStream(rewriteFile.getName());
- if (is != null)
- {
- try (BufferedReader bufread = new BufferedReader(new InputStreamReader(is, "UTF8"))) {
- line = bufread.readLine();
- while (line != null) {
- parseLine(line);
- line = bufread.readLine();
- }
- }
- }
- }
- catch (UnsupportedEncodingException e)
+ if (is != null)
{
- logger.error(e.toString(), e);
- }
- catch (FileNotFoundException e)
- {
- logger.info("There is no URLRouter file");
- }
- catch (IOException e)
- {
- logger.error(e.toString(), e);
+ loadRewriteInputStream(is);
}
}
}
}
+ private static void loadRewriteInputStream(InputStream is) {
+ String line;
+ try (BufferedReader bufread = new BufferedReader(new InputStreamReader(is, "UTF8"))) {
+ line = bufread.readLine();
+ while (line != null) {
+ parseLine(line);
+ line = bufread.readLine();
+ }
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ logger.error(e.toString(), e);
+ }
+ catch (FileNotFoundException e)
+ {
+ logger.info("There is no URLRouter file");
+ }
+ catch (IOException e)
+ {
+ logger.error(e.toString(), e);
+ }
+ }
+
private static void parseLine(String line)
{
int len = line.length();
diff --git a/gxspringboot/pom.xml b/gxspringboot/pom.xml
index 45b761371..0267fc5cd 100644
--- a/gxspringboot/pom.xml
+++ b/gxspringboot/pom.xml
@@ -35,7 +35,12 @@
spring-boot-starter-web
3.1.2
provided
-
+
+
+ org.tuckey
+ urlrewritefilter
+ 5.1.3
+
diff --git a/gxspringboot/src/main/java/com/genexus/springboot/GXConfig.java b/gxspringboot/src/main/java/com/genexus/springboot/GXConfig.java
index 40b4566e3..83602a855 100644
--- a/gxspringboot/src/main/java/com/genexus/springboot/GXConfig.java
+++ b/gxspringboot/src/main/java/com/genexus/springboot/GXConfig.java
@@ -4,18 +4,23 @@
import com.genexus.common.interfaces.SpecificImplementation;
import com.genexus.diagnostics.core.ILogger;
import com.genexus.diagnostics.core.LogManager;
+import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.ClassPathResource;
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;
+import org.tuckey.web.filters.urlrewrite.UrlRewriteFilter;
@Configuration
@EnableWebMvc
public class GXConfig implements WebMvcConfigurer {
public static final ILogger logger = LogManager.getLogger(GXConfig.class);
+ private static final String REWRITE_FILE = "rewrite.config";
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
@@ -45,4 +50,19 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
logger.error("Error setting context folders ", e);
}
}
+
+ @Bean
+ public FilterRegistrationBean urlRewriteFilter() {
+ FilterRegistrationBean registrationBean = new FilterRegistrationBean<>();
+ registrationBean.setFilter(new UrlRewriteFilter());
+ registrationBean.addUrlPatterns("/*");
+ if (new ClassPathResource(REWRITE_FILE).exists()) {
+ registrationBean.addInitParameter("modRewriteConf", "true");
+ registrationBean.addInitParameter("confPath", REWRITE_FILE);
+ }
+ else {
+ registrationBean.setEnabled(false);
+ }
+ return registrationBean;
+ }
}