views:

154

answers:

1

Hi, I am working on a GWT application which uses GWT-RPC. I just made a test groovlet to see if it worked, but ran into some problems

here's my groovlet

package groovy.servlet;
print "testing the groovlet";

Every tutorial said we don't need to subclass anything, and just a simple script would act as a servlet.

my web.xml looks like this -

<!--  groovy -->
 <servlet>
      <servlet-name>testGroovy</servlet-name>
      <servlet-class>groovy.servlet.testGroovy</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>testGroovy</servlet-name>
        <url-pattern>*.groovy</url-pattern>
    </servlet-mapping

When I Run as -> web application, i get the following error from jetty :

 [WARN] failed testGroovy
javax.servlet.UnavailableException: Servlet class groovy.servlet.testGroovy is not a javax.servlet.Servlet
 at org.mortbay.jetty.servlet.ServletHolder.checkServletType(ServletHolder.java:377)
 at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:234)
 at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
 at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:616)
 at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
 at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
 at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)
 at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
 at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload.doStart(JettyLauncher.java:447)
 at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
 at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
 at org.mortbay.jetty.handler.RequestLogHandler.doStart(RequestLogHandler.java:115)
 at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
 at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
 at org.mortbay.jetty.Server.doStart(Server.java:222)
 at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
 at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:543)
 at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:421)
 at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1035)
 at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:783)
 at com.google.gwt.dev.DevMode.main(DevMode.java:275)

What did I miss ?

A: 

You're building a new class there, not extending the HttpServlet class (or the groovy.servlet.GroovyServlet either).

GroovyServlet is the servlet, that then interprets your groovy script.

To set it up in web.xml you use

<servlet>
  <servlet-name>GroovyServlet</servlet-name>
  <servlet-class>groovy.servlet.GroovyServlet</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>GroovyServlet</servlet-name>
  <url-pattern>*.groovy</url-pattern>
</servlet-mapping>

And then in a file named something.groovy somwhere under your web root you can write

out.println 'testing the groovlet'

The objects request, response, session, params and others are also present at your disposal. So that you for instance can write

out.println "Hello ${params['name']}"

More info at http://groovy.codehaus.org/Groovlet

traneHead