2016-11-24 136 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