Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud Storage: Could not initialize class OauthRawGcsServiceFactory

I'm trying to do a simple upload and download on Appengine with Google Cloud Storage Client Library.

During the execution, it returns these errors:

java.lang.NoClassDefFoundError: Could not initialize class com.google.appengine.tools.cloudstorage.oauth.OauthRawGcsServiceFactory
    at com.google.appengine.tools.cloudstorage.GcsServiceFactory.createRawGcsService(GcsServiceFactory.java:42)
    at com.google.appengine.tools.cloudstorage.GcsServiceFactory.createGcsService(GcsServiceFactory.java:34)

The error points to here:

    @Override
    public void doGet( HttpServletRequest request, HttpServletResponse response ) throws IOException {
        GcsFilename fileName = getFileName( request );

        GcsInputChannel readChannel = gcsService.openPrefetchingReadChannel(fileName, 0, BUFFER_SIZE);
        copy(Channels.newInputStream(readChannel), response.getOutputStream());
    }

    @Override
    public void doPost( HttpServletRequest request, HttpServletResponse response ) throws IOException {
        GcsOutputChannel outputChannel = gcsService.createOrReplace( getFileName(request), GcsFileOptions.getDefaultInstance() );
        copy( request.getInputStream(), Channels.newOutputStream(outputChannel) );
    }

How do I solve this?

like image 607
benjtupas Avatar asked Oct 21 '22 06:10

benjtupas


2 Answers

One of the required jars is missing from your /war/WEB-INF/lib/ folder.

First, if you use Eclipse, check that there are no warnings in the Problems tab about a resource not being available on the server. If you see them, right-click QuickFix and choose "Copy to ..." option. If you don't use Eclipse, check manually.

If this does not help, check that you included all the dependencies necessary for you project:

https://code.google.com/p/google-api-java-client/wiki/Setup#Download_Library_with_Dependencies

like image 126
Andrei Volgin Avatar answered Oct 24 '22 05:10

Andrei Volgin


One of possible causes for this problem is absence of libraries, required by the GCS library. When Google states in their docs that you need 1) Guava, 2) Joda-Time, 3) Cloud Storage API Client library - they are not joking.

The problem is, you don't need those libraries to run your application on a dev server. Your application will work fine locally. When you upload it to Google, though, you'll get a NoClassDefFoundError with an incorrect message: it will report OAuthRawGcsServiceFactory, or maybe URLFetchUtils, even though the missing classes are in Joda or in CS API.

Once you include everything required by Google, your project (hopefully) will work. Download links for those libraries can be found on the Appengine Docs page: https://cloud.google.com/appengine/docs/java/googlecloudstorageclient/download .

like image 33
Vythe Avatar answered Oct 24 '22 04:10

Vythe