diff --git a/gxspringboot/src/main/java/com/genexus/springboot/GXConfig.java b/gxspringboot/src/main/java/com/genexus/springboot/GXConfig.java index 912a1bc28..ae148c82a 100644 --- a/gxspringboot/src/main/java/com/genexus/springboot/GXConfig.java +++ b/gxspringboot/src/main/java/com/genexus/springboot/GXConfig.java @@ -6,11 +6,17 @@ import com.genexus.diagnostics.core.LogManager; import com.genexus.servlet.CorsFilter; import com.genexus.xml.GXXMLSerializable; + import jakarta.annotation.PreDestroy; +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.servlet.ServletContainer; +import org.glassfish.jersey.servlet.ServletProperties; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.servlet.ServletContextInitializer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.Ordered; import org.springframework.core.io.ClassPathResource; import org.springframework.util.AntPathMatcher; import org.springframework.web.servlet.config.annotation.EnableWebMvc; @@ -19,6 +25,10 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.tuckey.web.filters.urlrewrite.UrlRewriteFilter; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + @Configuration @EnableWebMvc public class GXConfig implements WebMvcConfigurer { @@ -82,6 +92,32 @@ public FilterRegistrationBean urlRewriteFilter() { return registrationBean; } + @Bean + public ServletContextInitializer jerseyFilter() { + Set> rrcs = JaxrsResourcesHolder.getAll(); + + if (rrcs.isEmpty()) { + return sc -> {}; + } + + ResourceConfig rc = new ResourceConfig(); + rc.registerClasses(rrcs.toArray(new Class[0])); + rc.property(ServletProperties.FILTER_FORWARD_ON_404, true); + + ServletContainer container = new ServletContainer(rc); + + FilterRegistrationBean reg = new FilterRegistrationBean<>(container); + reg.addUrlPatterns("/rest/*"); + reg.setName("jersey-filter"); + reg.setOrder(Ordered.HIGHEST_PRECEDENCE + 1); + + Map initParams = new HashMap<>(); + initParams.put(ServletProperties.FILTER_CONTEXT_PATH, "/rest"); + reg.setInitParameters(initParams); + + return reg; + } + @PreDestroy public void onDestroy() { GXXMLSerializable.classesCacheMethods.clear(); diff --git a/gxspringboot/src/main/java/com/genexus/springboot/GXImportSelector.java b/gxspringboot/src/main/java/com/genexus/springboot/GXImportSelector.java index db7a7f7c6..7d83e4de6 100644 --- a/gxspringboot/src/main/java/com/genexus/springboot/GXImportSelector.java +++ b/gxspringboot/src/main/java/com/genexus/springboot/GXImportSelector.java @@ -7,6 +7,8 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; import org.springframework.context.annotation.ImportSelector; import org.springframework.core.io.ClassPathResource; @@ -20,26 +22,28 @@ public class GXImportSelector implements ImportSelector { @Override public String[] selectImports(AnnotationMetadata importingClassMetadata) { ArrayList restImports = new ArrayList<>(); + Set> rrcs = new HashSet>(); try { Resource[] resources = new PathMatchingResourcePatternResolver().getResources("classpath*:*.services"); for (Resource resource : resources) { - selectImport(restImports, resource.getFilename()); + selectImport(rrcs, restImports, resource.getFilename()); } } catch (IOException e){ logger.error("Error loading External Services classes ", e); } + JaxrsResourcesHolder.setAll(rrcs); addWebSocketsImport(restImports); return restImports.toArray(new String[0]); } - private void selectImport(ArrayList restImports, String servicesClassesFileName) { + private void selectImport(Set> rrcs, ArrayList restImports, String servicesClassesFileName) { try { InputStream is = new ClassPathResource(servicesClassesFileName).getInputStream(); if (is != null) { - WebUtils.AddExternalServicesFile(null, restImports, is); + WebUtils.AddExternalServicesFile(rrcs, restImports, is); is.close(); } diff --git a/gxspringboot/src/main/java/com/genexus/springboot/JaxrsResourcesHolder.java b/gxspringboot/src/main/java/com/genexus/springboot/JaxrsResourcesHolder.java new file mode 100644 index 000000000..fe6e139c7 --- /dev/null +++ b/gxspringboot/src/main/java/com/genexus/springboot/JaxrsResourcesHolder.java @@ -0,0 +1,19 @@ +package com.genexus.springboot; + +import java.util.LinkedHashSet; +import java.util.Set; + +public final class JaxrsResourcesHolder { + private static final Set> RESOURCES = new LinkedHashSet<>(); + private JaxrsResourcesHolder() {} + + public static void setAll(Set> rrcs) { + RESOURCES.clear(); + if (rrcs != null) RESOURCES.addAll(rrcs); + } + + public static Set> getAll() { + return new LinkedHashSet<>(RESOURCES); + } +} + diff --git a/java/src/main/java/com/genexus/webpanels/WebUtils.java b/java/src/main/java/com/genexus/webpanels/WebUtils.java index 04b332bc0..99c491c3e 100644 --- a/java/src/main/java/com/genexus/webpanels/WebUtils.java +++ b/java/src/main/java/com/genexus/webpanels/WebUtils.java @@ -523,7 +523,7 @@ public static void AddExternalServicesFile(Set> rrcs, ArrayList if (serviceClass != null) if (rrcs != null) rrcs.add(serviceClass); - else + if (restImports != null) restImports.add(serviceClass.getName()); } reader.close();