Search code examples
javaspringhttp-redirectiframejersey

Failed to migrate Jersey redirect to Spring redirect


I have the following jersey code to redirect inside an iframe (redirectLink is full URL in same domain):

private Response redirect(String redirectLink) {
   return Response.seeOther(new URI(redirectLink)).build();
}

I tried migration to Spring using ResponseEntity:

public ResponseEntity<String> confirm(String redirectLink) {
   return ResponseEntity.created(new URI(redirectLink)).build();
}

But I see a blank page instead of redirect

  • I logged that that full URL is correct

Example in documentation:

URI location = ...;
return ResponseEntity.created(location).header("MyResponseHeader", "MyValue").body("Hello World");

Solution

  • I succeeded using RedirectView (using partial/relative path to domain)

    public RedirectView  confirm(String partialPath) {
       return new RedirectView(partialPath);
    }
    

    View that redirects to an absolute, context relative, or current request relative URL