Skip to content

Commit 5c7d9cb

Browse files
authored
Native web service support was added to Spring Boot Platform (#844)
issue: 105554
1 parent cc12943 commit 5c7d9cb

File tree

3 files changed

+63
-5
lines changed

3 files changed

+63
-5
lines changed

gxspringboot/pom.xml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@
1414
<name>GeneXus Spring Boot</name>
1515

1616
<dependencies>
17-
<dependency>
18-
<groupId>${project.groupId}</groupId>
19-
<artifactId>gxclassR</artifactId>
20-
<version>${project.version}</version>
21-
</dependency>
17+
<dependency>
18+
<groupId>${project.groupId}</groupId>
19+
<artifactId>gxclassR</artifactId>
20+
<version>${project.version}</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>${project.groupId}</groupId>
24+
<artifactId>gxwrapperjakarta</artifactId>
25+
<version>${project.version}</version>
26+
</dependency>
2227
<dependency>
2328
<groupId>jakarta.servlet</groupId>
2429
<artifactId>jakarta.servlet-api</artifactId>

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ public void onStartup(ServletContext container) {
2828
ServletRegistration.Dynamic dispatcherQuery3 = container.addServlet("gxqueryviewerforsd", (Servlet) Class.forName("qviewer.services.gxqueryviewerforsd").getConstructor().newInstance());
2929
dispatcherQuery3.addMapping("/qviewer.services.gxqueryviewerforsd");
3030
}
31+
32+
try {
33+
Class<?> wsServlet = Class.forName("com.sun.xml.ws.transport.http.servlet.WSServlet");
34+
ServletRegistration.Dynamic dispatcherQuery3 = container.addServlet("JaxWSServlet", (Servlet) wsServlet.getConstructor().newInstance());
35+
dispatcherQuery3.setLoadOnStartup(1);
36+
dispatcherQuery3.addMapping("/servlet/ws/*");
37+
dispatcherQuery3.addMapping("/ws/*");
38+
}
39+
catch (ClassNotFoundException e) {
40+
log.info("Declare servlet mapping for com.sun.xml.ws.transport.http.servlet.WSServlet is not necessary");
41+
}
3142
}
3243
catch(Exception e) {
3344
log.error("Error executing ServletContextInitializer", e);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.genexus.springboot.jaxws;
2+
3+
import jakarta.servlet.*;
4+
import jakarta.servlet.annotation.WebListener;
5+
import org.apache.commons.io.FileUtils;
6+
import org.apache.logging.log4j.Logger;
7+
import org.springframework.core.io.ClassPathResource;
8+
import java.io.IOException;
9+
10+
@WebListener
11+
public class GXWSServletContextListener implements ServletContextListener {
12+
private static Logger log = org.apache.logging.log4j.LogManager.getLogger(GXWSServletContextListener.class);
13+
private com.sun.xml.ws.transport.http.servlet.WSServletContextListener listener = null;
14+
15+
public static final String JAXWS_METADATA_FILE = "sun-jaxws.xml";
16+
public static final String JAXWS_METADATA_PATH = "WEB-INF/sun-jaxws.xml";
17+
18+
public GXWSServletContextListener() {
19+
if (new ClassPathResource(JAXWS_METADATA_FILE).exists())
20+
this.listener = new com.sun.xml.ws.transport.http.servlet.WSServletContextListener();
21+
}
22+
23+
@Override
24+
public void contextInitialized(ServletContextEvent sce) {
25+
if (listener != null) {
26+
try {
27+
FileUtils.copyInputStreamToFile(new ClassPathResource(JAXWS_METADATA_FILE).getInputStream(),
28+
new java.io.File(sce.getServletContext().getRealPath("") + JAXWS_METADATA_PATH));
29+
} catch (IOException e) {
30+
log.error(String.format("File %s not found", JAXWS_METADATA_FILE), e);
31+
}
32+
33+
listener.contextInitialized(sce);
34+
}
35+
}
36+
37+
@Override
38+
public void contextDestroyed(ServletContextEvent sce) {
39+
if (listener != null)
40+
listener.contextDestroyed(sce);
41+
}
42+
}

0 commit comments

Comments
 (0)