1
votes

I'm new to springframework (and annotations in general) and need help finding documentation. There are a few things that I'm struggling with.

The specific question I have is what are the annotations/methods/parameters available to the method below and more specifically, how do I get the full url string that was used to get to this method?

This is what the class looks like:

import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.utils.URIBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
...

@CrossOrigin
@RestController
@Slf4j
public class MyController {


    /**
     * 
     * Method mapped to /mymethod
     * 
     */
    @GetMapping("/mymethod")
    public ResponseEntity<AuthRedirect> mymethod(
            @RequestParam("param1") String param1,
            @RequestParam("param2") String param2,
            @RequestParam("param3") String param3,
            @RequestParam("param4") String param4) {
        System.out.println("I was called by" + ???HOW-DO-I-GET-THIS???);
        ...

Is this Spring Boot? Spring MVC? Something else?

If I google around I get to sites like this but they don't seem to tell me what are the parameters available in this method and how do I get the raw url that was used to call this method?

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/GetMapping.html

https://www.baeldung.com/spring-requestmapping

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/

https://docs.spring.io/spring-boot/docs/current/reference/html/

1
You might find it useful link1 link2 link3 link4 - ajayg2808

1 Answers

2
votes

In order to get the full url you can add HttpServletRequest request as parameter in mymethod and then compose the url as follows:

  @GetMapping("/mymethod")
  public String mymethod(
      @RequestParam("param1") String param1,
      @RequestParam("param2") String param2,
      @RequestParam("param3") String param3,
      @RequestParam("param4") String param4,
      HttpServletRequest request) {
    System.out.println(String.format("%s?%s", request.getRequestURL(), request.getQueryString()));
...

The annotations are from Spring.