Tomcat Reset and RPC error

245 views
Skip to first unread message

nicco

unread,
Jan 11, 2008, 7:35:31 AM1/11/08
to Google Web Toolkit
Hi to everyone,

I developed some applications for gwt and I never had many problems in
publishing them with tomcat but now I'm getting some problems with
tomcat that r making me mad.

I've created an application that uses RPC provided by GWT. If i put it
in my tomcat server webapp diectory (using a war package) it works
well but then in the night (around 6 am) tomcat reset itself in some
way and the application does not perform anymore any RPC call and
instead rises the following exception:

Jan 11, 2008 11:57:09 AM org.apache.catalina.core.ApplicationContext
log
SEVERE: Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method
'public abstract java.util.Vector
com.novacom.novacalendar.client.Remote.query(java.lang.String,java.lang.String)'
threw an unexpected exception: java.lang.NullPointerException
at
com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:
361)
at
com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:
547)
at
com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:
265)
at
com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java:
187)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:
710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:
803)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:
233)


If I reboot tomcat the applicaton works well...

does someone have some hints for me?
thanks

nicco

Charlie Collins

unread,
Jan 11, 2008, 8:57:36 AM1/11/08
to Google Web Toolkit
What if you change the clock on the machine to after midnight, just as
a test.

Only a hunch, but you are getting an NPE in a class that I am guessing
does something with date/time (novacalendar package). Is there any
chance it's related to a bug in your code that only happens after the
next day rolls around (again, just a guess, not much detail here)?

In any case it's not a Tomcat problem, it's clearly in
com.novacom.novacalendar.client.Remote.

nicco

unread,
Jan 13, 2008, 6:31:06 AM1/13/08
to Google Web Toolkit
Hi, thanks to your reply,

the problem does not seem to be related to a time problem because the
application does not change any time, it just connects to a database.

The problem unfortunately seems to be more complex because I have
another application created before that runs the same code and works
perfectly.
Novacalendar was created after renaming the fist application into
novacalendar. The class remote (that creates the rpc connection) is
the same in both the applications.

the exception unfortunately seems raised from the gwt compiler....
What I cannot understand is why the applicaion works perfectly for a
couple of hours and then crashes....

thanks


On Jan 11, 2:57 pm, Charlie Collins <charlie.coll...@gmail.com> wrote:
> What if you change the clock on the machine to after midnight, just as
> a test.
>
> Only a hunch, but you are getting an NPE in a class that I am guessing
> does something with date/time (novacalendar package). Is there any
> chance it's related to a bug in your code that only happens after the
> next day rolls around (again, just a guess, not much detail here)?
>
> In any case it's not aTomcatproblem, it's clearly in
> com.novacom.novacalendar.client.Remote.
>
> On Jan 11, 7:35 am, nicco <nicc...@gmail.com> wrote:
>
> > Hi to everyone,
>
> > I developed some applications for gwt and I never had many problems in
> > publishing them withtomcatbut now I'm getting some problems with
> >tomcatthat r making me mad.
>
> > I've created an application that usesRPCprovided by GWT. If i put it
> > in mytomcatserver webapp diectory (using a war package) it works
> > well but then in the night (around 6 am)tomcatresetitself in some
> > way and the application does not perform anymore anyRPCcall and
> > If I reboottomcatthe applicaton works well...

nicco

unread,
Jan 13, 2008, 6:37:58 AM1/13/08
to Google Web Toolkit
to say something more correct the exception is rised from the code
genereted by the gwt comiler, the one that maps the RPC class (where
you create the abstract methods) in the client package to it's
implementation in the server package

here is the code:


package com.novacom.novacalendar.client;

import java.io.Serializable;
import java.util.Vector;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.novacom.novacalendar.model.ListValues;

public interface Remote extends RemoteService {
/**
* Utility class for simplifying access to the instance of async
service.
*/
public static class Util {
private static RemoteAsync instance;
public static RemoteAsync getInstance(){
if (instance == null) {
instance = (RemoteAsync) GWT.create(Remote.class);
ServiceDefTarget target = (ServiceDefTarget) instance;
target.setServiceEntryPoint(GWT.getModuleBaseURL() + "Remote");
}
return instance;
}
}
public void insertOrUpdate(Serializable object);
public void delete(String table,int id);
public Vector query(String className,String query);
public Serializable getObject(String className, int id);
public ListValues getListValues(int callingObj,String listName);
}

the first part of the code was created by the RPC class generator of
GWTDesigner...

nicco

unread,
Jan 13, 2008, 10:02:38 AM1/13/08
to Google Web Toolkit
Hi

I think I found the problem and it's not related to what I've said in
my previous post. It's a null pointer exception generated by a line of
code in the server package that creates a statement in mysql.

s = con.createStatement();

