Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List servlets in a java webapp (running in tomcat)

I am trying to re-package a relatively big java webapp which I did not code and for which the project configuration was lost. I setup a first packaging, and deployed it in tomcat. Now to understand it, I'd like to get a list of the servlets that started successfully or failed, with corresponding access url.

  • Is there a way to get that list (from some startup log maybe)?

Some details: the webapp uses gwt (which I don't master), I use tomcat7 on ubuntu. I am not against a solution using another servlet container, if practical.

like image 854
Juh_ Avatar asked Mar 16 '23 00:03

Juh_


1 Answers

I would write a simple JSP or ServletContextListener to read all the ServletRegistratioins from the servlet context and display them.

So your JSP/ServletContextListener would read the data from

servletContext.getServletRegistrations();

and just display it.

Edit

@WebServlet(urlPatterns = "/mappings")
public class TestServlet extends HttpServlet {

    private static final long serialVersionUID = -7256602549310759826L;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {

        PrintWriter writer = resp.getWriter();

        Map<String, ? extends ServletRegistration> registrations = req
                .getServletContext().getServletRegistrations();

        for (String key : registrations.keySet()) {
            ServletRegistration registration = registrations.get(key);
            writer.write("Name: " + registration.getName());
            writer.write("<br>Mappings:");
            for (String mapping : registration.getMappings()) {
                writer.write(mapping);
            }
        }

        // of course you can write that to log or console also depending on your
        // requirement.
    }

}
like image 57
K139 Avatar answered Mar 31 '23 19:03

K139