I have a controller which accepts some params process it and should return a param back to UI by redirecting to a given url.
I have tried HttpResponse.seeOther and HttpResponse.redirect both displays bank page and "see other" message but does not redirect to an existing servable page. What am I missing here?
@Post('/getServ')
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_HTML)
HttpResponse<String> serve(@Nullable @Body LinkedHashMap payload) {
//...
URI location = new URI(redirectURL)
return HttpResponse.redirect(location).
header("Location", redirectURL).
status(302).
header("JWT", jwt.toString())
//...
}
The expected result should be a redirection to a url from the controller.
Have not tried it, but this should work:
@Post('/getServ')
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
HttpResponse<String> serve(@Nullable @Body LinkedHashMap payload) {
//...
URI location = new URI(redirectURL)
return HttpResponse.redirect(location).
header("JWT", jwt.toString())
//...
}
Your endpoint does not produce text/html - the redirect is an empty response with just the Location header set (by the framework). However, returning that (Content-Type) header may confuse your browser.
You should also not need to additionally set the status code and the location header directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With