404 when accessing RPC Service in GWTHandler

249 views
Skip to first unread message

dchicks

unread,
Mar 8, 2010, 7:43:06 PM3/8/10
to gwt-sl
I know this has been covered ad-nauseum in various place, but I'll be
darned if i can get it working for me. I've tried every combination
of configurations I can think of. I prefer the GWTHandler method for
its simplicity, though. The fact remains, that when my application
attempts to access my RPC service, I get a 404. I can't tell if the
Spring DispatcherServlet ever even gets the request, or not. So, I
thought I'd post some snippets here in hopes that someone can spot
where I'm going wrong. I'd appreciate any input.

My service is a simple POJO with 3 methods.

public interface ActivityService extends RemoteService {
public List<ActivityDTO> listActivities();
public void deleteActivity(Long activityId);
public void addActivity(String name, String activityData);
}

I define the DispatcherServlet to look for URL's of the form /services/
*
<servlet>
<servlet-name>services</servlet-name>
<servlet-
class>org.springframework.web.servlet.DispatcherServlet</servlet-
class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>services</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>

Then in services-servlet.xml define the mappings that GWTHandler
should look for:
<bean id="urlMapping"
class="org.gwtwidgets.server.spring.GWTHandler">
<property name="mappings">
<map>
<entry key="/services/activityService" value-
ref="activityService"/>
</map>
</property>
</bean>

"activityService" is defined in a separately loaded Spring
configuration using ContextLoaderListener. This loads a bunch of
other beans, including the service bean and wires them all up.

Finally, in my application, I instantiate an ActivityServiceAsync and
give it the entry point:
target.setServiceEntryPoint( GWT.getModuleBaseURL() +
"services/activityService" );

I've seen some references to hosted mode not being able to use the
Spring container, but other postings saying that it works just fine.
I looked for a FAQ on the home page in SourceForge to see if there was
more information, but I found no reference to such a page. So, I
apologize in advance if this information is out there. I just can't
seem to find it.

Thanks,
Dave

David C. Hicks

unread,
Mar 8, 2010, 10:16:08 PM3/8/10
to gwt...@googlegroups.com
After posting this, I did find the FAQ page in the documentation and
discovered an error in my configuration. Where I defined my URL
mappings for GWTHandler, I had included the servlet portion of the URL.
After removing this, I still get a 404, however. The new URL mapping
looks like this:

<bean id="urlMapping" class="org.gwtwidgets.server.spring.GWTHandler">
<property name="mappings">
<map>

<entry key="/activityService" value-ref="activityService"/>
</map>
</property>
</bean>

Dave

David C. Hicks

unread,
Mar 9, 2010, 2:45:27 AM3/9/10
to gwt...@googlegroups.com
Partly from a friend's input and partly from an answer I saw on another
thread here tonight, I managed to solve this issue. I had not
previously understood that the @RemoteServiceRelativePath annotation
specified a path relative to the GWT Module. I had been thinking it was
relative to the base URL. Once I understood that difference, it was
pretty easy to figure out how to get the mapping to work out.

Dave


On 03/08/2010 07:43 PM, dchicks wrote:

arous riadh

unread,
Mar 9, 2010, 3:29:41 AM3/9/10
to gwt...@googlegroups.com
Hi David
i have tryed to follow your exemple but it didn't work
my web.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

<web-app>
  
  <!-- Servlets -->
 <servlet>
<servlet-name>services</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet  <!--  This is a Spring configuration-->
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>services</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
 
  
  <!-- Default page to serve -->
  <welcome-file-list>
    <welcome-file>GwtDeply.html</welcome-file>
  </welcome-file-list>

</web-app>

my services-servlet.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean class="org.gwtwidgets.server.spring.GWTHandler">
<property name="mappings">
<map>
<entry key="/services/activityService" value-ref="RPCTest" />
</map>
</property>
</bean>
<bean id="RPCTest" class="gwt.deploy.test.server.ServiceAddImpl" />
</beans>

