How to find which method is called when going to route?

423 Views Asked by At

I am getting too many redirects error I and want to find in which method this happens. The url I am going is

https://localhost:8443/OpenELIS-Global/

I tried searching codebase for OpenELIS-Global but I could not find something related with routes.

Also searched for @GetMapping - also nothing with OpenELIS-Global.

How do I find which method is called when going to that route?

In symfony can simply use

php bin/console debug:router

It is unbelievable if there is no similar command for spring.

Update

Base on the answer: spring version 5, as I understand MVC because there are controller files, log framework - I see there is log4j-1.2.8.jar

Update

The application I am working on looks like is forked from https://github.com/I-TECH-UW/OpenELIS-Global-2 . Just last commit being used is from 2021 if I remember well.

Update

Based on Jordi answer I added logging configs. It shows for most routes but for one route - https://localhost:8443/OpenELIS-Global/ which was giving problems (ketp redirecting to itself) and I did not know where to debug it - it still does not show:

enter image description here

When going to https://localhost:8443/OpenELIS-Global url, there are redirects

as you can see there were 3 requess but only login and home routes shown in log:

openelisglobal-webapp | 26 Apr 2022 17:31:55 -- TRACE -- Mapped to org.openelisglobal.login.controller.LoginPageController#showLoginPage(HttpServletRequest, Principal)
openelisglobal-webapp | 26 Apr 2022 17:31:55 -- TRACE -- Mapped to org.openelisglobal.login.controller.LoginPageController#showLoginPage(HttpServletRequest, Principal)
openelisglobal-webapp | 26 Apr 2022 17:31:55 -- TRACE -- Mapped to org.openelisglobal.home.controller.HomeController#showPanelManagement(HttpServletRequest)
openelisglobal-webapp | 26 Apr 2022 17:31:55 -- TRACE -- Mapped to org.openelisglobal.home.controller.HomeController#showPanelManagement(HttpServletRequest)

With another guy I discussed - it was somehow complicated done - the root route compressed in .war file.

src/main/resources/log4j2.properties:

loggers=rolling,routes
    logger.routes.name=org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
    logger.routes.level = trace
    logger.routes.appenderRefs = file, console
    logger.routes.appenderRef.file.ref = RollingFile
    logger.routes.appenderRef.console.ref = STDOUT

Update

Added

logging.level.org.springframework.web=debug

to src/main/resources/application.properties

from Antoniossss answer. Intellij shows that it is unused property.

And it shows logs from Jordi config as I understand

openelisglobal-webapp | 26 Apr 2022 21:56:15 -- TRACE -- Mapped to org.openelisglobal.login.controller.LoginPageController#showLoginPage(HttpServletRequest, Principal)
openelisglobal-webapp | 26 Apr 2022 21:56:15 -- TRACE -- Mapped to org.openelisglobal.login.controller.LoginPageController#showLoginPage(HttpServletRequest, Principal)
openelisglobal-webapp | 26 Apr 2022 21:56:15 -- TRACE -- Mapped to org.openelisglobal.login.controller.LoginPageController#showLoginPage(HttpServletRequest, Principal)
openelisglobal-webapp | 26 Apr 2022 21:56:15 -- TRACE -- Mapped to org.openelisglobal.login.controller.LoginPageController#showLoginPage(HttpServletRequest, Principal)
openelisglobal-webapp | 26 Apr 2022 21:56:15 -- TRACE -- Mapped to org.openelisglobal.login.controller.LoginPageController#showLoginPage(HttpServletRequest, Principal)
openelisglobal-webapp | 26 Apr 2022 21:56:15 -- TRACE -- Mapped to org.openelisglobal.login.controller.LoginPageController#showLoginPage(HttpServletRequest, Principal)
2

There are 2 best solutions below

3
On

By one hand, there is some additional information that could be useful in order to provide a more concrete answer: Spring Version (5 ?), assuming Spring MVC, and also the log framework that you are using.

By other hand, there are mainly two approaches to analyse routes further than what you can deduce directly looking into your code:

  • Activate a log level detailed enough that shows information on the URL mappings.
  • Debug the application in your IDE with the help of Spring source code; going to some specific Spring MVC classes and methods. As your url refers to localhost, I assume you will be able to do that.

Both approaches are detailed here: How to debug Spring MVC url mapping?

It is an old post with some recent updates in which two most voted answers provide details on the commented approaches.

Added info

According to the additional info provided, it seems clear you are using log4j2. It is a mavenized project, the maven pom.xml config file contains a log4j2 specific version config (2.17.1). Also, in src/main/resources you can find a log4j2.properties config file.

You can configure there a specific logger, similar to the following config (it has not been tested):

loggers=rolling,routes

logger.routes.name=org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
logger.routes.level = trace
logger.routes.appenderRefs = file, console
logger.routes.appenderRef.file.ref = RollingFile
logger.routes.appenderRef.console.ref = STDOUT

You can add also a more generic one for org.springframework.web to debug level.

This will probably help, as stated in the referenced post.

0
On

I would simply turn on loggin with (application.properties)

logging.level.org.springframework.web=debug

this will disclose some information about existing mappiongs and which handler methods are picked upt to serve incoming requests as well as used response handlers.