user1587852 user1587852 - 4 days ago 5
reST (reStructuredText) Question

Debugging JIRA Rest Api Call

I am trying to invoke the JIRA rest API. Using HTTPBuilder I invoke the server. However I get a 400 Bad Request. In the logs of JIRA I see nothing.

What is the best way, to debug this problem. What logging do I have to enable or where do I have to look, that jira tells me, what the problem is.

My Reuest in the logs of the client (groovy)

2016-11-24 19:44:22,761 DEBUG DefaultClientConnectionOperator - Connecting to jira.test.com:443
2016-11-24 19:44:23,097 DEBUG RequestAddCookies - CookieSpec selected: best-match
2016-11-24 19:44:23,108 DEBUG RequestAuthCache - Auth cache not set in the context
2016-11-24 19:44:23,108 DEBUG RequestProxyAuthentication - Proxy auth state: UNCHALLENGED
2016-11-24 19:44:23,108 DEBUG DefaultHttpClient - Attempt 1 to execute request
2016-11-24 19:44:23,108 DEBUG DefaultClientConnection - Sending request: POST /jira/rest/api/2/issue HTTP/1.1
2016-11-24 19:44:23,109 DEBUG wire - >> "POST /jira/rest/api/2/issue HTTP/1.1[\r][\n]"
2016-11-24 19:44:23,110 DEBUG wire - >> "Accept: application/json[\r][\n]"
2016-11-24 19:44:23,110 DEBUG wire - >> "Authorization: Basic cG1hOmJlZmltZTQ3[\r][\n]"
2016-11-24 19:44:23,110 DEBUG wire - >> "Content-Type: application/json[\r][\n]"
2016-11-24 19:44:23,110 DEBUG wire - >> "Content-Length: 86[\r][\n]"
2016-11-24 19:44:23,110 DEBUG wire - >> "Host: jira.test.com:443[\r][\n]"
2016-11-24 19:44:23,110 DEBUG wire - >> "Connection: Keep-Alive[\r][\n]"
2016-11-24 19:44:23,110 DEBUG wire - >> "[\r][\n]"
2016-11-24 19:44:23,110 DEBUG wire - >> "{"fields":{"project":{"key":"DEMO"},"summary":"REST Test","issuetype":{"name":"Bug"}}}"
2016-11-24 19:44:23,332 DEBUG wire - << "HTTP/1.1 400 Bad Request[\r][\n]"
2016-11-24 19:44:23,337 DEBUG wire - << "Date: Thu, 24 Nov 2016 18:44:23 GMT[\r][\n]"
2016-11-24 19:44:23,337 DEBUG wire - << "Server: Apache-Coyote/1.1[\r][\n]"
2016-11-24 19:44:23,337 DEBUG wire - << "X-AREQUESTID: 1184x11559x1[\r][\n]"
2016-11-24 19:44:23,337 DEBUG wire - << "X-ASESSIONID: xxx[\r][\n]"
2016-11-24 19:44:23,338 DEBUG wire - << "X-AUSERNAME: xxx[\r][\n]"
2016-11-24 19:44:23,338 DEBUG wire - << "Cache-Control: no-cache, no-store, no-transform[\r][\n]"
2016-11-24 19:44:23,338 DEBUG wire - << "X-Content-Type-Options: nosniff[\r][\n]"
2016-11-24 19:44:23,338 DEBUG wire - << "Content-Type: application/json;charset=UTF-8[\r][\n]"
2016-11-24 19:44:23,338 DEBUG wire - << "Set-Cookie: JSESSIONID=xxxx; Path=/jira/; HttpOnly[\r][\n]"
2016-11-24 19:44:23,338 DEBUG wire - << "Set-Cookie: atlassian.xsrf.token=BH04-20JI-TPKW-BCOS|fd0f9908f0241d6289509e6c621348ee63ead9c9|lin; Path=/jira[\r][\n]"
2016-11-24 19:44:23,339 DEBUG wire - << "Connection: close[\r][\n]"
2016-11-24 19:44:23,339 DEBUG wire - << "Transfer-Encoding: chunked[\r][\n]"
2016-11-24 19:44:23,339 DEBUG wire - << "[\r][\n]"
2016-11-24 19:44:23,341 DEBUG DefaultClientConnection - Receiving response: HTTP/1.1 400 Bad Request


The code to produce the problem reads as follows:

HTTPBuilder jiraHttp = new HTTPBuilder(jiraEndpoint)
jiraHttp.headers[ 'Authorization' ] = "Basic " + "$username:$password".getBytes('iso-8859-1').encodeBase64()
jiraHttp.headers[ 'Content-Type' ] = "application/json"
jiraHttp.ignoreSSLIssues();

String issueString = "{\"fields\":{\"project\":{\"key\":\"10300\"},\"summary\":\"REST Test\",\"issuetype\":{\"key\":\"10004\"}}}";
jiraHttp.post(contentType : 'application/json', path : '/jira/rest/api/2/issue', body: issueString);

Answer

The problem is indirectly resolved. I switched the HTTP Library to Jersey. Since than it works, unfortunately I could not find out, what the orignal problem was.

Comments