1

我正在尝试为我的 groovlet 使用 Catch-all groovy 脚本。这就是我所做的

public class GroovletServletCatchAll extends GroovyServlet { 
    public URLConnection getResourceConnection(String name) throws ResourceException { 
        return super.getResourceConnection("CatchAll.groovy"); 
    } 
}

现在,使用CatchAll.groovy文件中的任何代码,我得到了错误

jndi:/localhost/web_app/CatchAll.groovy: 1: 
Invalid duplicate class definition of class CatchAll. 
One of the classes is an explicit generated class using the class statement, 
the other is a class generated from the script body based on the file name. 

为什么生成第一类?我的代码中没有任何其他类。只有 Catch-all 脚本和扩展的 servlet。


这是我得到上述错误的剥离代码

  println """
  Hello, ${request.remoteHost}: ${new Date()}
  """

奇怪的是,如果我删除new Date()上面的子句,第一个错误就会消失,并且我在 CatchAll 构造函数中得到一个 stackOverflow(继续调用自身)。

这就是我在日志中看到的重复(以及其他痕迹)

    at groovy.lang.GroovyObjectSupport.<init>(GroovyObjectSupport.java:32)
    at groovy.lang.Script.<init>(Script.java:40)
    at groovy.lang.Script.<init>(Script.java:37)
    at CatchAll.<init>(CatchAll.groovy)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

我也在这里发布了同样的问题

4

2 回答 2

0

我无法深入解决奇怪的行为,但有一个更简单的解决方案。我添加它以将所有请求定向到单个脚本。

<init-param>
    <param-name>resource.name.replacement</param-name>
    <param-value>CatchAll.groovy</param-value>
</init-param>

<init-param>
    <param-name>resource.name.regex</param-name>
    <param-value>/.*</param-value>
</init-param>
于 2013-08-30T17:07:42.857 回答
0

必须更正我之前的答案:修复不是我之前发布的代码更改,而是从 2.4.3 降级到 2.3.9。在 2.4.3 中,GroovyServlet 本身运行良好,但扩展其 setVariables、getScriptUri、getResourceConnection 和 getScriptUriAsFile 确实导致了上述问题。

仍在进一步调查。

于 2015-08-24T15:49:23.137 回答