73 public static String fullPath(HttpServletRequest req) { |
73 public static String fullPath(HttpServletRequest req) { |
74 return req.getServletPath() + Optional.ofNullable(req.getPathInfo()).orElse(""); |
74 return req.getServletPath() + Optional.ofNullable(req.getPathInfo()).orElse(""); |
75 } |
75 } |
76 |
76 |
77 /** |
77 /** |
78 * Returns the module path of the given LightPIT Servlet module. |
|
79 * <p> |
|
80 * If you specify a malformed LightPIT servlet, which does not have a module |
|
81 * annotation, the path to the <code>/error/404.html</code> page is returned. |
|
82 * |
|
83 * @param clazz the servlet class |
|
84 * @return the module path |
|
85 */ |
|
86 public static String modulePathOf(Class<? extends AbstractLightPITServlet> clazz) { |
|
87 Optional<LightPITModule> moduleInfo = Optional.ofNullable(clazz.getAnnotation(LightPITModule.class)); |
|
88 if (moduleInfo.isPresent()) { |
|
89 return moduleInfo.get().modulePath(); |
|
90 } else { |
|
91 LOG.warn( |
|
92 "{} is a LightPIT Servlet but is missing the module annotation.", |
|
93 clazz.getName() |
|
94 ); |
|
95 return "/error/404.html"; |
|
96 } |
|
97 } |
|
98 |
|
99 /** |
|
100 * This class is not instantiatable. |
78 * This class is not instantiatable. |
101 */ |
79 */ |
102 private Functions() { |
80 private Functions() { |
103 } |
81 } |
104 } |
82 } |