如何正确访问 gwtp 服务实例中的文件?

How to properly access a File in a gwtp service instance?

我是 GWT 应用程序的新手,现在正在处理它。我有一个看起来很简单的问题,但我已经好几个小时都没有解决了。我想通过这行代码通过 P12 密钥文件访问 google 分析数据。

GoogleCredential credential = new GoogleCredential.Builder()
    .setTransport(httpTransport)
    .setJsonFactory(jsonFactory)
    .setServiceAccountId(serviceAccountMail)
    .setServiceAccountPrivateKeyFromP12File(new File("src/main/webapp/WEB-INF/key","XXXXXX-77b2f9138e9612309473.p12"))
    .setServiceAccountScopes(AnalyticsScopes.all()).build();

如果我通过 运行 测试上面的代码,它只是作为 Java 应用程序,代码工作正常。但是当我将 GWT 应用程序部署到 tomcat 并拥有它时 运行。我遇到以下错误。

Mon Feb 15 16:04:41 GMT+800 2016 mp.client.XXAsyncCallback WARNING: 
ERROR:Type 'java.io.FileNotFoundException' was not included in the set of 
types which can be serialized by this SerializationPolicy or its Class    
object could not be loaded. For security purposes, this type will not 
be serialized.
: instance = java.io.FileNotFoundException: XXXXXX-77b2f9138e9612309473.p12
(The system cannot find the file specified) from Service_Proxy.getData

如能提供即时帮助,我们将不胜感激。谢谢

GWT 不允许通过 RPC 传递任何类型。 FileNotFoundException 似乎是不应传递给客户端或在客户端调用的类型之一。

Class 可以传递的类型应该实现接口 com.google.gwt.user.client.rpc.IsSerializable

有关详细信息,请查看 this 线程。

希望对您有所帮助。