My favorites | Sign in
Google
                
New issue | Search
for
| Advanced search | Search tips
Issue 389: Refactor RPC out of RemoteServiceServlet
13 people starred this issue and may be notified of changes. Back to list
Status:  Fixed
Owner:  mmendez@google.com
Closed:  May 2007
Type-Enhancement
Priority-Low
Category-RPC
Milestone-1_4_RC


Sign in to add a comment
 
Reported by g.georgovassilis, Nov 10, 2006
GWT Release: future

Detailed description:
I perceive RPC as a communication infrastructure between the client and the
server. While the client is free to look up any services and invoke freely
any of their methods, services are bound to extending the
RemoteServiceServlet placing great restrictions on inheritance and
dependence. I propose that the RPC mechanism is factored out as a class
which can be invoked later. Several ways would be possible like:

RPC.invoke(servletRequest, servletResponse, service);

or

String response = RPC.invoke(rpcContentAsString, service);

or (why not?)

Invocation inv = RPC.resolve(servletRequest);
Object response = inv.getMethod().invoke(service, inv.getArguments());
RPC.respond(response, servletResponse);

Workaround if you have one:


Links to the relevant GWT Developer Forum posts:

Comment 1 by miroslav.pokorny, Nov 12, 2006
I personally just have my rpc service servlet impl delegate to the real impl with
both implementing the interface. Its a minor inconvenience. It keeps things simple
and avoids the need for introducing a controller.

I realise you have already achieved this with your spring rpc controller package, i
suppose such a feature would make that obsolete... :)
Comment 2 by g.georgovassilis, Nov 13, 2006
70% of the code in the GWTHandler is about ripping RPC off RemoteServiceServlet in a
(hopefully) future-safe way and only the rest is about actually providing spring
integration. I'd gladly sacrifice wealth & glory for a simple, open and accessible
RPC impl.
Comment 3 by gwt.team.vli, Nov 15, 2006
(No comment was entered for this change.)
Owner: gwt.team.mmendez
Labels: -Type-Defect -Priority-Medium Type-Enhancement Priority-Low
Comment 4 by rjellinghaus, Nov 22, 2006
Another implementation strategy for this would be to have something like
RemoteServiceDelegatingServlet, an alternate implementation of RemoteServiceServlet.
 RemoteServiceDelegatingServlet would have the following key method:

public abstract class RemoteServiceDelegatingServlet {
    // ... all the standard GWT RemoteServiceServlet methods ...
    public abstract Object invoke (String method, Object[] args);

}

If your server-side servlet mapping was to a subclass of
RemoteServiceDelegatingServlet, GWT would do its normal generic deserialization (in
the base RemoteServiceDelegatingServlet class), then it would call "Object
serviceMethodReturnValue = this.invoke(methodName, arguments)".  This would then
do... well, whatever the service author wants, generally delegate via trivial
reflection to a specific server-side implementation component.  Then 
RemoteServiceDelegatingServlet would do the normal serialization and return the
response. 

I only suggest this because I'm not exactly sure what George means by the
"RPC.invoke" method above -- I don't see quite how that integrates with the existing
GWT servlet infrastructure.  But then again George already implemented this and I
didn't, so it's probably my problem :-)

See
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/9a4b8ff450151b31/5b7ffd06298981e1#5b7ffd06298981e1
Comment 5 by rjellinghaus, Jan 08, 2007
I am starting to work on this (
http://groups.google.com/group/Google-Web-Toolkit-Contributors/browse_thread/thread/8f1140184070548f
) -- if anyone else is also, please reply to the above thread or post a comment here?

My plan is to refactor RemoteServiceServlet into an abstract superclass
DelegatingServiceServlet, and a concrete subclass RemoteServiceServlet which will be
100% compatible with the current version.  Basically DelegatingServiceServlet will
have an abstract method something like "protected abstract Object
fetchServiceDelegate (HttpRequest request);" which RemoteServiceServlet implements as
"return this;".  

Then all the existing interface lookup logic will live in DelegatingServiceServlet
and will do all the method lookup off the result of fetchServiceDelegate.  

Net result:  RemoteServiceServlet works exactly as it did previously, but any
server-side implementors who want to can instead subclass DelegatingServiceServlet,
and override fetchServiceDelegate to return whatever existing server-side component
they like.  Should let George get rid of the 70% of his GWTHandler code that he
doesn't want, and should allow g4jsf to have a much more GWT-like RPC mechanism (I
will be patching g4jsf to prove that concept as part of this work).

Comments welcome.
Comment 6 by g.georgovassilis, Jan 08, 2007
Yes!
Comment 7 by rjellinghaus, Jan 12, 2007
Here is a proposed patch.  I've refactored RemoteServiceServlet and split big bits of
it into three new classes (RPC, RPCCall, and DelegatingServiceServlet, all in the
same package).  I'm appending all four classes since what I want now is code review.
 This is not yet ready for final submission!

See the link to the above GWT-Contributors thread for more discussion on this.
RemoteServiceServlet.java
3.6 KB Download
DelegatingServiceServlet.java
15.0 KB Download
RPC.java
4.4 KB Download
RPCCall.java
8.5 KB Download
Comment 8 by rjellinghaus, Jan 12, 2007
Whoops, I left the license header off of DelegatingServiceServlet.java.  Sorry about
that!  Not intentional!  Like I said, not ready for final submission :-)
Comment 9 by rjellinghaus, Jan 23, 2007
OK, now I think it's ready for final submission.  Please review.

