Skip to content

Commit 403b751

Browse files
authored
OfflineEventReplicator in Spring Boot (#1041)
* OfflineEventReplicator in Spring Boot The mechanism of interpreting the .services of the external REST services was not working for the spring boot case. In particular this causes the OfflineEventReplicator service to not work Issue: 206569 * OfflineEventReplicator in Spring Boot The mechanism of interpreting the .services of the external REST services was not working for the spring boot case. In particular this causes the OfflineEventReplicator service to not work Issue: 206569 * OfflineEventReplicator in Spring Boot The mechanism of interpreting the .services of the external REST services was not working for the spring boot case. In particular this causes the OfflineEventReplicator service to not work Issue: 206569
1 parent 09c8239 commit 403b751

File tree

4 files changed

+63
-4
lines changed

4 files changed

+63
-4
lines changed

gxspringboot/src/main/java/com/genexus/springboot/GXConfig.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@
66
import com.genexus.diagnostics.core.LogManager;
77
import com.genexus.servlet.CorsFilter;
88
import com.genexus.xml.GXXMLSerializable;
9+
910
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;
1014
import org.springframework.boot.web.servlet.FilterRegistrationBean;
1115
import org.springframework.beans.factory.annotation.Value;
16+
import org.springframework.boot.web.servlet.ServletContextInitializer;
1217
import org.springframework.context.annotation.Bean;
1318
import org.springframework.context.annotation.Configuration;
19+
import org.springframework.core.Ordered;
1420
import org.springframework.core.io.ClassPathResource;
1521
import org.springframework.util.AntPathMatcher;
1622
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@@ -19,6 +25,10 @@
1925
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
2026
import org.tuckey.web.filters.urlrewrite.UrlRewriteFilter;
2127

28+
import java.util.HashMap;
29+
import java.util.Map;
30+
import java.util.Set;
31+
2232
@Configuration
2333
@EnableWebMvc
2434
public class GXConfig implements WebMvcConfigurer {
@@ -82,6 +92,32 @@ public FilterRegistrationBean<UrlRewriteFilter> urlRewriteFilter() {
8292
return registrationBean;
8393
}
8494

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+
85121
@PreDestroy
86122
public void onDestroy() {
87123
GXXMLSerializable.classesCacheMethods.clear();

gxspringboot/src/main/java/com/genexus/springboot/GXImportSelector.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import java.io.IOException;
88
import java.io.InputStream;
99
import java.util.ArrayList;
10+
import java.util.HashSet;
11+
import java.util.Set;
1012

1113
import org.springframework.context.annotation.ImportSelector;
1214
import org.springframework.core.io.ClassPathResource;
@@ -20,26 +22,28 @@ public class GXImportSelector implements ImportSelector {
2022
@Override
2123
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
2224
ArrayList<String> restImports = new ArrayList<>();
25+
Set<Class<?>> rrcs = new HashSet<Class<?>>();
2326
try {
2427
Resource[] resources = new PathMatchingResourcePatternResolver().getResources("classpath*:*.services");
2528
for (Resource resource : resources) {
26-
selectImport(restImports, resource.getFilename());
29+
selectImport(rrcs, restImports, resource.getFilename());
2730
}
2831
}
2932
catch (IOException e){
3033
logger.error("Error loading External Services classes ", e);
3134
}
3235

36+
JaxrsResourcesHolder.setAll(rrcs);
3337
addWebSocketsImport(restImports);
3438

3539
return restImports.toArray(new String[0]);
3640
}
3741

38-
private void selectImport(ArrayList<String> restImports, String servicesClassesFileName) {
42+
private void selectImport(Set<Class<?>> rrcs, ArrayList<String> restImports, String servicesClassesFileName) {
3943
try {
4044
InputStream is = new ClassPathResource(servicesClassesFileName).getInputStream();
4145
if (is != null) {
42-
WebUtils.AddExternalServicesFile(null, restImports, is);
46+
WebUtils.AddExternalServicesFile(rrcs, restImports, is);
4347

4448
is.close();
4549
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.genexus.springboot;
2+
3+
import java.util.LinkedHashSet;
4+
import java.util.Set;
5+
6+
public final class JaxrsResourcesHolder {
7+
private static final Set<Class<?>> RESOURCES = new LinkedHashSet<>();
8+
private JaxrsResourcesHolder() {}
9+
10+
public static void setAll(Set<Class<?>> rrcs) {
11+
RESOURCES.clear();
12+
if (rrcs != null) RESOURCES.addAll(rrcs);
13+
}
14+
15+
public static Set<Class<?>> getAll() {
16+
return new LinkedHashSet<>(RESOURCES);
17+
}
18+
}
19+

java/src/main/java/com/genexus/webpanels/WebUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ public static void AddExternalServicesFile(Set<Class<?>> rrcs, ArrayList<String>
523523
if (serviceClass != null)
524524
if (rrcs != null)
525525
rrcs.add(serviceClass);
526-
else
526+
if (restImports != null)
527527
restImports.add(serviceClass.getName());
528528
}
529529
reader.close();

0 commit comments

Comments
 (0)