简体   繁体   中英

Redirection to an external absolute URL in spring-boot-starter-webflux without a View Resolver

I am creating an application using spring-webflux. I have exposed a controller which has a method that is reactive and returns a Mono as the return type. The stack is reactive. The request comes in the browser and the API is expected to redirect the user in the browser to a url based on some calculation which are async in nature. Instead of redirection right now I am getting a response as shown below.

Is there a way to achieve this?

{
"defaultCharset": "UTF-8",
"requestContextAttribute": null,
"beanName": null,
"applicationContext": null,
"url": "https://my.box.com/service/auth/oauth/authorize?client_id=3d58a6ae9da221193d688feb521cf3f78ab8f1e04b3110813798b6feb877aa4d&response_type=code&redirect_uri=https://memini.serveo.net/api/v1/sources/BOX/connection?state=79299a49-e716-4ac5-a4f1-d16a2fdf6de5",
"contextRelative": true,
"statusCode": "SEE_OTHER",
"propagateQuery": false,
"hosts": null,
"redirectView": true,
"supportedMediaTypes": [
{
"type": "text",
"subtype": "html",
"parameters": {
"charset": "UTF-8"
},
"qualityValue": 1,
"wildcardType": false,
"wildcardSubtype": false,
"charset": "UTF-8",
"concrete": true
}
]
}

Well made it work using the code below

@GetMapping("/")
Mono<Void> redirect(ServerHttpResponse response) {
  response.setStatus(TEMPORARY_REDIRECT);
  response.getHeaders().setLocation(URI.create(authorizationUrl));
  return response.setComplete();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM