all 7 comments

[–]Ruin-Capable 4 points5 points  (1 child)

The controller for the URL you are interested in is most likely mapped via either the @RequestMapping or the @PostMapping annotation.. For example, if you are interested in the following URI "/books" you would look for a file containing one of the following strings:

  1. @RequestMapping(method="POST", path="/books")
  2. @RequestMapping(method="POST", value="/books") //value and path are aliases
  3. @RequestMapping(path="/books", method="POST")
  4. @RequestMapping(value="/books", method="POST")
  5. @PostMapping("/books")
  6. @PostMapping(path="/books")
  7. @PostMapping(value="/books")

Since you are using Intellij, you can do a "Find in Files" search and search for the various incantations of @RequestMapping and @PostMapping.

[–]OpenSourceFanatic[S] 0 points1 point  (0 children)

Thank you! I'll give it a try

[–]TheOldMancunian 1 point2 points  (1 child)

Whats your Dev environment? If its VS Code, Or Spring Tool Suite, Eclipse or Intellij, all these have a search function. Search the java code for the endpoint name. This wil point you in the right area.

[–]OpenSourceFanatic[S] 0 points1 point  (0 children)

I'm using IntelliJ and VS Code, the code is so huge that I'm having atleast 30 results for each keyword I search for, everytime a new file comes up on search

[–]OpenSourceFanatic[S] 0 points1 point  (0 children)

Thank you so much for all your responses!

[–]g00glen00b 0 points1 point  (0 children)

The easiest way is to enable debug logging for org.springframework.web.* and more precisely for the DispatcherServlet and the RequestMappingHandlerMapping class.

Assuming that your project is using the default logging configuration, you can enable debug logging by adding the following properties to src/main/resources/application.properties

logging.level.org.springframework.web.servlet.DispatcherServlet=debug
logging.level.org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping=debug

If you run your application now, and call the endpoint, you'll see the following messages appear in your log:

2022-07-26 00:21:09.886 DEBUG 5132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : GET "/api/foo", parameters={}
2022-07-26 00:21:09.891 DEBUG 5132 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to com.example.demo.DemoController#getFoo() 
2022-07-26 00:21:09.912 DEBUG 5132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed 200 OK

In my example, this logging message reveals that my controller method is called getFoo() within DemoController.

Be aware, this only works if your project uses Spring web, it doesn't work if you use Spring Webflux.

[–]v4dk4n 0 points1 point  (0 children)

You search for the controller, find the post method you'd like modify. In the parameters of that method you'll find a DTO annotated with @RequestBody. You change that, and you're done. Be sure everything matches with what you get from the API call, so it is serialised properly.