micronaut-projects / micronaut-core

Micronaut Application Framework
http://micronaut.io
Apache License 2.0
6.07k stars 1.07k forks source link

Connection time out when running Micronaut behind corporate proxy #1611

Closed 3logy closed 5 years ago

3logy commented 5 years ago

When i run/test a micronaut application behind a corporate proxy, using cntlm or not, it occurs the following error :

"Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection timed out: no further information: test.api.corporateurl.net/{proxyHost}:{proxyPort}"

I posted a question on Stackoverflow and set the proxy like the documentation said, but it seems like micronaut while requesting append the proxy at the end of the client root url.

I can test and request with the same complete url on postman (using system proxy) and its works.

`

  @MicronautTest
  public class DataControllerTest {

         @Client("https://test.api.corporateurl.net/api/v1/data/")
         @Inject RxHttpClient httpClient;

         @Test
         public void testFetchData() throws Exception {
               Map<String, Object> pathVariableMap = new HashMap<>();
               pathVariableMap.put("param1", "parametervariable");

               String uri = UriBuilder.of("/{param1}/")
                                .expand(pathVariableMap)
                               .toString();

               assertEquals("/parametervariable", uri);

               String result = httpClient.toBlocking().retrieve(uri);
               System.out.println(result);
          }  
}

` The complete stacktrace :

io.micronaut.http.client.exceptions.ReadTimeoutException: Read Timeout at io.micronaut.http.client.exceptions.ReadTimeoutException.(ReadTimeoutException.java:26) at io.micronaut.http.client.DefaultHttpClient.lambda$null$26(DefaultHttpClient.java:1069) at io.reactivex.internal.operators.flowable.FlowableOnErrorNext$OnErrorNextSubscriber.onError(FlowableOnErrorNext.java:103) at io.micronaut.reactive.rxjava2.InstrumentedSubscriber.lambda$onError$1(InstrumentedSubscriber.java:96) at io.micronaut.http.context.ServerRequestContext.with(ServerRequestContext.java:52) at io.micronaut.http.context.ServerRequestContext.lambda$instrument$0(ServerRequestContext.java:68) at io.micronaut.reactive.rxjava2.InstrumentedSubscriber.onError(InstrumentedSubscriber.java:100) at io.reactivex.internal.operators.flowable.FlowableTimeoutTimed$TimeoutSubscriber.onTimeout(FlowableTimeoutTimed.java:139) at io.reactivex.internal.operators.flowable.FlowableTimeoutTimed$TimeoutTask.run(FlowableTimeoutTimed.java:170) at io.micronaut.http.context.ServerRequestContext.with(ServerRequestContext.java:52) at io.micronaut.http.context.ServerRequestContext.lambda$instrument$0(ServerRequestContext.java:68) at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66) at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Exception in thread "nioEventLoopGroup-1-9" io.reactivex.exceptions.UndeliverableException: The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with. Further reading: https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling | io.micronaut.http.client.exceptions.HttpClientException: Connect Error: Connection timed out: no further information: test.api.corporate.net/122.144.66.277:443 at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:367) at io.reactivex.internal.operators.flowable.FlowableCreate$BaseEmitter.onError(FlowableCreate.java:275) at io.micronaut.http.client.DefaultHttpClient.lambda$null$24(DefaultHttpClient.java:1034) at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:511) at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:504) at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:483) at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:424) at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:121) at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.fulfillConnectPromise(AbstractNioChannel.java:327) at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:343) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:632) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:579) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:496) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897) at io.micronaut.http.context.ServerRequestContext.with(ServerRequestContext.java:52) at io.micronaut.http.context.ServerRequestContext.lambda$instrument$0(ServerRequestContext.java:68) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Unknown Source) Caused by: io.micronaut.http.client.exceptions.HttpClientException: Connect Error: Connection timed out: no further information: test.api.corporate.net/122.144.66.277:443 at io.micronaut.http.client.DefaultHttpClient.lambda$null$24(DefaultHttpClient.java:1035) ... 16 more Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection timed out: no further information: test.api.corporate.net/122.144.66.277:443 at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) at sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source) at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:327) at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:340) ... 9 more Caused by: java.net.ConnectException: Connection timed out: no further information ... 13 more

Thanks for reporting an issue for Micronaut, please review the task list below before submitting the issue. Your issue report will be closed if the issue is incomplete and the below tasks not completed.

NOTE: If you are unsure about something and the issue is more of a question a better place to ask questions is on Stack Overflow (http://stackoverflow.com/tags/micronaut) or Gitter (https://gitter.im/micronautfw/). DO NOT use the issue tracker to ask questions.

Task List

Steps to Reproduce

  1. Be behind a corporate proxy running on windows 7
  2. Request data (from a corporate api)

Expected Behaviour

Return 200 OK and a JSON in the Response

Actual Behaviour

Return a Read Time Out

Environment Information

graemerocher commented 5 years ago

The stack over flow answer relates to the CLI, for the HTTP client you need to configure the proxy settings through the HttpClientConfiguration settings in application.yml

3logy commented 5 years ago

@graemerocher` thank you. it's work.

I set it for example like this :

` myclient:

    client:

          proxy-address: xx.xx.xx.xx:2222

          proxy-type: HTTP

`

graemerocher commented 5 years ago

Perfect