Permalink
Browse files

corrections before publish

  • Loading branch information...
dpacaud committed Sep 22, 2012
1 parent f54c5f9 commit 6cc2f72e91c52841ab73365fc3c28eb415cdec7a
@@ -1,90 +1,86 @@
-
-package org.grails.mandrill
-
-import grails.converters.JSON
-import groovyx.net.http.ContentType
-import groovyx.net.http.HTTPBuilder
-import groovyx.net.http.Method
-
-class HttpWrapperService {
- static transactional = false
- def grailsApplication
-
- def postText(String baseUrl, String path, query, method = Method.POST) {
- try {
-
- def ret = null
- def http = new HTTPBuilder(baseUrl)
-
- /*************************************
- * Handling Proxy configuration
- *************************************/
-
- if(grailsApplication.config.mandrill.proxy?.host && grailsApplication.config.mandrill.proxy?.port){
- if(grailsApplication.config.mandrill.proxy?.port?.isInteger()){
- log.info "setting Proxy to : ${grailsApplication.config.mandrill.proxy.host} on port : ${grailsApplication.config.mandrill.proxy.port}"
- http.setProxy(grailsApplication.config.mandrill.proxy.host,Integer.parseInt(grailsApplication.config.mandrill.proxy.port),null)
- }
- else {
- throw new NumberFormatException("mandrill Proxy PORT must be an integer, please correct the config file")
- }
- }
-
- // perform a POST request, expecting TEXT response
- http.request(method, ContentType.TEXT) {
-
- uri.path = path
- body = new JSON(query)
-
- headers.'User-Agent' = 'Mozilla/5.0 Ubuntu/8.10 Firefox/3.0.4'
- println uri
- // response handler for a success response code
- response.success = { resp, reader ->
- println "response status: ${resp.statusLine}"
- println 'Headers: -----------'
- resp.headers.each { h ->
- println " ${h.name} : ${h.value}"
- }
-
- ret = reader.getText()
-
- println 'Response data: -----'
- println ret
- println '--------------------'
- }
-
- response.failure = { resp, reader ->
- println "------ Failure ------ "
- resp.headers.each { h ->
- println " ${h.name} : ${h.value}"
- }
- ret = reader.getText()
-
- println 'Response data: -----'
- println ret
- println '--------------------'
- }
- }
- return ret
-
- } catch (groovyx.net.http.HttpResponseException ex) {
- println "toto"
- println ex
- return null
- } catch (java.net.ConnectException ex) {
- println "tata"
- println ex
- return null
- }
- catch (NumberFormatException nfe) {
- log.error nfe.getMessage()
- return null
- }
- catch (Exception e) {
- println "titi"
- println e
- return null
- }
- }
-
-}
+
+package org.grails.mandrill
+
+import grails.converters.JSON
+import groovyx.net.http.ContentType
+import groovyx.net.http.HTTPBuilder
+import groovyx.net.http.Method
+
+class HttpWrapperService {
+ static transactional = false
+ def grailsApplication
+
+ def postText(String baseUrl, String path, query, method = Method.POST) {
+ try {
+
+ def ret = null
+ def http = new HTTPBuilder(baseUrl)
+
+ /*************************************
+ * Handling Proxy configuration
+ *************************************/
+
+ if(grailsApplication.config.mandrill.proxy?.host && grailsApplication.config.mandrill.proxy?.port){
+ if(grailsApplication.config.mandrill.proxy?.port?.isInteger()){
+ log.info "Mandrill plugin is setting setting Proxy to : ${grailsApplication.config.mandrill.proxy.host} on port : ${grailsApplication.config.mandrill.proxy.port}"
+ http.setProxy(grailsApplication.config.mandrill.proxy.host,Integer.parseInt(grailsApplication.config.mandrill.proxy.port),null)
+ }
+ else {
+ throw new NumberFormatException("mandrill Proxy PORT must be an integer, please correct the config file")
+ }
+ }
+
+ // perform a POST request, expecting TEXT response
+ http.request(method, ContentType.TEXT) {
+
+ uri.path = path
+ body = new JSON(query)
+
+
+ // response handler for a success response code
+ response.success = { resp, reader ->
+ log.debug "response status: ${resp.statusLine}"
+ log.debug 'Headers: -----------'
+ resp.headers.each { h ->
+ log.debug " ${h.name} : ${h.value}"
+ }
+
+ ret = reader.getText()
+
+ log.debug 'Response data: -----'
+ log.debug ret
+ log.debug '--------------------'
+ }
+
+ response.failure = { resp, reader ->
+ log.debug "------ Failure ------ "
+ resp.headers.each { h ->
+ log.debug " ${h.name} : ${h.value}"
+ }
+ ret = reader.getText()
+
+ log.debug 'Response data: -----'
+ log.debug ret
+ log.debug '--------------------'
+ }
+ }
+ return ret
+
+ } catch (groovyx.net.http.HttpResponseException ex) {
+ log.error ex.getMessage()
+ return null
+ } catch (java.net.ConnectException ex) {
+ log.error ex.getMessage()
+ return null
+ }
+ catch (NumberFormatException nfe) {
+ log.error nfe.getMessage()
+ return null
+ }
+ catch (Exception e) {
+ log.error e.getMessage()
+ return null
+ }
+ }
+
+}
View
0 plugin.xml 100755 → 100644
No changes.
View
@@ -12,7 +12,8 @@
def configFile = new File(basedir, 'grails-app/conf/Config.groovy')
-if (configFile.exists() && configFile.text.indexOf("gmandrill") == -1) {
+if (configFile.exists() && configFile.text.indexOf("mandrill") == -1) {
+ println "Adding mandrill config options to the Config file"
configFile.withWriterAppend {
it.writeLine '\n// Added by the Grails Mandrill plugin:'
it.writeLine '''mandrill {

0 comments on commit 6cc2f72

Please sign in to comment.