1
2
3
4
5
6
7
8
9
10
11 package psiprobe.controllers.threads;
12
13 import jakarta.servlet.http.HttpServletRequest;
14 import jakarta.servlet.http.HttpServletResponse;
15
16 import java.net.URLClassLoader;
17 import java.util.Arrays;
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
32
33 @Controller
34 public class GetClassLoaderUrlsController extends ParameterizableViewController {
35
36
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 }