|
| 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