我创建了一个groovlet,它将充当一种HTTP代理。它接受GET请求,然后根据请求中提供的URL进行Web服务调用。Groovy servlet在Tomcat中找不到JAR文件
这里是到目前为止,我已经得到了代码:
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.0')
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
String url = params.url
def http = new HTTPBuilder(url)
http.request(GET, TEXT) {
response.success = { resp, reader ->
println reader
}
response.'404' = { resp ->
println 'not found!'
}
}
我得在Groovlet中的WEB-INF/lib
文件夹中的Groovy HTTPBuilder JAR文件。但是,代码不能正常工作。 (我也尝试将文件夹放在$TOMCAT_HOME/common/lib
中,结果与下面相同。)
当我完全按照上面的方式运行代码时,页面会完全空白。
如果我只删除顶部的@Grab
行(因为JAR理论上应该在类路径中),我从Tomcat中得到了一个令人讨厌的错误(我在5.5上运行它,但我得到的行为大致相同对6):
HTTP Status 500 - GroovyServlet Error: script: '/proxy.groovy': Script processing failed.startup failed: General error during semantic analysis: Type org.apache.http.client.methods.HttpRequestBase not present java.lang.TypeNotPresentException: Type org.apache.http.client.methods.HttpRequestBase not present...
然后是堆栈跟踪。
我的groovlet有什么问题?