user14132461
user14132461

Reputation: 73

Spring Controller Get REST API is called more than once when accessed by user authenticated by 3rd party service

I have a Spring application (say ServiceA) which has only one user who does Admin related actions. ServiceA has it's own UI(Angular). The application also services other users who are authenticated by 3rd party service (say ServiceB). ServiceB has it's own separate UI(Flutter).

When ServiceB wants to access Rest api of ServiceA it sends a jwt access token. ServiceA process this token and if authorized will allow access to the api. JWT token filter is configured for ServiceA

The ServiceA has one Rest api for GET action. When the Admin user of ServiceA access this API, the end point works fine. However when the GET request comes from ServiceB then the API is called thrice. The API output results in json as shown below ....

{ //content }{ //content }{ //content }

Since this is an invalid json format, the 3rd party UI is not able to process the output.

Using Postman for sending requests also shows the same behaviour. Any idea why the api is called more than once?

Temporary Solution:

The signature of the GET Rest Api is as follows....

public ResponseEntity getResult(HttpServletRequest request, HttpServletResponse response, @RequestParam Long id)

I changed the Rest Api to POST as follows (RequestBody used)...

public ResponseEntity getResult(HttpServletRequest request, HttpServletResponse response, @RequestBody TempObj obj)

Now I am the Rest Api is called only once. Still wondering why GET has issues

Upvotes: 0

Views: 119

Answers (1)

user14132461
user14132461

Reputation: 73

Temporary Solution:

The signature of the GET Rest Api is as follows....

public ResponseEntity getResult(HttpServletRequest request, HttpServletResponse response, @RequestParam Long id)

I changed the Rest Api to POST as follows (RequestBody used)...

public ResponseEntity getResult(HttpServletRequest request, HttpServletResponse response, @RequestBody TempObj obj)

Now the Rest Api is called only once.

Still wondering why GET has issues

Upvotes: 0

Related Questions