Permalink
Browse files

Make getRequest() append params to the URL's query string. Services s…

…uch as the Twitter API expect the params as URL parameters and will ignore headers. Unfortunately, for now we still add headers otherwise signpost doesn't seem to sign them correctly.
  • Loading branch information...
1 parent 81ac6d4 commit 85d105a9ef60b76c600cd1d385647543a586b76b @petedoyle petedoyle committed Aug 31, 2010
Showing with 23 additions and 2 deletions.
  1. +23 −2 oauth-plugin/grails-app/services/org/grails/plugins/oauth/OauthService.groovy
@@ -258,6 +258,27 @@ class OauthService implements InitializingBean {
throw new OauthServiceException(errorMessage)
}
+ if (params) {
+ log.debug "Putting additional params as URL params: $params"
+
+ StringBuffer queryParams = new StringBuffer()
+ queryParams.append("?")
+ params.eachWithIndex { key, value, i ->
+ if( i > 0 ) {
+ queryParams.append("&")
+ }
+
+ queryParams.append(key)
+ queryParams.append("=")
+ queryParams.append(URLEncoder.encode( "$value", "utf-8"))
+ }
+
+ if( queryParams.length() > 0 ) {
+ url = new URL( url.toString() + queryParams.toString() )
+ log.debug "URL is now: ${url.toString()}"
+ }
+ }
+
log.debug "Open connection to $url"
// Create an HTTP request to a protected resource
@@ -267,10 +288,10 @@ class OauthService implements InitializingBean {
request.setRequestMethod(method)
if (params) {
- log.debug "Putting additional params: $params"
+ log.debug "Putting additional params as headers: $params"
params.each { key, value ->
- request.addRequestProperty(key, value)
+ request.addRequestProperty(key, "$value")
}
log.debug "Request properties are now: ${request?.getRequestProperties()}"

0 comments on commit 85d105a

Please sign in to comment.