Permalink
Browse files

Fix for bug whereby socket/connection timeouts became mandatory!

  • Loading branch information...
1 parent 62f0f7d commit 90338b1c182dac69665544daf03d0107ebbb6b6a Antony Jones committed Aug 29, 2011
View
2 grails-app/conf/BuildConfig.groovy
@@ -32,7 +32,7 @@ grails.project.dependency.resolution = {
}
plugins {
-
+ test ':spock:0.5-groovy-1.7'
}
}
View
8 grails-app/services/org/grails/plugins/oauth/OauthService.groovy
@@ -74,8 +74,8 @@ class OauthService implements InitializingBean {
private HttpClient httpClient
String callback = ""
- int connectionTimeout = C.config.httpClient.timeout.connection as Integer
- int socketTimeout = C.config.httpClient.timeout.socket as Integer
+ Integer connectionTimeout = (C.config?.httpClient?.timeout?.connection ?: SIXTY_SECONDS) as Integer
+ Integer socketTimeout = (C.config?.httpClient?.timeout?.socket ?: SIXTY_SECONDS) as Integer
/**
* Initialise config properties.
@@ -158,8 +158,8 @@ class OauthService implements InitializingBean {
HttpProtocolParams.setContentCharset(clientParams, HTTP.UTF_8)
HttpProtocolParams.setUseExpectContinue(clientParams, false)
- HttpConnectionParams.setConnectionTimeout(clientParams, connectionTimeout ?: SIXTY_SECONDS)
- HttpConnectionParams.setSoTimeout(clientParams, socketTimeout ?: SIXTY_SECONDS)
+ HttpConnectionParams.setConnectionTimeout(clientParams, connectionTimeout)
+ HttpConnectionParams.setSoTimeout(clientParams, socketTimeout)
final SchemeRegistry schemeRegistry = new SchemeRegistry()
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80))
View
50 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.