1

我有一个使用 gwt 并托管在 gae 上的应用程序。有一个使用 xfbml 的表单,并在填写数据并提交表单后具有重定向 url。问题是如果通过 xfbml 表单提交发生这种情况,它会引发异常。如果我直接调用 url 它工作得很好。

xfbml 代码是:

<fb:registration redirect-uri="http://www.sakshum.org/FbBloodDonorRegister" fields='[{"name":"name"},{"name":"first_name"},{"name":"last_name"}, {"name":"cellPhone", "description":"Cell Number", "type":"text"}, {"name":"homePhone", "description":"Home Number", "type":"text"}]'  onvalidate="validated" width="530">
</fb:registration>

例外如下

javax.servlet.ServletContext log: Exception while dispatching incoming RPC call
javax.servlet.ServletException: Content-Type was 'application/x-www-form-urlencoded'. Expected 'text/x-gwt-rpc'.
    at com.google.gwt.user.server.rpc.RPCServletUtils.checkContentTypeIgnoreCase(RPCServletUtils.java:427)
    at com.google.gwt.user.server.rpc.RPCServletUtils.readContent(RPCServletUtils.java:160)
    at com.google.gwt.user.server.rpc.RPCServletUtils.readContentAsGwtRpc(RPCServletUtils.java:205)
    at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.readContent(AbstractRemoteServiceServlet.java:182)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:239)
    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:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:102)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:249)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:135)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:447)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:452)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:458)
    at com.google.tracing.TraceContext.runInContext(TraceContext.java:698)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:336)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:328)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:456)
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
    at java.lang.Thread.run(Thread.java:679)
4

2 回答 2

1

我看到您的错误显示:Content-Type 是 'application/x-www-form-urlencoded'。预期的“文本/x-gwt-rpc”

我会将您的 servlet 中的预期内容类型更改为“text/x-gwt-rpc”。那是你的servlet得到回调吗?

于 2012-09-11T03:28:37.677 回答
1

查看上面调用的这个文件: http ://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/google/gwt/user/server/rpc/ RPCServletUtils.java

您将无法轻松更改预期的内容类型,因为这是在

public static String readContentAsGwtRpc(HttpServletRequest request)
  throws IOException, ServletException {
    return readContent(request, GWT_RPC_CONTENT_TYPE, CHARSET_UTF8_NAME);
}

关键似乎是您正在从 Facebook 的 XFBML 调用特定于 RPC 的 servlet。尝试摆弄特定于 RPC 的调用是不值得的,而且您可能无法更改 FB 调用它的方式。最简单的解决方案是添加另一个接受普通 POSTS 和 GETS 的 servlet,然后从 Facebook 调用它。

于 2012-09-13T07:23:49.547 回答