Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@WebServlet annotation and GWT RPC

In my GWT project running in glassfishv3, everything is worked properly, but when I change my servlet url patterns mapping from web.xml to @WebServlet annotation inside servlet classes, GWT rpc cand find the servlet!

note that, other usual servlets work with this annotation(WebServlet) and just GWT RPC doesnt work.

what is the reason?

RGDS

like image 619
Nav Avatar asked Nov 24 '11 09:11

Nav


People also ask

What is GWT RPC?

What is GWT RPC? The GWT RPC framework makes it easy for the client and server components of your web application to exchange Java objects over HTTP. The server-side code that gets invoked from the client is often referred to as a service.

What is @WebServlet?

Use the @WebServlet annotation to define a servlet component in a web application. This annotation is specified on a class and contains metadata about the servlet being declared. The annotated servlet must specify at least one URL pattern. This is done by using the urlPatterns or value attribute on the annotation.


2 Answers

Did you set the version number of web-app in the web.xml to the correct servlet version, because this feature is available only since 3.0:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
      version="3.0"> 
like image 63
Hilbrand Bouwkamp Avatar answered Sep 20 '22 23:09

Hilbrand Bouwkamp


Ok, I finally got this working but with some caveats. I was able to get it working in Tomcat within Intellij and as a deployed WAR to a Tomcat 7 container.

I was NOT able to get it working in dev-mode without using -noserver. I believe this is because the built-in Jetty server is not JSR315 compatible but have no evidence of this as I've not tried to determine what version of jetty is in the gwt-dev jar.

The trick is you need to fully qualify the path in WebServlet. So if your remote service interface has the relative path of "bar" and your module name (rename-to in gwt.xml) is "foo" then the path you need to set the path of "/foo/bar" in WebServlet and it will work.

like image 37
icfantv Avatar answered Sep 23 '22 23:09

icfantv