Skip to content

Commit

Permalink
Fix for bug whereby socket/connection timeouts became mandatory!
Browse files Browse the repository at this point in the history
  • Loading branch information
Antony Jones committed Aug 29, 2011
1 parent 62f0f7d commit 90338b1
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
2 changes: 1 addition & 1 deletion grails-app/conf/BuildConfig.groovy
Expand Up @@ -32,7 +32,7 @@ grails.project.dependency.resolution = {
} }


plugins { plugins {

test ':spock:0.5-groovy-1.7'
} }
} }


Expand Up @@ -74,8 +74,8 @@ class OauthService implements InitializingBean {
private HttpClient httpClient private HttpClient httpClient
String callback = "" String callback = ""


int connectionTimeout = C.config.httpClient.timeout.connection as Integer Integer connectionTimeout = (C.config?.httpClient?.timeout?.connection ?: SIXTY_SECONDS) as Integer
int socketTimeout = C.config.httpClient.timeout.socket as Integer Integer socketTimeout = (C.config?.httpClient?.timeout?.socket ?: SIXTY_SECONDS) as Integer


/** /**
* Initialise config properties. * Initialise config properties.
Expand Down Expand Up @@ -158,8 +158,8 @@ class OauthService implements InitializingBean {
HttpProtocolParams.setContentCharset(clientParams, HTTP.UTF_8) HttpProtocolParams.setContentCharset(clientParams, HTTP.UTF_8)
HttpProtocolParams.setUseExpectContinue(clientParams, false) HttpProtocolParams.setUseExpectContinue(clientParams, false)


HttpConnectionParams.setConnectionTimeout(clientParams, connectionTimeout ?: SIXTY_SECONDS) HttpConnectionParams.setConnectionTimeout(clientParams, connectionTimeout)
HttpConnectionParams.setSoTimeout(clientParams, socketTimeout ?: SIXTY_SECONDS) HttpConnectionParams.setSoTimeout(clientParams, socketTimeout)


final SchemeRegistry schemeRegistry = new SchemeRegistry() final SchemeRegistry schemeRegistry = new SchemeRegistry()
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)) schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80))
Expand Down
50 changes: 50 additions & 0 deletions test/unit/ConfigurationSpec.groovy
@@ -0,0 +1,50 @@
import grails.plugin.spock.ControllerSpec
import org.grails.plugins.oauth.OauthService
import grails.plugin.spock.UnitSpec
import spock.lang.Unroll

class ConfigurationSpec extends UnitSpec {

@Unroll("Socket timeout is correctly read when socket timeout is #socketTimeout and connection timeout is #connectionTimeout")
def "Socket timeout is read correctly"() {

given:
mockConfig """
httpClient {
timeout {
socket = ${socketTimeout}
connection = ${connectionTimeout}
}
}
"""

when:
OauthService oauthService = new OauthService()

then:
oauthService.connectionTimeout == connectionTimeout
oauthService.socketTimeout == socketTimeout

where:
connectionTimeout | socketTimeout
5000 | 5000
60000 | 60000

}

def "Socket timeout is defaulted when no configuration is available"() {

given:
mockConfig ''

when:
OauthService oauthService = new OauthService()

then:
oauthService.connectionTimeout == 60000
oauthService.socketTimeout == 60000


}

}

0 comments on commit 90338b1

Please sign in to comment.