Permalink
Browse files

Added the ability to set a socket/connection timeout for the embedded…

… httpclient.
  • Loading branch information...
1 parent 67b262c commit 80e4b59309ba2df8931ff5604f7aa15fde3408e6 Antony Jones committed Aug 24, 2011
@@ -1,7 +1,7 @@
#Grails Metadata file
-#Wed Aug 18 00:59:17 BST 2010
-app.grails.version=1.3.4
+#Wed Aug 24 19:50:42 BST 2011
+app.grails.version=1.3.7
app.name=oauth-plugin
app.version=0.11
-plugins.hibernate=1.3.4
-plugins.tomcat=1.3.4
+plugins.hibernate=1.3.7
+plugins.tomcat=1.3.7
@@ -52,6 +52,7 @@ import org.apache.http.params.BasicHttpParams
import org.apache.http.protocol.HTTP
import org.apache.http.util.EntityUtils
import org.apache.http.client.methods.HttpRequestBase
+import org.apache.http.params.HttpConnectionParams
/**
* OAuth Service to provide OAuth functionality to a
@@ -66,11 +67,16 @@ class OauthService implements InitializingBean {
boolean transactional = false
+ private static int SIXTY_SECONDS = 60000
+
def providers = [:]
def consumers = [:]
private HttpClient httpClient
String callback = ""
+ int connectionTimeout = C.config.httpClient.timeout.connection as Integer
+ int socketTimeout = C.config.httpClient.timeout.socket as Integer
+
/**
* Initialise config properties.
*/
@@ -152,6 +158,9 @@ 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)
+
final SchemeRegistry schemeRegistry = new SchemeRegistry()
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80))
schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443))
@@ -337,7 +346,7 @@ class OauthService implements InitializingBean {
* @throws OauthServiceException
* If {@code args.consumer} does not represent an existing consumer.
*/
- def accessResource(final def url, final def consumer, final def token,
+ OauthResponse accessResource(final def url, final def consumer, final def token,
final def method = 'GET', final def params = null, final def headers = [:],
final def body = null, final def accept = null, final def contentType = null) {
@@ -374,7 +383,7 @@ class OauthService implements InitializingBean {
oauthResponse.with {
body = EntityUtils.toString(response.entity)
- status = response.statusCode
+ status = response.statusLine.statusCode
}
log.debug "Response body read successfully"

0 comments on commit 80e4b59

Please sign in to comment.