the connection is null (don't know why) so the rpc process crashes.

The big problem is that even reloading the page the rpc does not work
because con is null.

con is instantiates at the first execution of the serverside code in
this method

public void createSession() {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();

} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
con = DriverManager.getConnection("jdbc:mysql://localhost/Db",
"user","pass");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


I have now to understand:

why con is null if it was instantiated in previous lines.
why even reloading the application I can't instantiate con.
why this happen in between after several hours of correct work
why an application with the same code running in the same server but
connecting to a different database does not suffer from this problem

if you have some ideas... they are all welcome

Charlie Collins

unread,
Jan 13, 2008, 5:14:46 PM1/13/08
to Google Web Toolkit
Are any of those exceptions getting caught and logged, specifically
the SQLException after DriverManager.getConnection? (Could be that
the DB is down/flaky/exhausted, etc, in which case you would get a
SQLException and a null con.)

nicco

unread,
Jan 13, 2008, 7:37:38 PM1/13/08
to Google Web Toolkit
hi unfortunately no exception related to the database and the strange
thing is that if I just restart tomcat the application works again
without restarting Mysql

the exception is


GRAVE: Exception while dispatching incoming RPC
callcom.google.gwt.user.server.rpc.UnexpectedException: Service method
'public abstract java.util.Vector
com.novacom.novacalendar.client.Remote.query(java.lang.Stri
ng,java.lang.String)' threw an unexpected exception:
java.lang.NullPointerException
at
com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:
361)
at
com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:
547)
at
com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:
265)
at
com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServ
iceServlet.java:187)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:
710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:
803)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290) at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:
233)

at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:
102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:
109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
263)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:
844)
at org.apache.coyote.http11.Http11Protocol
$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint
$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException

HERE IS THE PROBLEM:

at com.novacom.novacalendar.server.DbUtil.query(DbUtil.java:
349)



at
com.novacom.novacalendar.server.RemoteImpl.query(RemoteImpl.java:33)
at sun.reflect.GeneratedMethodAccessor37.invoke(Unknown
Source)
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:
528)
... 16 more


but there is the line the code points out:


Statement s=null;
try {
s = con.createStatement();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
--> ResultSet result = s.executeQuery(query);


before the error was in the line s = con.createStatement(); but now
i've forced a new instantiation of con if it was null...

How can s be null if I just instanciated it? and the strange thing
that this happends after midnight......

no idea at all about what's going on...


nicco

unread,
Jan 13, 2008, 8:12:59 PM1/13/08
to Google Web Toolkit
probably that's what happends:

24.4.5.3.4: I have a servlet/application that works fine for a day,
and then stops working overnight

MySQL closes connections after 8 hours of inactivity. You either need
to use a connection pool that handles stale connections or use the
"autoReconnect" parameter (see Section 23.4.4.1, "Driver/Datasource
Class Names, URL Syntax and Configuration Properties for Connector/
J").

Also, you should be catching SQLExceptions in your application and
dealing with them, rather than propagating them all the way until your
application exits, this is just good programming practice. MySQL
Connector/J will set the SQLState (see
java.sql.SQLException.getSQLState() in your APIDOCS) to "08S01" when
it encounters network-connectivity issues during the processing of a
query. Your application code should then attempt to re-connect to
MySQL at this point.


I've added "?autoReconnect=true" to the connection string... let's
see!

Charlie Collins

unread,
Jan 14, 2008, 10:41:02 AM1/14/08
to Google Web Toolkit
Make sure that you are also closing the connections on your own? (Also
really, using some pooling stuff would be a good idea, even the built
in Tomcat DB pooling capabilities, might want to look into that).

nicco

unread,
Jan 14, 2008, 2:53:44 PM1/14/08
to Google Web Toolkit
hi!

so i've put a listener for the application that checks ehen i'm
closing the window and closes the connection... but it still does not
work... also adding ?autoReconnect=true does not work.... so what do
you mean by using some pooling stuff??

thanks

Charlie Collins

unread,
Jan 15, 2008, 8:20:51 AM1/15/08
to Google Web Toolkit
I am not sure how you are using your database connections, but they
should have nothing to do with the window, and not need a listener?
You want to do data stuff on the server side, fill out a DTO, close
the connection, then transfer the DTO to the client - in general
anyway.

As for connection pool "stuff," there are many many approaches and
tools, including Commons DBCP, which is basically included in Tomcat.
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html#Database%20Connection%20Pool%20(DBCP)%20Configurations

It depends which version of Tomcat your are using on how the setup is
done (very different in 5.0.x, which is what GWT hosted mode uses,
verses 5.5.x and 6.x), but in all versions you can configure
datasource pooling, so that the container creates/closes/handles db
resources for you, rather than you having to do it manually. That may
help if the problem is related to resources being exhausted or such
(which it still isn't really clear that it is, but it's possible).
Reply all
Reply to author
Forward
0 new messages