ffang commented on code in PR #1633:
URL: https://github.com/apache/cxf/pull/1633#discussion_r1452786038


##########
rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java:
##########
@@ -937,25 +1035,81 @@ private ThreadPool getThreadPool() {
      */
     public synchronized void removeServant(URL url) {
 
-        final String contextName = HttpUriMapper.getContextName(url.getPath());
-        final String smap = HttpUriMapper.getResourceBase(url.getPath());
+        String contextName = HttpUriMapper.getContextName(url.getPath());
+        if (contextName.length() == 0) {
+            contextName = "/"; //ensure it is mapped as root context,
+        }
+        String smap = HttpUriMapper.getResourceBase(url.getPath());
+        if (!smap.equals("/")) {
+            //add /* to enable wild match
+            smap = smap + "/*";
+        }
+        
+        if (contextName.endsWith("/*")) {
+            //This is how Jetty ServletContextHandler handle the contextName
+            //without suffix "/", the "*" suffix will be removed
+            contextName = contextName + "/";
+        }
 
         boolean found = false;
 
         if (server != null && server.isRunning()) {
-            for (Handler handler : 
contexts.getChildHandlersByClass(ContextHandler.class)) {
-                if (handler instanceof ContextHandler) {
-                    ContextHandler contextHandler = (ContextHandler) handler;
-                    Handler jh = contextHandler.getHandler();
-                    if (jh instanceof JettyHTTPHandler
+            for (Handler handler : contexts.getHandlers()) {
+                if (handler instanceof ServletContextHandler) {
+                    ServletContextHandler contextHandler = 
(ServletContextHandler) handler;
+                    ServletHandler servletHandler = 
contextHandler.getServletHandler();
+                    
+                    MatchedResource<MappedServlet> mappedServlet = 
servletHandler.getMatchedServlet(smap);
+                    if (mappedServlet == null) {
+                        continue;
+                    }
+                    ServletHolder servletHolder = 
mappedServlet.getResource().getServletHolder();
+                    Servlet servlet = null;
+                    
+                    try {
+                        servlet = servletHolder.getServlet();
+                    } catch (ServletException ex) {
+                        LOG.log(Level.WARNING, "REMOVE_HANDLER_FAILED_MSG", 
new Object[] {
+                                                                               
        ex.getMessage()
+                        });
+                        continue;
+                    }
+                    if (servlet != null && servlet instanceof JettyHTTPHandler
                         && (contextName.equals(contextHandler.getContextPath())
                             || (StringUtils.isEmpty(contextName)
                                 && 
"/".equals(contextHandler.getContextPath())))
-                        && ((JettyHTTPHandler)jh).getName().equals(smap)) {
+                        && 
smap.startsWith(((JettyHTTPHandler)servlet).getName())) {
                         try {
-                            contexts.removeHandler(handler);
-                            handler.stop();
-                            handler.destroy();
+                            servletHolder.stop();
+                            contextHandler.getContext().destroy(servlet);
+                            //need to remove path from 
ServletHandler._servletMappings
+                            //and has to access the private field.
+                            
+                            Field privateField

Review Comment:
   We have to use ReflectionUtil here. A new commit addressed it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@cxf.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to