Zn2O / gwt-google-apis

Automatically exported from code.google.com/p/gwt-google-apis
0 stars 0 forks source link

Content-type is stripped when using GWT RPC with iGoogle #154

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Found in Release:
r508

Detailed description:
GWT RPC is not working when using an HTML type gadget in iGoogle as your
gadget container.  (The gwt-gadgets project creates an HTML gadget as its
output.)

You can use this code to change the URL of the RPC service to go through
the gadget container's proxy:

 (GadgetService inherits from RemoteService for an RPC interface)

 gadgetService = GWT.create(GadgetService.class);
 ServiceDefTarget serviceDef = (ServiceDefTarget) gadgetService;
 String rpcUrl =
intrinsicMethods.getCachedUrl(serviceDef.getServiceEntryPoint());
 serviceDef.setServiceEntryPoint(rpcUrl);

On the servlet side you will see a message similar to the following:

javax.servlet.ServletException: Content-Type must be 'text/x-gwt-rpc' with
'char
set=utf-8'.  (got application/x-www-form-urlencoded)

Workaround if you have one:

Here are some workarounds to this problem:

1) Change your gadget spec (your <module>.gadget.xml file) so that the
content is in a separate file, and the <Content> attribute in the spec is
re-written as a URL type of gadget.  

2) Download the GWT source code, make a strategic edit to
RPCServletUtils.java in the GWT distribution to short-circuit the
contentTypeIsOkay check, and rebuild gwt-servlet.jar without the
Content-Type check.

Links to the relevant GWT Developer Forum posts:

Original issue reported on code.google.com by galgwt.reviews@gmail.com on 7 Aug 2008 at 6:32

GoogleCodeExporter commented 9 years ago
internal ref b/1314311

Original comment by galgwt.reviews@gmail.com on 7 Aug 2008 at 6:33

GoogleCodeExporter commented 9 years ago
internal suggestion is to either pass encoding on the query parameter (or 
inline with
the content) or to otherwise loosen up on the RPC check (as already noted.)

Original comment by ericzun...@gmail.com on 18 Aug 2008 at 10:23

GoogleCodeExporter commented 9 years ago
Eric made a change to GWT's RPC servlet to enable the header checks to be 
programatically disabled, since the 
Gadget container strips them off.  This change was committed in r3549, and will 
be included in a post GWT 1.5 
RC2 build.

Original comment by mmendez+personal@google.com on 25 Aug 2008 at 2:57

GoogleCodeExporter commented 9 years ago
Is this fixed in GWT 1.5.2 ?

Original comment by norman.m...@googlemail.com on 12 Sep 2008 at 12:03

GoogleCodeExporter commented 9 years ago
Is this fixed in GWT 1.5.2 ?

Original comment by norman.m...@googlemail.com on 12 Sep 2008 at 12:04

GoogleCodeExporter commented 9 years ago
The necessary changes were included in 1.5.2.

Original comment by mmendez+personal@google.com on 12 Sep 2008 at 12:15

GoogleCodeExporter commented 9 years ago
Steps for getting RPC working:

After creating the service, update it with the cachedURL retrieved from the 
Gadget API.

    gadgetService = GWT.create(GadgetService.class);
    // Work around the Single Origin Policy(SOP) when the gadget is hosted inside the
gadget spec.
    ServiceDefTarget serviceDef = (ServiceDefTarget) gadgetService;
    String rpcUrl = serviceDef.getServiceEntryPoint();
    rpcUrl = intrinsicMethods.getCachedUrl(rpcUrl);
    serviceDef.setServiceEntryPoint(rpcUrl);

Then on the server side, you need to request that RemoteServiceServlet turn off
strict HTTP header checking by overriding a 'checkHeaders()':

public class GadgetRPCServlet extends RemoteServiceServlet implements
    GadgetService {

  @Override
  protected boolean checkHeaders() {
   return false;
  }

Original comment by galgwt.reviews@gmail.com on 12 Sep 2008 at 12:36

GoogleCodeExporter commented 9 years ago
Thx for the example. But where the "checkHeaders()" method is coming from ? I 
don't
see itin the RemoteServiceServlet source code...

Thx

Original comment by norman.m...@googlemail.com on 13 Sep 2008 at 11:28

GoogleCodeExporter commented 9 years ago
Sorry, that was from an early verison of the patch.  This is the method you 
need to
override.

  protected String readContent(HttpServletRequest request)
      throws ServletException, IOException {
    return RPCServletUtils.readContentAsUtf8(request, true);
  }

for a Gadget, implement it as:

  protected String readContent(HttpServletRequest request)
      throws ServletException, IOException {
    return RPCServletUtils.readContentAsUtf8(request, false);
  }

Original comment by galgwt.reviews@gmail.com on 13 Sep 2008 at 11:57

GoogleCodeExporter commented 9 years ago

Original comment by zundel@google.com on 21 Dec 2009 at 1:57