2

I'm trying to call an api with WebClient and it throws 404 with the below error message {"fault":{"faultstring":"Unable to identify proxy for host: localhost:9943 and url: \/url\/post\/msg","detail":{"errorcode":"messaging.adaptors.http.flow.ApplicationNotFound"}}} Below is the snippet where I'm trying to call the api

HttpClient httpClient = HttpClient.create()
        .tcpConfiguration(client -> client
                .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000)
                .doOnConnected(conn -> conn.addHandlerLast(new ReadTimeoutHandler(10000))
                        .addHandlerLast(new WriteTimeoutHandler(10000))));
        ClientHttpConnector connector = new ReactorClientHttpConnector(httpClient);
        WebClient webClient =  WebClient.builder().baseUrl("https://example.com").clientConnector(connector)
                .exchangeStrategies(ExchangeStrategies.builder()
                        .codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(16 * 1024 * 1024)).build())
                .build();       
        return webClient.post().uri(uriBuilder -> {
            URI url = uriBuilder.path(/postMsg).build();
            return url;
        }).headers(t -> {
            t.addAll(headers);
            
        }).body(Mono.just(request), Request.class)
                .exchangeToMono(clientResponse -> handleResponse(clientResponse));

Tried with and without proxy and it doesn't work.

But the same api works fine from postman and with restTemplate. Below is the snippet which works fine with restTemplate

HttpHeaders header = new HttpHeaders();
        headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
        HttpEntity<Request> entity = new HttpEntity<Request>(request, headers);
        String response = restTemplate
                .exchange("https://example.com/postMsg", HttpMethod.POST, entity, String.class)
                .getBody();

request and headers are the same for both webClient and restTemplate implementation. Any pointers on what I'm doing wrong is appreciated

Priya
  • 59
  • 7

0 Answers0