튜토리얼을 기반으로 한 코드에서 누락 된 메스 테이션 및 어제 작업
-
14-11-2019 - |
문제
groovy 및 httpbuilder 라이브러리에 이상한 문제가 있습니다.첫째, 나는 그루비에게 신선합니다.
튜토리얼에서 내 코드를 기반으로합니다.HTTP Server에서 파일 목록을로드하기 만하면됩니다.이 코드는 어제 오늘 (작업 공간 빌드 이후)하지 않았습니다.
문제는 다음과 같습니다 :
.
Caught: groovy.lang.MissingMethodException: No signature of method: groovyx.net.http.HTTPBuilder.request() is applicable for argument types: (groovyx.net.http.Method, groovyx.net.http.ContentType, pl.linfo.groovy.samples.HttpTest$_main_closure1)
Possible solutions: request(groovyx.net.http.Method, groovy.lang.Closure)
코드는 다음과 같습니다.
.
def http = new HTTPBuilder( 'http://nbp.pl/Kursy/xml/dir.txt' )
http.request( GET, TEXT ) {
response.success = { resp, reader ->
println "${resp.statusLine}"
files = reader.text.split ('\r\n')
}
response.'404' = {
println "Not found!"
return
}
};
실행중인 환경은 Eclipse 3.6
문제가 Groovy Compilation 문제이고 더 이상 일치하는 폐쇄가 없으면 재 컴파일 후 Groovy 코드 조각입니다.그러나 Groovy의 새로운 것처럼 나는 무슨 일이 일어나는지 알아내는 데 문제가 있으므로 도움을주십시오.
해결책
This has to be some problem with the Eclipse Groovy plugin. The code you posted works well for me when run using the groovy interpreter.
$ cat hbuildertest.groovy
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.1' )
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
def http = new HTTPBuilder( 'http://nbp.pl/Kursy/xml/dir.txt' )
http.request( GET, TEXT ) {
response.success = { resp, reader ->
println "${resp.statusLine}"
files = reader.text.split ('\r\n')
}
response.'404' = {
println "Not found!"
return
}
};
$ groovy hbuildertest.groovy
May 19, 2011 12:59:08 AM groovyx.net.http.ParserRegistry getCharset
WARNING: Could not find charset in response
HTTP/1.1 200 OK
$
Also the method with signature:
public Object request( Method m, Object contentType, Closure configClosure )
throws ClientProtocolException, IOException
exists in groovyx.net.http.HTTPBuilder
class since at least 0.3.0 version of the library.