Home > database >  Run two Spring endpoints at the same time
Run two Spring endpoints at the same time

Time:01-19

I have a Controller class with two endpoints:

@GetMapping("/refresh")
public String refresh() {
// does something
}

 @GetMapping("/watch")
    public String watch() {
    // does something
}

When I call the endpoint /watch I want to call the /refresh endpoint before (more precise I only make one call to the endpoint /watch but /refresh gets called before)

I tried to instantiate it like this:

 @GetMapping("/watch")
public String watch() {
refresh();
// does something
}

but it did not work has anyone an idea what I am doing wrong?

CodePudding user response:

Generally I would advise to just not doing that but if you must you can do something like this:

URL url = new URL("http://example.com/refresh");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");

Tho as Gurkirat has correctly pointed out in the comments, you should not do this and instead call the business logic of /refresh in /watch

  •  Tags:  
  • Related