my module looks like:
...
private ServiceAddAsync greetingService = GWT
.create(ServiceAdd.class);
public void onModuleLoad() {
ServiceDefTarget endpoint = (ServiceDefTarget) greetingService;
endpoint.setServiceEntryPoint(GWT.getModuleBaseURL() +"services/activityService");
I am getting always this 404 error:

type Rapport d'état

message /war/gwtdeply/services/activityService

description La ressource demandée (/war/gwtdeply/services/activityService) n'est pas disponible.


what is wrong with my code!!


2010/3/9 David C. Hicks <dhi...@i-hicks.org>
--
You received this message because you are subscribed to the Google Groups "gwt-sl" group.
To post to this group, send an email to gwt...@googlegroups.com.
To unsubscribe from this group, send email to gwt-sl+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gwt-sl?hl=en-GB.


David C. Hicks

unread,
Mar 9, 2010, 3:58:57 AM3/9/10
to gwt...@googlegroups.com
Arous,

There were several places where I made changes, beginning with my actual GWT Module name.  The gwt-maven-plugin creates a rather long name, using the package path.  I changed this to "activities" in all the locations I could find.   This wasn't really necessary, but it helped reduce the "noise" so that I could more clearly see the effect of other changes.  The main thing that helped was adding a rename-to attribute on my GWT Module xml:
<module rename-to="activities">
This becomes the base URL of the module.  So my module is now located at something like http://localhost:8080/activities.  Next, I had to make sure that the DispatcherServlet was defined to intercept the correct URLs:
    <servlet>
        <servlet-name>activities</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>activities</servlet-name>
        <url-pattern>/activities/services/*</url-pattern>
    </servlet-mapping>
Notice that the url-pattern includes the name of the GWT module!  This is important!  Next, I define the mapping for the services in activities-servlet.xml:
    <bean id="urlMapping" class="org.gwtwidgets.server.spring.GWTHandler">
        <property name="mappings">
            <map>
                <entry key="/activityService" value-ref="activityService"/>
            </map>
        </property>
    </bean>
Finally, I must define the relative path for the service on the service interface:
@RemoteServiceRelativePath("services/activityService")

public interface ActivityService extends RemoteService {
    public List<ActivityDTO> listActivities();
    public void deleteActivity(Long activityId);
    public void addActivity(String name, String activityData);
}
Note that here, the path is relative to the GWT Module - not to the base URL.  With all of those things in place, my RPC services are working wonderfully, and all of my service, persistence, and other beans are now managed by Spring!  Awesome!

Dave

zizou84

unread,
Mar 10, 2010, 1:11:53 PM3/10/10
to gwt-sl
Hi David
i have followed your exempleexactly but i am getting always an 404
error

Sending name to the server:
878

Server replies:
Etat HTTP 404 - Servlet activities n'est pas disponible.

type Rapport d'�tat

message Servlet activities n'est pas disponible.

description La ressource demand�e (Servlet activities n'est pas
disponible.) n'est pas disponible.

another thing that may help you to help me:in developpment mode, i get

Starting Jetty on port 8888
[WARN] Exception while dispatching incoming RPC call
java.lang.RuntimeException:
com.google.gwt.user.server.rpc.UnexpectedException: Service method
'public abstract java.lang.String
gwt.spring.serverlibrary.client.GreetingService.greetServer(java.lang.String)'
threw an unexpected exception: java.lang.NullPointerException
at
org.gwtwidgets.server.spring.GWTRPCServiceExporter.handleExporterProcessingException(GWTRPCServiceExporter.java:
384)
at
org.gwtwidgets.server.spring.GWTRPCServiceExporter.processCall(GWTRPCServiceExporter.java:
353)
at
com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:
224)
at
com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:
62)
at
org.gwtwidgets.server.spring.GWTRPCServiceExporter.handleRequest(GWTRPCServiceExporter.java:
407)
at
org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:
49)
at
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:
771)
at
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:
716)
at
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:
647)
at
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:
563)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:
487)
at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:
362)
at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:
216)
at
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:
181)
at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:
729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:
405)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at
org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:
49)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
505)
at org.mortbay.jetty.HttpConnection
$RequestHandler.content(HttpConnection.java:843)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:
395)
at org.mortbay.thread.QueuedThreadPool
$PoolThread.run(QueuedThreadPool.java:488)
Caused by: com.google.gwt.user.server.rpc.UnexpectedException: Service
method 'public abstract java.lang.String
gwt.spring.serverlibrary.client.GreetingService.greetServer(java.lang.String)'
threw an unexpected exception: java.lang.NullPointerException
at
com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:
378)
at
com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:
361)
at
org.gwtwidgets.server.spring.GWTRPCServiceExporter.encodeResponseForFailure(GWTRPCServiceExporter.java:
223)
at
org.gwtwidgets.server.spring.GWTRPCServiceExporter.handleInvocationTargetException(GWTRPCServiceExporter.java:
256)
at
org.gwtwidgets.server.spring.GWTRPCServiceExporter.processCall(GWTRPCServiceExporter.java:
344)
... 27 more
Caused by: java.lang.NullPointerException
at javax.servlet.GenericServlet.getServletContext(GenericServlet.java:
160)
at
gwt.spring.serverlibrary.server.GreetingServiceImpl.greetServer(GreetingServiceImpl.java:
14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.gwtwidgets.server.spring.GWTRPCServiceExporter.invokeMethodOnService(GWTRPCServiceExporter.java:
169)
at
org.gwtwidgets.server.spring.GWTRPCServiceExporter.processCall(GWTRPCServiceExporter.java:
338)
... 27 more
[ERROR] 500 - POST /activities/services/activityService (127.0.0.1) 57
bytes
Request headers
Host: localhost:8888
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:
1.9.1.8) Gecko/20100202 Firefox/3.5.8
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/
*;q=0.8
Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://localhost:8888/activities/hosted.html?activities
X-GWT-Permutation: HostedMode
X-GWT-Module-Base: http://localhost:8888/activities/
Content-Type: text/x-gwt-rpc; charset=utf-8
Content-Length: 178
Pragma: no-cache
Cache-Control: no-cache
Response headers
Content-Type: text/plain

my web.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<servlet>


<servlet-name>activities</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</
servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>activities</servlet-name>
<url-pattern>/activities/services/*</url-pattern>
</servlet-mapping>

<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>Activities.html</welcome-file>
</welcome-file-list>

</web-app>

my activities-servlet.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://
www.springframework.org/dtd/spring-beans.dtd">
<beans>

<bean id="activityService"
class="gwt.spring.serverlibrary.server.GreetingServiceImpl" />


<bean id="urlMapping" class="org.gwtwidgets.server.spring.GWTHandler">
<property name="mappings">
<map>
<entry key="/activityService" value-ref="activityService" />
</map>
</property>
</bean>

</beans>

and in my service interface: @RemoteServiceRelativePath("services/
activityService")

i had test all the cases and i am really getting worried
what is my fault

David C. Hicks

unread,
Mar 10, 2010, 1:55:05 PM3/10/10
to gwt...@googlegroups.com
Arous,

It's hard to tell what might be the problem without seeing all of the code.  One of the unfortunate parts of this method of service binding is that the configuration is spread across 3 or 4 different sources.  Let me see the following files, please:

  • service interface (ActivityService.java?)
  • web.xml
  • dispatcher servlet config xml (activities-servlet.xml?)
  • GWT module config (Activities.gwt.xml?)
Perhaps we can figure out what the problem is from those files.
Dave


zizou84

unread,
Mar 10, 2010, 4:57:17 PM3/10/10
to gwt-sl
Hi David
the exemple looks now working but only in developpment mode
in web mode, i am getting yhis message:

Etat HTTP 404 - Servlet activities n'est pas disponible.

i don't know why my servlet
org.springframework.web.servlet.DispatcherServlet isn't found
i have include all the necessar jar in the war/WEB-INF/lib folder

David C. Hicks

unread,
Mar 10, 2010, 5:07:35 PM3/10/10
to gwt...@googlegroups.com
I would suggest you make sure to turn on logging in your web.xml. Make
sure that Spring is getting all of its configuration loaded properly by
checking the logs after the application starts on your server.

There are dozens of reasons why it might not find the servlet. If it's
working in Dev mode for you, you probably have some kind of
configuration problem on your app container.

zizou84

unread,
Mar 10, 2010, 5:20:02 PM3/10/10
to gwt-sl
how could i turn on logging in my web.xml
Another thing, in the gwt-sl FAQ, i red that the project does not run
with the hosted mode browser
but in my case, it is running on the developpmnet mode?!

David C. Hicks

unread,
Mar 10, 2010, 5:24:13 PM3/10/10
to gwt...@googlegroups.com
It works just fine in the hosted mode browser. I think the FAQ is out
of date.

To get logging turned on, add a log4j.xml file and the log4j listener in
your web.xml. Like this...

<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

Here's an example log4j.xml file:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n" />
</layout>
</appender>
<root>
<priority value="info"></priority>
<appender-ref ref="stdout" />
</root>
<logger name="org.mypackages">
<priority value="debug"/>
<appender-ref ref="stdout"/>
</logger>
</log4j:configuration>

zizou84

unread,
Mar 10, 2010, 5:54:26 PM3/10/10
to gwt-sl
Thank you David very much
the problem disappears when i have added the common-logging and log4j
API
i don't really know why they they are necessar!
Reply all
Reply to author
Forward
0 new messages