View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
10   */
11  package psiprobe.controllers.threads;
12  
13  import java.net.URLClassLoader;
14  import java.util.Arrays;
15  
16  import javax.servlet.http.HttpServletRequest;
17  import javax.servlet.http.HttpServletResponse;
18  
19  import org.slf4j.Logger;
20  import org.slf4j.LoggerFactory;
21  import org.springframework.beans.factory.annotation.Value;
22  import org.springframework.stereotype.Controller;
23  import org.springframework.web.bind.ServletRequestUtils;
24  import org.springframework.web.bind.annotation.RequestMapping;
25  import org.springframework.web.servlet.ModelAndView;
26  import org.springframework.web.servlet.mvc.ParameterizableViewController;
27  
28  import psiprobe.Utils;
29  
30  /**
31   * The Class GetClassLoaderUrlsController.
32   */
33  @Controller
34  public class GetClassLoaderUrlsController extends ParameterizableViewController {
35  
36    /** The Constant logger. */
37    private static final Logger logger = LoggerFactory.getLogger(GetClassLoaderUrlsController.class);
38  
39    @RequestMapping(path = "/cldetails.ajax")
40    @Override
41    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
42        throws Exception {
43      return super.handleRequest(request, response);
44    }
45  
46    @Override
47    protected ModelAndView handleRequestInternal(HttpServletRequest request,
48        HttpServletResponse response) throws Exception {
49  
50      String threadName = ServletRequestUtils.getStringParameter(request, "thread");
51  
52      Thread thread = Utils.getThreadByName(threadName);
53  
54      if (thread != null) {
55        ClassLoader cl = thread.getContextClassLoader();
56        if (cl instanceof URLClassLoader) {
57          try {
58            request.setAttribute("urls", Arrays.asList(((URLClassLoader) cl).getURLs()));
59          } catch (Exception e) {
60            logger.error("There was an exception querying classloader for thread '{}'", threadName,
61                e);
62          }
63        }
64      }
65  
66      return new ModelAndView(getViewName());
67    }
68  
69    @Value("ajax/classLoaderDetails")
70    @Override
71    public void setViewName(String viewName) {
72      super.setViewName(viewName);
73    }
74  
75  }