Hi,
I am testing the JIRA REST api by writing a small program in Groovy. I am using Groovy 1.8 with HTTPBuilder 0.5.1.
I have this code so far:
import groovyx.net.http.HTTPBuilder
import net.sf.json.JSONArray
class Test
{
def static JIRA_REST_URL = "http://testserver:8888/jira/rest"
def static JIRA_API_URL = JIRA_REST_URL + "/api/2.0.alpha1/"
public static void main(String[] args)
{
def jira = new HTTPBuilder(JIRA_API_URL);
jira.auth.basic "myusername", "mypassword"
def serverInfo = jira.get(path: 'serverInfo')
println "Using JIRA version " + serverInfo.version
def JSONArray projects = jira.get(path: 'project');
println projects
def int numberOfProjects = projects.size()
println "Got $numberOfProjects projects in JIRA";
projects.each { println it.dump() }
}
}
Which gives this result:
Using JIRA version 4.3.4
[]
Got 0 projects in JIRA
Community moderators have prevented the ability to post new answers.
Hi Wim,
The source formatter in this thing is pretty dire eh.
I believe the issue is that httpbuilder will only send the basic auth header when challenged, to stop credentials being spewed all over the place. However jira never sends a challenge.
There may be more elegant ways to do this, but, the following works for me. Replace jira.auth.basic(...) with:
jira.client.addRequestInterceptor(new HttpRequestInterceptor() {
void process(HttpRequest httpRequest, HttpContext httpContext) {
httpRequest.addHeader('Authorization', 'Basic ' + 'admin:admin'.bytes.encodeBase64().toString())
}
})
(where admin:admin is username:password).
Making this change made your test class work for me.
(Ref http://en.wikipedia.org/wiki/Basic_access_authentication)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.