Search code examples
javagwtgwtp

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


I am new to GWT application and working on it right now. I have a problem which seems to be quite simple, but I haven't resolved it for hours already. I want to access google analytics data through a P12 key file through this line of code.

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();

If I test above code by running it simply as Java application, the code works fine. But when I deploy the GWT application to tomcat and have it running. I am getting below errors.

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

Any immediate help would be much appreciated. Thanks.


Solution

  • GWT does not allow any type to be passed through RPC. FileNotFoundException seems to be one of the types that should not be passed to or invoked on the client side.

    Class types that can be passed should implement interface com.google.gwt.user.client.rpc.IsSerializable

    For more info please check this thread.

    Hope this helps.