Hi, im writting the code for a console using GWT and Spring integration. I have followed GWT tutorial and read some forums about how to use spring qith GWT.
I'm at the point that the RPC call is returning null and i can't seem to see why. As english is not my native language and i'm pretty new to this, I'm just going to put my code here to see if someone can help me with it.
Service:
@RemoteServiceRelativePath("GestionUserService")public interface GestionUserService extends RemoteService {Collection<Usuario> dameTablaUsuarios(String entidad);}
Async:
public interface GestionUserServiceAsync {void dameTablaUsuarios(String entidad,AsyncCallback<Collection<Usuario>> callback);}
Impl:
@SuppressWarnings("serial")@Service("GestionUserService")public class GestionUsersConsultImpl extends RemoteServiceServlet implements GestionUserService {@AutowiredUserConsoleDBUtil utilDB;Logger logger = Logger.getLogger(GestionUsersConsultImpl.class);@SuppressWarnings("unchecked")public Collection<Usuario> dameTablaUsuarios(String entidad) {GWT.log("Log");logger.info("He llegado al IMPL dameTablaUsuarios.======================="+entidad);logger.info("UtilDB "+utilDB.toString());return utilDB.getDao().getUsuarios(entidad);}}
*gwt.xml:
<?xml version="1.0" encoding="UTF-8"?><module rename-to='userConsole'><!-- Inherit the core Web Toolkit stuff. --><inherits name='com.google.gwt.user.User' /><!-- Compilar solamente para Firefox --><!--<set-property name="user.agent" value="gecko1_8"></set-property> --><inherits name='com.google.gwt.user.theme.standard.Standard' /><inherits name="com.google.gwt.i18n.I18N" /><!-- Specify the app entry point class. --><entry-point class='com.santander.bam.comun.userconsole.client.GestionUsers' /><!-- English language, independent of country --><extend-property name="locale" values="es_ES" /><extend-property name="locale" values="en_US" /><extend-property name="locale" values="de_DE" /><!-- Specify the application specific style sheet. --><stylesheet src='UserConsole.css' /><!-- Specify the paths for translatable code --><source path='client' /><source path='client/services' /><source path='db/bean' /></module>
applicationContext.xml:
<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"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:task="http://www.springframework.org/schema/task" xmlns:util="http://www.springframework.org/schema/util"xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsdhttp://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsdhttp://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsdhttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"><!-- Agregado de la consola gwt-spring --><!-- Activates scanning of @Autowired --><context:annotation-config /><context:component-scan base-package="com.santander.bam.comun.userconsole" /><!-- FIN Agregado de la consola gwt-spring --><import resource="config.xml" /><util:constant id="VARCHAR" static-field="java.sql.Types.VARCHAR" /><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="myDataSource"/></bean><bean id="GestionUserService" class="com.santander.bam.comun.userconsole.server.GestionUsersConsultImpl"></bean><bean id="utilDB" class="com.santander.bam.comun.userconsole.db.UserConsoleDBUtil"><property name="dao" ref="UserConsoleDAO" /><property name="transactionManager" ref="transactionManager"/></bean></beans>
config.xml
<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"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:task="http://www.springframework.org/schema/task" xmlns:util="http://www.springframework.org/schema/util"xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsdhttp://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsdhttp://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsdhttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"><bean id="UserConsoleDAO" class="com.santander.bam.comun.userconsole.db.UserConsoleDAO"><property name="dataSource" ref="myDataSource" /><!-- Definicion de consultas --><property name="sqlUsuarios"value=" SELECT DISTINCT (IDUSER) IDUser,NOMBRE Nombre,IDPerfil IDPerfil,FECHAALTA FechaAlta,FECHABAM FechaBAM,FECHACON FechaConsolaFROMA_APAMA.USERSWHEREEMPRESA=?" /><property name="sqlUsuarios2"value=" SELECT DISTINCT (IDUSER) IDUserFROMA_APAMA.USERSWHEREEMPRESA=?" /></bean><bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource"destroy-method="close"><property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver" /><property name="url"value="jdbc:db2://udisapma.isban.dev.corp:60090/udisapma" /><property name="username" value="a_apama" /><property name="password" value="********" /></bean><bean id="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="myDataSource" /></bean></beans>
And finally my web.xml:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE web-appPUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN""http://java.sun.com/dtd/web-app_2_3.dtd"><web-app><context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/applicationContext.xml</param-value></context-param><!-- Loads and makes available the context defined in springconfig-service.xml --><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><servlet><servlet-name>springGwtRemoteServiceServlet</servlet-name><servlet-class>org.spring4gwt.server.SpringGwtRemoteServiceServlet</servlet-class></servlet><servlet><servlet-name>gestionUsersConsultImpl</servlet-name><servlet-class>com.santander.bam.comun.userconsole.server.GestionUsersConsultImpl</servlet-class></servlet><servlet-mapping><servlet-name>springGwtRemoteServiceServlet</servlet-name><url-pattern>/springGwtServices/*</url-pattern></servlet-mapping><servlet-mapping><servlet-name>gestionUsersConsultImpl</servlet-name><url-pattern>/userConsole/GestionUserService</url-pattern></servlet-mapping><!-- Default page to serve --><welcome-file-list><welcome-file>GestionUsers.html</welcome-file></welcome-file-list><!-- Paginas de error --><error-page><error-code>401</error-code><location>/accessDeny.html</location></error-page><error-page><error-code>500</error-code><location>/serverError.html</location></error-page></web-app>
In my main class i have this:
AsyncCallback<Collection<Usuario>> getUserID2 = new AsyncCallback<Collection<Usuario>>() {// Failure: muestra errorpublic void onFailure(Throwable caught) {whatever;}// Succes: obtener usuariopublic void onSuccess(Collection<Usuario> Users) {Whatever;}};gestionUservc.dameTablaUsuarios("3293", getUserID2);
Thanks in advanced for taking the time to analize this and try to help me.
Borja.
Edit: In case its usefull here is the error:
com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract java.util.Collection com.santander.bam.comun.userconsole.client.GestionUserService.dameTablaUsuarios(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.invokeAndEncodeResponse(RPC.java:581) at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:207) at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:243) at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62) 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: java.lang.NullPointerException: null at com.santander.bam.comun.userconsole.server.GestionUsersConsultImpl.dameTablaUsuarios(GestionUsersConsultImpl.java:31) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:562) at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:207) at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:243) at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62) 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)
Edit 2: And here whay my log is saying:
2013-02-25 16:20:02,424 INFO [org.springframework.web.context.ContextLoader] - Root WebApplicationContext: initialization started
2013-02-25 16:20:02,453 INFO [org.springframework.web.context.support.XmlWebApplicationContext] - Refreshing Root WebApplicationContext: startup date [Mon Feb 25 16:20:02 CET 2013]; root of context hierarchy
2013-02-25 16:20:02,496 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
2013-02-25 16:20:02,696 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from ServletContext resource [/WEB-INF/config.xml]
2013-02-25 16:20:02,724 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Overriding bean definition for bean 'transactionManager': replacing [Generic bean: class [org.springframework.jdbc.datasource.DataSourceTransactionManager]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in ServletContext resource [/WEB-INF/config.xml]] with [Generic bean: class [org.springframework.jdbc.datasource.DataSourceTransactionManager]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in ServletContext resource [/WEB-INF/applicationContext.xml]]
2013-02-25 16:20:02,724 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Overriding bean definition for bean 'GestionUserService': replacing [Generic bean: class [com.santander.bam.comun.userconsole.server.GestionUsersConsultImpl]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [D:\Workspace\USER_CONSOLE\target\UserConsole\WEB-INF\classes\com\santander\bam\comun\userconsole\server\GestionUsersConsultImpl.class]] with [Generic bean: class [com.santander.bam.comun.userconsole.server.GestionUsersConsultImpl]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in ServletContext resource [/WEB-INF/applicationContext.xml]]
2013-02-25 16:20:02,803 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3f96ee: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,GestionUserService,UserConsoleDAO,myDataSource,transactionManager,VARCHAR,utilDB]; root of factory hierarchy
2013-02-25 16:20:02,890 INFO [org.springframework.web.context.ContextLoader] - Root WebApplicationContext: initialization completed in 466 ms
2013-02-25 16:20:10,020 INFO [com.santander.bam.comun.userconsole.server.GestionUsersConsultImpl] - He llegado al IMPL dameTablaUsuarios.=======================3293
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment