Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I use dispatch reboot to connect to HTTPS / SSL server endpoint? #29

Closed
dmrolfs opened this issue Oct 29, 2012 · 0 comments
Closed

Comments

@dmrolfs
Copy link

dmrolfs commented Oct 29, 2012

I am trying to use dispatch (reboot) 0.9.3 to access a long-running HTTPS end point, however I consistent get a connection time out after 60s.

I am trying to set the timeout to 300s, and in tests with the same code against a non-SSL HTTP end point the code work as expected -- it holds until the response is returned.

Am I configuring async-http-client or dispatch improperly for HTTPS end points?

It seems that for an HTTPS end point dispatch is not connecting fully to the HTTPS service.

The code I use is:

val request = dispatch.url( endpt ).secure
val body = requestBodyFor( inquiry ).toString
request << body.toString
// actually I hold http in a variable that is lazy created but this is close enough
val response = http( request > as.String ).either 

def http: dispatch.Http = {
  val client = new AsyncHttpClient( 
    new AsyncHttpClientConfig.Builder()
    .setAllowPoolingConnection( true )
    .setAllowSslConnectionPool( true )
    .setConnectionTimeoutInMs( outer.timeout.toInt )
    .setIdleConnectionTimeoutInMs( outer.timeout.toInt )
    .setMaxRequestRetry( 3 )
    .setRequestTimeoutInMs( outer.timeout.toInt )
    .setAsyncHttpClientProviderConfig(
      new NettyAsyncHttpProviderConfig().addProperty(
        NettyAsyncHttpProviderConfig.BOSS_EXECUTOR_SERVICE, 
        juc.Executors.newCachedThreadPool( DaemonThreads.factory )
      )
    ).build()
  ) 

  dispatch.Http( client = client ).waiting( dispatch.Duration.millis( outer.timeout ) )
}

endpt is a configured string that is the URL I'm trying to hit; e.g., "https://www.foo.com/bar" timeout is also configured in ms -- currently set to 300000

even though I set the timeout to 300000ms (5mins), I get the following error after 1 minute:

[debug] c.n.h.c.p.n.NettyConnectListener - Trying to recover a dead cached channel [id: 0x06808e21] with a retry value of true 
[debug] c.n.h.c.p.n.NettyConnectListener - Failed to recover from exception: java.net.ConnectException: Connection timed out with channel [id: 0x06808e21]
[debug] c.n.h.c.AsyncCompletionHandlerBase - Connection timed out to https://direct.backgroundchecks.com/integration/bgcdirectpost.aspx
java.net.ConnectException: Connection timed out to https://direct.backgroundchecks.com/integration/bgcdirectpost.aspx
    at com.ning.http.client.providers.netty.NettyConnectListener.operationComplete(NettyConnectListener.java:100) ~[async-http-client.jar:na]
    at org.jboss.netty.channel.DefaultChannelFuture.notifyListener(DefaultChannelFuture.java:428) [netty.jar:na]
    at org.jboss.netty.channel.DefaultChannelFuture.notifyListeners(DefaultChannelFuture.java:419) [netty.jar:na]
    at org.jboss.netty.channel.DefaultChannelFuture.setFailure(DefaultChannelFuture.java:381) [netty.jar:na]
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.connect(NioClientSocketPipelineSink.java:409) [netty.jar:na]
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.processSelectedKeys(NioClientSocketPipelineSink.java:366) [netty.jar:na]
Caused by: java.net.ConnectException: Connection timed out
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:1.7.0_07]
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:692) ~[na:1.7.0_07]
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.connect(NioClientSocketPipelineSink.java:404) [netty.jar:na]
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.processSelectedKeys(NioClientSocketPipelineSink.java:366) [netty.jar:na]
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.run(NioClientSocketPipelineSink.java:282) [netty.jar:na]
    at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:102) [netty.jar:na]
[debug] c.n.h.c.p.n.NettyAsyncHttpProvider - Channel Closed: [id: 0x06808e21] with attachment null
[debug] c.n.h.c.p.n.NettyAsyncHttpProvider - Unexpected I/O exception on channel [id: 0x06808e21]
java.net.ConnectException: Connection timed out
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:1.7.0_07]
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:692) ~[na:1.7.0_07]
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.connect(NioClientSocketPipelineSink.java:404) ~[netty.jar:na]
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.processSelectedKeys(NioClientSocketPipelineSink.java:366) ~[netty.jar:na]
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.run(NioClientSocketPipelineSink.java:282) ~[netty.jar:na]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [na:1.7.0_07]
[debug] c.n.h.c.p.n.NettyAsyncHttpProvider - Closing Channel [id: 0x06808e21]

Again, if I change only the endpoint to a non-SSL URL, the code works as expected and waits up till 5mins for the response.

Thanks in advance!

@dmrolfs dmrolfs closed this as completed Oct 30, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant