Groovy和&之间的身份验证问题CouchDB的?

时间:2010-06-14 17:12:31

标签: groovy couchdb

对Groovy来说相当新,我一直在尝试用Groovy编写一些用于REST接口的测试用例。为了设置我们的测试夹具,我需要清理CouchDB数据库并编写一个简单的脚本来执行此操作,但由于某种原因,我不断从CouchDB获取未经授权的消息。尽管示例脚本现在如此简单,但减少了代码并仍然无法理解为什么。 CouchDB实例具有管理员用户设置,但这是与默认设置的唯一偏差。多次检查用户名/密码。恼人地处理来自groovy日志的请求并添加'curl -X ..'在cmd行中工作。

@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;找到处理程序:org.codehaus.groovy.runtime.MethodClosure@e2e4d7'?

完整日志读取:

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: org.codehaus.groovy.runtime.MethodClosure@e2e4d7 
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或任何花哨的东西 - 所有localhost尽管在Windows 7(开发环境)上。

PPS很快就尝试将用户名:password @ host添加到网址 - 这似乎不起作用 - 同样的错误信息。

  • 理查德

1 个答案:

答案 0 :(得分:1)

好的,这与CouchDB 0.11中的更改​​有关,后者关闭了基本的401身份验证标头。现在我只需要弄清楚如何打开RESTClient / HttpBuilder的预身份验证,就像curl一样。参考:http://markmail.org/thread/gbky5leiivngglck#query:+page:1+mid:3hraq5ufip2mlpq5+state:results