1

I want to make a Authorization request using Spring Webflux to Paysafe test environment. I tried this:

Mono<AuthorizeRequest> transactionMono = Mono.just(transaction);
        return client.post().uri("https://api.test.paysafe.com/cardpayments/v1/accounts/{id}/auths", "123456789")
                .header(HttpHeaders.CONTENT_TYPE, "application/json")
                .header(HttpHeaders.AUTHORIZATION, "Basic dGVz.......")
                .accept(MediaType.APPLICATION_JSON)
                .contentType(MediaType.APPLICATION_JSON)
                .body(transactionMono, AuthorizeRequest.class)
                .retrieve()
                .bodyToMono(AuthorizeResponse.class);

But I get:

org.springframework.web.reactive.function.client.WebClientResponseException$BadRequest: 400 Bad Request
    at org.springframework.web.reactive.function.client.WebClientResponseException.create(WebClientResponseException.java:174)
    at org.springframework.web.reactive.function.client.DefaultWebClient$DefaultResponseSpec.lambda$createResponseException$15(DefaultWebClient.java:512)

Do you know how I can solve this?

Peter Penzov
  • 1,126
  • 134
  • 430
  • 808

2 Answers2

-1

The server you sent the request to answered with http status code 400. That means, that your request seems to be malformed.

For example, you could have forgotten to include a parameter.

dan1st
  • 12,568
  • 8
  • 34
  • 67
-1

400 Bad Request could be of many reasons. To find out what exactly causing issue try printing the response body as below:

.exchange()
                .flatMap(clientResponse -> {
                    if (clientResponse.statusCode().is5xxServerError()) {
                        clientResponse.body((clientHttpResponse, context) -> {
                            return clientHttpResponse.getBody();
                        });
                        return clientResponse.bodyToMono(String.class);
                    }
                    else
                        return clientResponse.bodyToMono(String.class);
                })
                .block();

This helps you to find the right reason and then you can fix

  • First this would give a Mono object, and secondly it is blocking, so really a bad solution – Daniel Nov 29 '21 at 13:09
  • Daniel, I have faced similar issue and I have found actual reason of 400 bad request and fixed using this approach. This will help identifying the actual error. Mono and blocking is not a fixed option any one can customise based on the requirement. Also if you feel this can be implemented better you can post the modified version. – Ravikumar Kumarasamy Nov 30 '21 at 04:01
  • There is another issue in your solution : the result of clientHttpResponse.getBody is never used or logged – Daniel Nov 30 '21 at 09:07