Groovy script to Grails app -


well new groovy/grails. have written groovy script uses restclient make http post request jira server. post request sends jql query , receives result in json format. here's full code:

import groovyx.net.http.restclient; import groovyx.net.http.httpresponsedecorator; import org.apache.http.httprequest; import org.apache.http.protocol.httpcontext; import org.apache.http.httprequestinterceptor; import groovy.json.jsonslurper; import static groovyx.net.http.method.* import static groovyx.net.http.contenttype.*  @grab(value = 'org.codehaus.groovy:groovy-all:2.1.6',        initclass = false) @grapes([ @grab(group = 'org.codehaus.groovy.modules.http-builder',        module = 'http-builder', version = '0.5.2'), @grabexclude('org.codehaus.groovy:groovy') ])  // connect jira def jiraapiurl = 'http://my-jira.com/rest/api/2/' def jiraclient = new restclient(jiraapiurl);  // authentication def basic = 'basic ' + 'username:password'.bytes.encodebase64().tostring() jiraclient.client.addrequestinterceptor ( new httprequestinterceptor() {     void process(httprequest httprequest,                   httpcontext httpcontext) {                       httprequest.addheader('authorization', basic)       }     })  // http post method def uripath = 'search' def param = [maxresults : 1, jql : '<jql-query>']  def issues = jiraclient.post(requestcontenttype : json, path : uripath, body : param)  def slurpedissues = new jsonslurper().parsetext(issues.data.tostring())  println issues.data.total 

i need migrate script grails app. suggestions how same?

  1. define dependencies in buildconfig (except groovy dependency)
  2. copy script contents service

possible extension:

  1. use grails rest plugin or grails rest-client-builder plugin instead of http-builder

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -