Deploying GWT RPC servlet as a separate WAR

212 views
Skip to first unread message

Uros Trebec

unread,
Oct 7, 2009, 1:23:44 PM10/7/09
to Google Web Toolkit
Hi there!

I was wondering if there is in any way possible to package and deploy
GWT-RPC servlet as a stand-alone WAR application, without client side
JS & resources?

Basically what I want to do is have a client-side JS & resurces
deployable separately from the servlet, so the servlet application
wouldn't be redeployed every time I compile and deploy generated JS.

Any suggestions?

Best regards,
Uros

Chris Ramsdale

unread,
Oct 9, 2009, 9:22:05 AM10/9/09
to google-we...@googlegroups.com
Uros,

If you are using GWT style RPC you won't be able to decouple the client/server relationship as the GWT compiler needs to know about (and compile) both sides in order for the application to be built. You may want to take a look at GWT's RequestBuilder class (link below) that allows you to build GWT based client apps that communicate with a server that may or may not be GWT based and are ultimately compiled and deployed without having to do the same with the server.

RequestBuilder Class

Thanks,
- Chris


Sripathi Krishnan

unread,
Oct 11, 2009, 7:35:06 PM10/11/09
to google-we...@googlegroups.com
You should be able to decouple.

  1. Split your code into three logical packages - client, server and shared.
    • client package has all UI code
    • shared has the RemoteService and corresponding Async Interfaces, plus any Serializable classes needed  for the communication between client and server
    • server has the RPC Servlets, plus any other code needed for server components.
  2. Run GWT on client and shared packages. You may want to include a <source path='shared'/> and <source path='client'/> lines to your module.gwt.xml. Also, during compilation of gwtc, you don't need gwt-servlet.jar in your claspath.
  3. When you are compiling server side code, make sure to include java files from shared folder. Your classpath should include gwt-server.jar, but it doesn't need the client side jar files.
  4. When you bundle your war, gwt-serlvet.jar needs to be present in the lib folder.

--Sri


2009/10/9 Chris Ramsdale <cram...@google.com>

Saurabh

unread,
Nov 5, 2009, 6:08:20 PM11/5/09
to Google Web Toolkit
Even if the RPC Servlets are separate from the UI code, how would you
let your Async service code know the URL of the RPC servlets which may
be deployed in a different tomcat container all together?

On Oct 11, 6:35 pm, Sripathi Krishnan <sripathi.krish...@gmail.com>
wrote:
> You should be able to decouple.
>
>    1. Split your code into three logical packages - client, server and
>    shared.
>       - client package has all UI code
>       - shared has the RemoteService and corresponding Async Interfaces,
>       plus any Serializable classes needed  for the communication
> between client
>       and server
>       - server has the RPC Servlets, plus any other code needed for server
>       components.
>    2. Run GWT on client and shared packages. You may want to include a
>    <source path='shared'/> and <source path='client'/> lines to your
>    module.gwt.xml. Also, during compilation of gwtc, you don't need
>    gwt-servlet.jar in your claspath.
>    3. When you are compiling server side code, make sure to include java
>    files from shared folder. Your classpath should include gwt-server.jar, but
>    it doesn't need the client side jar files.
>    4. When you bundle your war, gwt-serlvet.jar needs to be present in the
>    lib folder.
>
> --Sri
>
> 2009/10/9 Chris Ramsdale <cramsd...@google.com>
>
> > Uros,
> > If you are using GWT style RPC you won't be able to decouple the
> > client/server relationship as the GWT compiler needs to know about (and
> > compile) both sides in order for the application to be built. You may want
> > to take a look at GWT's RequestBuilder class (link below) that allows you to
> > build GWT based client apps that communicate with a server that may or may
> > not be GWT based and are ultimately compiled and deployed without having to
> > do the same with the server.
>
> > RequestBuilder Class
>
> >http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/g...
>
> > Thanks,
> > - Chris

Sripathi Krishnan

unread,
Nov 5, 2009, 7:15:01 PM11/5/09
to google-we...@googlegroups.com
You just put a @RemoteServiceRelativePath("/path/to/servlet") annotation in your RPC interface. It just needs the url, not the actual servlet class that is implementing it - so you are still separating the ui code and the server code.

Or am I completely missing your point?

 
--Sri


2009/11/5 Saurabh <saurab...@citi.com>

Saurabh

unread,
Nov 5, 2009, 9:01:28 PM11/5/09
to Google Web Toolkit
Sri
So consider the scenario where I have two WAR files: First WAR file
contains the RPC service and the contextpath is /allservices and
Second WAR file contains all the generated module code+a-whole-lot-of-
other-stuff. Second WAR file has a context /mycontent The GWT
generated JS is being served from the second WAR file.

The problem that I am facing is that when I get the service using
GWT.create and then modify the ServiceDef using
ServiceDefTarget.setEntry...

I then run into seriliazation issues. Root cause of this issue is that
when an RPC call is being made from WAR2 to WAR1 RPC service, the
moduelBaseURL is different from the contextPath. There is line in
RemoteServiceServlet that goes like this:

if (modulePath == null || !modulePath.startsWith(contextPath))

This check ensures that RPC WAR cannot be separate from rest of the
module. modulePath which is moduleBaseURL passed in the RPC request is
not the same as contextPath. That is always going to be the case,
unless there is an explict way to configure moduleBaseURL for RPC
request.

-Saurabh

On Nov 5, 7:15 pm, Sripathi Krishnan <sripathi.krish...@gmail.com>
wrote:
> You just put a @RemoteServiceRelativePath("/path/to/servlet") annotation in
> your RPC interface. It just needs the url, not the actual servlet class that
> is implementing it - so you are still separating the ui code and the server
> code.
>
> Or am I completely missing your point?
>
> --Sri
>
> 2009/11/5 Saurabh <saurabh.gu...@citi.com>

Saurabh

unread,
Nov 6, 2009, 12:14:29 AM11/6/09
to Google Web Toolkit
I think overriding RemoteServiceServlet.doSerializationGetPolicy
method might help. Anyways, interesting read on this topic are

http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/c5f77dee8cc3ddb3
http://code.google.com/p/google-web-toolkit/issues/detail?id=1863&q=rpc&sort=-type
Reply all
Reply to author
Forward
0 new messages