From 420608db94b645024c0fc9238f6df9692f915ae6 Mon Sep 17 00:00:00 2001 From: iroqueta Date: Tue, 26 Mar 2024 18:06:05 -0300 Subject: [PATCH] Native web service support was added to Spring Boot Platform issue: 105554 --- gxspringboot/pom.xml | 15 ++++--- .../GXServletContextInitializer.java | 11 +++++ .../jaxws/GXWSServletContextListener.java | 42 +++++++++++++++++++ 3 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 gxspringboot/src/main/java/com/genexus/springboot/jaxws/GXWSServletContextListener.java diff --git a/gxspringboot/pom.xml b/gxspringboot/pom.xml index 10c756fd6..45b761371 100644 --- a/gxspringboot/pom.xml +++ b/gxspringboot/pom.xml @@ -14,11 +14,16 @@ GeneXus Spring Boot - - ${project.groupId} - gxclassR - ${project.version} - + + ${project.groupId} + gxclassR + ${project.version} + + + ${project.groupId} + gxwrapperjakarta + ${project.version} + jakarta.servlet jakarta.servlet-api diff --git a/gxspringboot/src/main/java/com/genexus/springboot/GXServletContextInitializer.java b/gxspringboot/src/main/java/com/genexus/springboot/GXServletContextInitializer.java index 96a6e9d4e..01704a727 100644 --- a/gxspringboot/src/main/java/com/genexus/springboot/GXServletContextInitializer.java +++ b/gxspringboot/src/main/java/com/genexus/springboot/GXServletContextInitializer.java @@ -28,6 +28,17 @@ public void onStartup(ServletContext container) { ServletRegistration.Dynamic dispatcherQuery3 = container.addServlet("gxqueryviewerforsd", (Servlet) Class.forName("qviewer.services.gxqueryviewerforsd").getConstructor().newInstance()); dispatcherQuery3.addMapping("/qviewer.services.gxqueryviewerforsd"); } + + try { + Class wsServlet = Class.forName("com.sun.xml.ws.transport.http.servlet.WSServlet"); + ServletRegistration.Dynamic dispatcherQuery3 = container.addServlet("JaxWSServlet", (Servlet) wsServlet.getConstructor().newInstance()); + dispatcherQuery3.setLoadOnStartup(1); + dispatcherQuery3.addMapping("/servlet/ws/*"); + dispatcherQuery3.addMapping("/ws/*"); + } + catch (ClassNotFoundException e) { + log.info("Declare servlet mapping for com.sun.xml.ws.transport.http.servlet.WSServlet is not necessary"); + } } catch(Exception e) { log.error("Error executing ServletContextInitializer", e); diff --git a/gxspringboot/src/main/java/com/genexus/springboot/jaxws/GXWSServletContextListener.java b/gxspringboot/src/main/java/com/genexus/springboot/jaxws/GXWSServletContextListener.java new file mode 100644 index 000000000..630df5100 --- /dev/null +++ b/gxspringboot/src/main/java/com/genexus/springboot/jaxws/GXWSServletContextListener.java @@ -0,0 +1,42 @@ +package com.genexus.springboot.jaxws; + +import jakarta.servlet.*; +import jakarta.servlet.annotation.WebListener; +import org.apache.commons.io.FileUtils; +import org.apache.logging.log4j.Logger; +import org.springframework.core.io.ClassPathResource; +import java.io.IOException; + +@WebListener +public class GXWSServletContextListener implements ServletContextListener { + private static Logger log = org.apache.logging.log4j.LogManager.getLogger(GXWSServletContextListener.class); + private com.sun.xml.ws.transport.http.servlet.WSServletContextListener listener = null; + + public static final String JAXWS_METADATA_FILE = "sun-jaxws.xml"; + public static final String JAXWS_METADATA_PATH = "WEB-INF/sun-jaxws.xml"; + + public GXWSServletContextListener() { + if (new ClassPathResource(JAXWS_METADATA_FILE).exists()) + this.listener = new com.sun.xml.ws.transport.http.servlet.WSServletContextListener(); + } + + @Override + public void contextInitialized(ServletContextEvent sce) { + if (listener != null) { + try { + FileUtils.copyInputStreamToFile(new ClassPathResource(JAXWS_METADATA_FILE).getInputStream(), + new java.io.File(sce.getServletContext().getRealPath("") + JAXWS_METADATA_PATH)); + } catch (IOException e) { + log.error(String.format("File %s not found", JAXWS_METADATA_FILE), e); + } + + listener.contextInitialized(sce); + } + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + if (listener != null) + listener.contextDestroyed(sce); + } +}