2016-11-24 152 views
0

我试图调用JIRA rest API。使用HTTPBuilder我调用服务器。但是,我收到了400个错误的请求。在JIRA的日志中,我什么都看不到。调试JIRA Rest Api调用

调试此问题的最佳方法是什么?我必须启用什么日志记录功能,或者我必须查看哪些日志,jira告诉我,问题是什么。

我Reuest在客户机的日志(常规)

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 

以产生该问题的代码如下:

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); 
+0

什么是响应体? –

回答

0

问题是间接解决的。我将HTTP库切换到泽西岛。由于比它的工作,不幸的是我无法找出,原始问题是什么。

0

正如巴特洛梅耶已经说过的,响应体是其中实际的错误描述是可用的。你需要捕获并看到。

虽然我可以猜到是什么问题。 错误的请求表示发布的问题格式无效。这很可能是issuetype变量。您需要传递实际的id而不是名称。

+0

不幸的是,没有响应的机构。发布的日志是由HTTPBuilder显示的连线日志。答复中没有任何内容。我使用ID来尝试请求。同样的问题 – user1587852

+0

我更新了问题,以便它也显示代码...你有什么想法吗? – user1587852

+0

有两件事:a)肯定有一个响应体b)你的有效载荷不同于原来的,'project'中的数字变量应该是'id'。 '钥匙'是字母数字的。 – rorschach