1

I'd like to send 302 response with redirectUri and query parameters. I am able to fill the location but not sure how to include values as query parameters in response of the controller.

I have tried to add values to body but I'd like to send them in query parameters.

public ResponseEntity<Void> redirect(@RequestBody MultiValueMap<String,String> formVars, HttpServletResponse response) {
    String clientId = formVars.getFirst(CLIENT_ID);
    String redirectUri = formVars.getFirst(REDIRECT_URI);
    String redirectToken = formVars.getFirst(REDIRECTION_TOKEN);

    ResponseHandler<RedirectDto> redirectDtoResponseHandler = redirectService.redeemRedirectToken(redirectToken);
    if (!redirectDtoResponseHandler.isPresent()) {
        //handle error
    }

    redirectDtoResponseHandler.map(redirectDto -> toCookie(redirectDto.getCustomerSessionId()))
        .ifPresent(response::addCookie);

    URI uri = UriComponentsBuilder.fromHttpUrl(redirectUri).build().toUri();

    //I'd like to add clientId as query param in this response?
    return ResponseEntity.status(HttpStatus.FOUND).location(uri).build();
}

I'd like to add clientId as query param in this response?

2
  • Can't you just return it in the body instead of a Void? Commented Feb 8, 2019 at 14:19
  • Nope, it's 302 response it can't have body. We can return things either in params or headers Commented Feb 9, 2019 at 15:07

1 Answer 1

2
UriComponents uriComponents = UriComponentsBuilder.newInstance()
      .scheme("http").host(redirectUri)
      .path("/").query("clientId={keyword}").buildAndExpand(clientId);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.