對Groovy來說相當新穎,我一直在嘗試用Groovy編寫一些測試用例用於REST接口。爲了設置我們的測試夾具,我需要清除CouchDB數據庫,並編寫了一個簡單的腳本來完成此操作,但由於某種原因,我一直從CouchDB獲取未授權的消息。儘管示例腳本現在非常簡單,但仍然看不到原因。 CouchDB實例具有admin用戶設置,但這是與默認設置唯一的偏差。多次檢查用戶名/密碼。惱人地應對來自groovy日誌的請求,並從cmd行添加'curl -X ..'作品。Groovy和CouchDB之間的身份驗證問題?
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.0') import groovyx.net.http.RESTClient RESTClient couchDBRestApi = new RESTClient('http://localhost:5984/') couchDBRestApi.auth.basic 'scott', 'tiger' ['mydb'].each { name -> def resp = couchDBRestApi.delete(path:name) assert resp.status == 200 }
看着我擔心在年底特別是空列表幾個條目的日誌「WARN DefaultRequestDirector - 驗證錯誤:{}:無法對任何的應對這些挑戰」?和'DEBUG RESTClient - 響應碼:401;找到處理程序:[email protected]'?
完整的日誌記載:
2010-06-14 15:19:27,520 DEBUG RESTClient - DELETE http://localhost:5984/mydb
2010-06-14 15:19:27,522 DEBUG wire -> "DELETE /mydb HTTP/1.1[EOL]"
2010-06-14 15:19:27,523 DEBUG wire -> "Accept: /[EOL]"
2010-06-14 15:19:27,523 DEBUG wire -> "Host: localhost:5984[EOL]"
2010-06-14 15:19:27,524 DEBUG wire -> "Connection: Keep-Alive[EOL]"
2010-06-14 15:19:27,525 DEBUG wire -> "User-Agent: Apache-HttpClient/4.0 (java 1.5)[EOL]"
2010-06-14 15:19:27,525 DEBUG wire -> "Accept-Encoding: gzip,deflate[EOL]"
2010-06-14 15:19:27,526 DEBUG wire -> "[EOL]"
2010-06-14 15:19:27,526 DEBUG headers -> DELETE /mydb HTTP/1.1
2010-06-14 15:19:27,527 DEBUG headers -> Accept: /
2010-06-14 15:19:27,527 DEBUG headers -> Host: localhost:5984
2010-06-14 15:19:27,528 DEBUG headers -> Connection: Keep-Alive
2010-06-14 15:19:27,528 DEBUG headers -> User-Agent: Apache-HttpClient/4.0 (java 1.5)
2010-06-14 15:19:27,529 DEBUG headers -> Accept-Encoding: gzip,deflate
2010-06-14 15:19:27,543 DEBUG wire <- "HTTP/1.1 401 Unauthorized[EOL]"
2010-06-14 15:19:27,543 DEBUG wire <- "Server: CouchDB/0.11.0 (Erlang OTP/R13B)[EOL]"
2010-06-14 15:19:27,544 DEBUG wire <- "Date: Mon, 14 Jun 2010 14:19:27 GMT[EOL]"
2010-06-14 15:19:27,544 DEBUG wire <- "Content-Type: text/plain;charset=utf-8[EOL]"
2010-06-14 15:19:27,544 DEBUG wire <- "Content-Length: 64[EOL]"
2010-06-14 15:19:27,545 DEBUG wire <- "Cache-Control: must-revalidate[EOL]"
2010-06-14 15:19:27,545 DEBUG wire <- "[EOL]"
2010-06-14 15:19:27,545 DEBUG headers <- HTTP/1.1 401 Unauthorized
2010-06-14 15:19:27,545 DEBUG headers <- Server: CouchDB/0.11.0 (Erlang OTP/R13B)
2010-06-14 15:19:27,546 DEBUG headers <- Date: Mon, 14 Jun 2010 14:19:27 GMT
2010-06-14 15:19:27,546 DEBUG headers <- Content-Type: text/plain;charset=utf-8
2010-06-14 15:19:27,546 DEBUG headers <- Content-Length: 64
2010-06-14 15:19:27,547 DEBUG headers <- Cache-Control: must-revalidate
2010-06-14 15:19:27,548 WARN DefaultRequestDirector - Authentication error: Unable to respond to any of these challenges: {}
2010-06-14 15:19:27,548 DEBUG RESTClient - Response code: 401; found handler: [email protected]
2010-06-14 15:19:27,549 DEBUG RESTClient - Parsing response as: text/plain
2010-06-14 15:19:27,549 DEBUG RESTClient - Parsed data to instance of: class java.io.InputStreamReader
2010-06-14 15:19:27,550 DEBUG wire <- "{"error":"unauthorized","reason":"You are not a server admin."}[\n]"
任何想法?做一些愚蠢的事情?或某人(誰?couchdb或groovy?)的錯誤
PS沒有代理/防火牆/ NTLM或任何花哨 - 所有本地主機,儘管在Windows 7(開發環境)。
PPS只是很快嘗試添加用戶名:密碼@主機到網址 - 這似乎並不工作 - 相同的錯誤消息。
- 理查德