|
6 | 6 | import com.genexus.diagnostics.core.LogManager; |
7 | 7 | import com.genexus.servlet.CorsFilter; |
8 | 8 | import com.genexus.xml.GXXMLSerializable; |
| 9 | + |
9 | 10 | import jakarta.annotation.PreDestroy; |
| 11 | +import org.glassfish.jersey.server.ResourceConfig; |
| 12 | +import org.glassfish.jersey.servlet.ServletContainer; |
| 13 | +import org.glassfish.jersey.servlet.ServletProperties; |
10 | 14 | import org.springframework.boot.web.servlet.FilterRegistrationBean; |
11 | 15 | import org.springframework.beans.factory.annotation.Value; |
| 16 | +import org.springframework.boot.web.servlet.ServletContextInitializer; |
12 | 17 | import org.springframework.context.annotation.Bean; |
13 | 18 | import org.springframework.context.annotation.Configuration; |
| 19 | +import org.springframework.core.Ordered; |
14 | 20 | import org.springframework.core.io.ClassPathResource; |
15 | 21 | import org.springframework.util.AntPathMatcher; |
16 | 22 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; |
|
19 | 25 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; |
20 | 26 | import org.tuckey.web.filters.urlrewrite.UrlRewriteFilter; |
21 | 27 |
|
| 28 | +import java.util.HashMap; |
| 29 | +import java.util.Map; |
| 30 | +import java.util.Set; |
| 31 | + |
22 | 32 | @Configuration |
23 | 33 | @EnableWebMvc |
24 | 34 | public class GXConfig implements WebMvcConfigurer { |
@@ -82,6 +92,32 @@ public FilterRegistrationBean<UrlRewriteFilter> urlRewriteFilter() { |
82 | 92 | return registrationBean; |
83 | 93 | } |
84 | 94 |
|
| 95 | + @Bean |
| 96 | + public ServletContextInitializer jerseyFilter() { |
| 97 | + Set<Class<?>> rrcs = JaxrsResourcesHolder.getAll(); |
| 98 | + |
| 99 | + if (rrcs.isEmpty()) { |
| 100 | + return sc -> {}; |
| 101 | + } |
| 102 | + |
| 103 | + ResourceConfig rc = new ResourceConfig(); |
| 104 | + rc.registerClasses(rrcs.toArray(new Class<?>[0])); |
| 105 | + rc.property(ServletProperties.FILTER_FORWARD_ON_404, true); |
| 106 | + |
| 107 | + ServletContainer container = new ServletContainer(rc); |
| 108 | + |
| 109 | + FilterRegistrationBean<ServletContainer> reg = new FilterRegistrationBean<>(container); |
| 110 | + reg.addUrlPatterns("/rest/*"); |
| 111 | + reg.setName("jersey-filter"); |
| 112 | + reg.setOrder(Ordered.HIGHEST_PRECEDENCE + 1); |
| 113 | + |
| 114 | + Map<String, String> initParams = new HashMap<>(); |
| 115 | + initParams.put(ServletProperties.FILTER_CONTEXT_PATH, "/rest"); |
| 116 | + reg.setInitParameters(initParams); |
| 117 | + |
| 118 | + return reg; |
| 119 | + } |
| 120 | + |
85 | 121 | @PreDestroy |
86 | 122 | public void onDestroy() { |
87 | 123 | GXXMLSerializable.classesCacheMethods.clear(); |
|
0 commit comments