0
votes

I have built a microservice using Java 8 and SpringBoot 2. From this microservice, I'm trying to consume another REST API service. However, I'm getting the following error on Chrome

java.lang.IllegalStateException: The underlying HTTP client completed without emitting a response.

2018-06-12 15:21:29.300 ERROR 17996 --- [ctor-http-nio-3] .a.w.r.e.DefaultErrorWebExceptionHandler : Failed to handle request [GET http://localhost:8080/category/search] io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection timed out: no further information: test.usdemo.xyz.com/92.54.41.24:443 at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:1.8.0_171] at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717) ~[na:1.8.0_171] at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:325) ~[netty-transport-4.1.24.Final.jar:4.1.24.Final] at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:340) ~[netty-transport-4.1.24.Final.jar:4.1.24.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:633) ~[netty-transport-4.1.24.Final.jar:4.1.24.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580) ~[netty-transport-4.1.24.Final.jar:4.1.24.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497) ~[netty-transport-4.1.24.Final.jar:4.1.24.Final] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459) ~[netty-transport-4.1.24.Final.jar:4.1.24.Final] at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884) ~[netty-common-4.1.24.Final.jar:4.1.24.Final] at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_171] Caused by: java.net.ConnectException: Connection timed out: no further information ... 10 common frames omitted

I'm able to consume the same service successfully using PostMan but not through my microservice.

Please assist to advise on this.

3
We need some more info. Can you post some code snippets of your service accessing the other service?mrkernelpanic
[Additional details] I have already disabled the firewall.Vinod Kumar
we need some code, can you please post the controller you are trying to access and the call you are doing from your microservice?rick
Without any code, there is little chance that someone can help you out. Please post some code and where exactly does the timeout occurUrosh T.
Code snippet for reference as follows:-Vinod Kumar

3 Answers

0
votes

I do not know how to edit my own question above as I do not see the edit option hence I'm adding the additional details here to get the resolution of my query.

Controller class:-

@RestController

public class CategorySearchController {

private final CategorySearchService categorySearchService;

@Autowired
public CategorySearchController(CategorySearchService categorySearchService) {
    this.categorySearchService = categorySearchService;
}


@GetMapping(path = "/search-category")
public Mono<CategoryResponse> searchCategories(SearchRequest categorySearchRequest){
    return categorySearchService
            .searchCategories()
            .switchIfEmpty(Mono.error(
                    new EntityNotFoundException("No category matching " + categorySearchRequest.getSearchTerm() + " was found")));
}

}

Service class:-

@Service
public class CategorySearchServiceImpl implements CategorySearchService {
    private String baseUrl = "https://demo0954903.mockable.io";

    @Override
    public Mono<CategoryResponse> searchCategories() {
        WebClient webClient = WebClient.create(baseUrl);
        return webClient.
                 get()
                .uri("/category-search")
                .retrieve()
                .bodyToMono(CategoryResponse.class);
    }
}
0
votes

I found the solution for this issue. I need to add the proxy in the webclient as follows:-

private final WebClient webClient;
ReactorClientHttpConnector connector = new ReactorClientHttpConnector(
                options -> options.httpProxy(addressSpec -> {
                return addressSpec.host(PROXY_HOST).port(PROXY_PORT);
                }));

        this.webClient = webClientBuilder.baseUrl(BASE_URL).clientConnector(connector).build();
0
votes

Check your proxy settings. In Spring applications, you can add the following to the VM arguments to set your proxy: -Dhttp.proxyHost=your.proxy.net -Dhttp.proxyPort=8080