1

I want to perform a rest call using org.springframework.web.reactive.function.client.WebClient

The correspondent curl command is this one:

curl -k --cert xxx.crt 
        --key yyy.key 
        --cacert ca.crt 
        -H "MyHEADER: userX" 
        -H "Content-Type: application/json" 
        https://host:1234/users -d '{"id":"XXXXX"}'

This is what I did so far:

 WebClient client = WebClient.create("https://host:1234");
 Mono<ClientResponse> result = client.get()
            .uri("/users")
            .headers(httpHeaders -> httpHeaders.add("MyHEADER","userX"))
            .accept(MediaType.APPLICATION_JSON)
            .exchange();

How can I specify the certificates?

I tried to configure the sslContext following this: Spring 5 WebClient using ssl but I get the exception: javax.net.ssl.SSLException: Received fatal alert: handshake_failure

I suppose that I have to specify the client certificates for the SSL client authentication ( In the curl command I use --cert xxx.crt --key yyy.key). How can I do the same in Spring/java?

Fabry
  • 1,498
  • 4
  • 23
  • 47
  • Does this answer your question? [Spring 5 WebClient using ssl](https://stackoverflow.com/questions/45418523/spring-5-webclient-using-ssl) – does Dec 29 '19 at 12:36
  • I tried to configure the sslContext as specified in the link you suggest but now I get an exception (I've updated my question with the new information) – Fabry Jan 02 '20 at 10:22

0 Answers0