0

I'm in the process of modernizing and transforming a legacy monolith application that runs in Spring on Jetty into a Spring Boot application.

In the legacy code, I have an endpoint that looks like that:

@POST
@Produces({MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_JSON})
@Path("/zoo/feedCats")
@WebMethod
public Response giveFood( @Context UriInfo uri, HungryCats hungryCats){...}

And the first draft of the new endpoint in Spring Boot looks like that:

@PostMapping("/zoo/feedCats")
public Response giveFood( UriInfo uri , @RequestBody HungryCats hungryCats) {...}

I'm not sure what should be the right replacement for the @Context UriInfo uri that is in the legacy code.

I found this post from 2016 and was wondering if there is something else to use?

riorio
  • 6,500
  • 7
  • 47
  • 100

1 Answers1

1

So I solved it like that:

Created

class MyUriInfo implements UriInfo{..}

In the controller I changed the signature to be:

@PostMapping("/zoo/feedCats")
public Response giveFood(@RequestBody HungryCats hungryCats, 
                                      HttpServletRequest request,
                                      @RequestParam Map<String, String> allParams)

And created a translator method that takes what I need from the request and allParams and inject them to MyUriInfo:

 public UriInfo requestToUriInfo(HttpServletRequest request, Map<String, String> 
                                                               allParams) {
     ...
     retrun new MyUriInfo(...)
 }
riorio
  • 6,500
  • 7
  • 47
  • 100