I'm attempting to introduce Spring into the standard GWT
GreetingService example. I keep getting HTTP Error 500. When testing
different servelet configurations would get HTTP Error 404, but once
corrected went back to HTTP Error 500.
Configuration
- GWT 2.4 in Spring STS Latest Eclipse IDE
- Spring 3.1
- GWT-SL 1.3
Using Standard GWT Plugin Demo Project with Spring Libraries Added
Resolution Steps Taken
1 - Verified Servlet and File Configurations
2 - Tried with and without Spring Annotation Based Instantiation of
RPC Service
3 - Attempted with and without Log4j Inclusion in web.xml as noted on
a couple of posts
File Data and Stack Trace at Bottom
I'm sure there is a simple oversight somewhere, but I've checked
several different configurations and haven't been able to resolve. Any
insight is appreciated.
*********** Web.xml ****************
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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_2_5.xsd"
version="2.5"
xmlns="
http://java.sun.com/xml/ns/javaee">
<listener>
<listener-
class>org.springframework.web.context.ContextLoaderListener</listener-
class>
</listener>
<!-- Front Controller for all GWT-Spring based servlets -->
<servlet>
<servlet-name>gwt</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</
servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Don't forget to declare a gwt-servlet.xml -->
<servlet-mapping>
<servlet-name>gwt</servlet-name>
<url-pattern>/testgwt/rpc/*</url-pattern>
</servlet-mapping>
</web-app>
*********** gwt-servlet.xml ****************
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="
http://www.springframework.org/schema/beans"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="
http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean id="greetingService"
class="com.mattbragaw.testgwt.server.GreetingServiceImpl" />
<!-- The GWT handler. Pay attention to the mappings -->
<bean class="org.gwtwidgets.server.spring.GWTHandler">
<property name="mappings">
<map>
<entry key="/greet" value-ref="greetingService" />
</map>
</property>
</bean>
</beans>
*********** applicationContext.xml ****************
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="
http://www.springframework.org/schema/beans"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="
http://www.springframework.org/schema/context"
xmlns:p="
http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<!-- Activates various annotations to be detected in bean classes -->
<context:annotation-config />
<!-- Scans the classpath for annotated components that will be auto-
registered as Spring beans.
For example @Controller and @Service. Make sure to set the correct
base-package -->
<context:component-scan base-package="com.mattbragaw.testgwt" />
</beans>
*********** GreetingService,java ****************
package com.mattbragaw.testgwt.client;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
/**
* The client side stub for the RPC service.
*/
@RemoteServiceRelativePath("rpc/greet")
public interface GreetingService extends RemoteService {
String greetServer(String name) throws IllegalArgumentException;
}
*********** GreetingServiceAsync,java ****************
package com.mattbragaw.testgwt.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
* The async counterpart of <code>GreetingService</code>.
*/
public interface GreetingServiceAsync {
void greetServer(String input, AsyncCallback<String> callback)
throws IllegalArgumentException;
}
*********** GreetingServiceImpl.java ****************
package com.mattbragaw.testgwt.server;
//import org.springframework.stereotype.Service;
import com.mattbragaw.testgwt.client.GreetingService;
import com.mattbragaw.testgwt.shared.FieldVerifier;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/**
* The server side implementation of the RPC service.
*/
//@Service("greetingService")
public class GreetingServiceImpl extends RemoteServiceServlet
implements
GreetingService {
private static final long serialVersionUID = -7540169356902342398L;
public String greetServer(String input) throws
IllegalArgumentException {
// Verify that the input is valid.
if (!FieldVerifier.isValidName(input)) {
// If the input is not valid, throw an IllegalArgumentException
back to
// the client.
throw new IllegalArgumentException(
"Name must be at least 4 characters long");
}
String serverInfo = getServletContext().getServerInfo();
String userAgent = getThreadLocalRequest().getHeader("User-Agent");
// Escape data from the client to avoid cross-site script
vulnerabilities.
input = escapeHtml(input);
userAgent = escapeHtml(userAgent);
return "Hello, " + input + "!<br><br>I am running " + serverInfo
+ ".<br><br>It looks like you are using:<br>" + userAgent;
}
/**
* Escape an html string. Escaping data received from the client
helps to
* prevent cross-site script vulnerabilities.
*
* @param html the html string to escape
* @return the escaped string
*/
private String escapeHtml(String html) {
if (html == null) {
return null;
}
return html.replaceAll("&", "&").replaceAll("<", "<")
.replaceAll(">", ">");
}
}
*********** JETTY STACK TRACE ON ERROR 500 ****************
SEVERE: javax.servlet.ServletContext log: Exception while dispatching
incoming RPC call
java.lang.RuntimeException:
com.google.gwt.user.server.rpc.UnexpectedException: Service method
'public abstract java.lang.String
com.mattbragaw.testgwt.client.GreetingService.greetServer(java.lang.String)
throws java.lang.IllegalArgumentException' threw an unexpected
exception: java.lang.NullPointerException
at
org.gwtwidgets.server.spring.GWTRPCServiceExporter.handleExporterProcessingException(GWTRPCServiceExporter.java:
456)
at
org.gwtwidgets.server.spring.GWTRPCServiceExporter.processCall(GWTRPCServiceExporter.java:
425)
at
com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:
248)
at
com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:
62)
at
org.gwtwidgets.server.spring.GWTRPCServiceExporter.handleRequest(GWTRPCServiceExporter.java:
478)
at
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:
48)
at
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:
900)
at
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:
827)
at
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:
882)
at
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:
789)
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:
511)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1166)
at
com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:
35)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:
60)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:
43)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:
122)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:
97)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:
388)
at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:
216)
at
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:
182)
at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:
765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:
418)
at
com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:
78)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at com.google.appengine.tools.development.JettyContainerService
$ApiProxyHandler.handle(JettyContainerService.java:362)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
542)
at org.mortbay.jetty.HttpConnection
$RequestHandler.content(HttpConnection.java:938)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:
409)
at org.mortbay.thread.QueuedThreadPool
$PoolThread.run(QueuedThreadPool.java:582)
Caused by: com.google.gwt.user.server.rpc.UnexpectedException: Service
method 'public abstract java.lang.String
com.mattbragaw.testgwt.client.GreetingService.greetServer(java.lang.String)
throws java.lang.IllegalArgumentException' threw an unexpected
exception: java.lang.NullPointerException
at
com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:
385)
at
org.gwtwidgets.server.spring.GWTRPCServiceExporter.encodeResponseForFailure(GWTRPCServiceExporter.java:
302)
at
org.gwtwidgets.server.spring.GWTRPCServiceExporter.handleInvocationTargetException(GWTRPCServiceExporter.java:
327)
at
org.gwtwidgets.server.spring.GWTRPCServiceExporter.processCall(GWTRPCServiceExporter.java:
416)
... 39 more
Caused by: java.lang.NullPointerException
at javax.servlet.GenericServlet.getServletContext(GenericServlet.java:
160)
at
com.mattbragaw.testgwt.server.GreetingServiceImpl.greetServer(GreetingServiceImpl.java:
27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
43)
at java.lang.reflect.Method.invoke(Method.java:601)
at
com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:
104)
at
org.gwtwidgets.server.spring.GWTRPCServiceExporter.invokeMethodOnService(GWTRPCServiceExporter.java:
245)
at
org.gwtwidgets.server.spring.GWTRPCServiceExporter.processCall(GWTRPCServiceExporter.java:
410)
... 39 more