0

When I'm trying to send POST request with WebClient, I get the following error.However if I try to send the request to the same uri using postman it is successful.Please help me out on this I am stuck in this issue and I am new to Spring WebFlux.

threw exception [Request processing failed; nested exception is reactor.core.Exceptions$ReactiveException: io.netty.channel.AbstractChannel$AnnotatedConnectException: finishConnect(..) failed: Connection refused: localhost/127.0.0.1:8080] with root cause\n+ Throwable: java.net.ConnectException: finishConnect(..) failed: Connection refused\n at io.netty.channel.unix.Errors.throwConnectException(Errors.java:124)\n at io.netty.channel.unix.Socket.finishConnect(Socket.java:243)\n at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.doFinishConnect(AbstractEpollChannel.java:672)\n at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.finishConnect(AbstractEpollChannel.java:649)\n at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.epollOutReady(AbstractEpollChannel.java:529)\n at

My WebClient Code to Send Post Req:

String success =
    webClient
        .post()
        .uri("/sendRequest")
        .contentType(MediaType.APPLICATION_JSON)
        .accept(MediaType.APPLICATION_JSON)
        .headers(
            httpHeaders -> {
     
              httpHeaders.add(
                 headerName, headerValue);

            })
        .body(Mono.just(messageBody), String.class)
        .exchange()
        .flatMap(
            response -> {
              HttpStatus httpStatus = response.statusCode();
              if (httpStatus.is2xxSuccessful()) {
                System.out.println("Message posted");
              } else {
                System.err.println("Message FAILED. Status=" + httpStatus.toString());
              }
              return response.bodyToMono(String.class);
            })
        .block();

}

//My WebClient Builder Code:

public WebClient getWebClient() {
  return WebClient.builder().baseUrl(this.MyUrl()).build();
}
Organik Street
  • 103
  • 1
  • 3
  • 10
  • 1
    Looks like it cannot find the other server. Try to build the request by hand and see if it responds properly. – tzortzik Feb 11 '21 at 08:50
  • Assuming you have a server running locally on port 8080, and other programs can connect to it ok, try turning off your firewall temporarily - it could be that 's letting through some programs ok, but not allowing your code to connect. – Michael Berry Feb 12 '21 at 10:47

0 Answers0