I am considering making a test of exception throwing (by extending the existing
RemoteServiceServletTest).  If that would be helpful to getting this patch accepted,
please advise.

BaseServiceServlet.java
14.0 KB Download
RemoteServiceServlet.java
6.1 KB Download
RPC.java
4.4 KB Download
RPCCall.java
8.5 KB Download
Comment 10 by rjellinghaus, Jan 23, 2007
Here is svn diff of RemoteServiceServlet.java against revision 259.  If I should
generate a patch against head, please advise, but I don't think
RemoteServiceServlet.java has moved at all in 1.3.
RemoteServiceServlet.java-r259-patch
22.9 KB Download
Comment 11 by rjellinghaus, Jan 29, 2007
After 28 postings and about 20 pages of discussion on GWT-Contributors, here is an
extensively revised patch.  Hopefully this is nearing submittability.  It passes "ant
test" in trunk (of course).  The package.html is from com.google.gwt.user.server.rpc.
RemoteServiceServlet.java
13.8 KB Download
RPC.java
17.5 KB Download
RPCRequest.java
1.4 KB Download
UnexpectedException.java
1.1 KB Download
package.html
1.5 KB Download
Comment 12 by rjellinghaus, Jan 29, 2007
:-(   There was a bug in RPC.java.  Here is the complete patch again with the bug
corrected.  *Now* it passes "ant test" in trunk.  My apologies.
Comment 13 by rjellinghaus, Jan 29, 2007
...
RemoteServiceServlet.java
13.8 KB Download
RPC.java
17.5 KB Download
RPCRequest.java
1.4 KB Download
UnexpectedException.java
1.1 KB Download
package.html
1.5 KB Download
RemoteServiceServlet.java-r259-patch-2
29.9 KB Download
Comment 14 by rjellinghaus, Jan 30, 2007
Aaaand, one minor error in a comment and in the package.html file.  Uploading all
files again to avoid any confusion about the complete patch contents.
RemoteServiceServlet.java
13.8 KB Download
RPC.java
17.5 KB Download
RPCRequest.java
1.4 KB Download
UnexpectedException.java
1.1 KB Download
package.html
1.6 KB Download
RemoteServiceServlet.java-r259-patch-3
30.0 KB Download
Comment 15 by rjellinghaus, Jan 30, 2007
...missed *one more* comment.  This time, uploading only the affected file.  The
other five files above, in comment #14, are fine.  (The error was stating the wrong
HTTP status code for failure responses.)
RemoteServiceServlet.java
13.8 KB Download
Comment 16 by gwt.team.morrildl, Feb 01, 2007
(No comment was entered for this change.)
Labels: Category-RPC
Comment 17 by rjellinghaus, Feb 03, 2007
Fixed many checkstyle errors, though not all (I believe the remaining ones are due to
issues with my local environment alone, see the GWT-Contributors thread on  issue
389 ).  This patch was generated with "svn diff" in
trunk/user/src/com/google/gwt/user/server/rpc after updating trunk to revision 353. 
I have also attached a zip of the files in that directory for reference.
com.google.gwt.user.server.rpc.patch
30.7 KB Download
rpc.zip
21.7 KB Download
Comment 18 by rjellinghaus, Feb 03, 2007
Omitted to "svn add" new files before running "svn diff".  This patch fixes that.
com.google.user.server.rpc.patch
51.8 KB Download
Comment 19 by rjellinghaus, Feb 05, 2007
Latest patch incorporating Miguel's feedback.  As above, generated with "svn diff" in
trunk/user/src/com/google/gwt/user/server/rpc at revision 353.
com.google.gwt.user.server.rpc.4.patch
60.0 KB Download
rpc.4.zip
26.8 KB Download
Comment 20 by rjellinghaus, Feb 06, 2007
The only thing worse than uploading a buggy patch is not finding the bug yourself! 
The decodeRequest(String) method was bugged; it did not properly short-cut the check
for whether the interface itself implemented RemoteService.  Fixed in
isImplementedRemoteServiceInterface, and verified by testing with the g4jsf
integration.  Looks like this needs a unit test... exception handling probably does
too.  I may create a separate issue for that, though....
com.google.gwt.user.server.rpc.5.patch
53.5 KB Download
rpc.5.zip
25.6 KB Download
Comment 21 by rjellinghaus, Feb 06, 2007
Ready for final review!  The handleFailure method is now called onUnexpectedFailure,
and the RemoteServiceServlet.doPost method is nice and minimal now.

com.google.gwt.user.server.rpc.6.patch
52.5 KB Download
rpc.6.zip
25.5 KB Download
Comment 22 by gwt.team.morrildl, Feb 18, 2007
(No comment was entered for this change.)
Labels: Milestone-1_4_RC
Comment 23 by gwt.team.mmendez, Mar 22, 2007
Good job Rob.
Status: FixedNotReleased
Comment 24 by gwt.team.bruce, May 29, 2007
Changing to Fixed status with GWT 1.4 RC release
Status: Fixed
Comment 25 by dandante, Jun 02, 2007
I realize it's too late for 1.4, but what if the RPC mechanism was
abstracted/generalized even further, so that the back end does not even have to be
java? Is this even possible? It may be heretical even to suggest this (not that I
care) but I would love to be able to use a GWT front-end with a Rails back end. JRuby
could be the glue here, but if the RPC mechanism was generic enough, it would not
need to depend on a particular language; simply use JSON for object serialization....
Comment 26 by sumitcha...@google.com, Apr 28, 2008
 
Owner: mmendez
Sign in to add a comment