2
votes

I'm working on a web-based application which would allow users to upload a Word document to Google Docs using the GData Java API.

( I came across this blog where I found out that I could actually use a byte array to upload a doc instead of using a File )

I'm using Netbeans + JDK 1.6

The relevant code in my servlet:

DocsService docsService = new DocsService("care.udhc.co.in");                
try {
    docsService.setUserCredentials("[email protected]", "*******");      

    DocumentListEntry newDocument = new DocumentListEntry();

    String s="hello bose";
    byte byteData[]=s.getBytes();

    // Load the byte array into a MediaSource
    MediaByteArraySource mediaSource = new MediaByteArraySource(byteData, MediaType.fromFileName("bose.doc").getMimeType());
    MediaContent content = new MediaContent();
    content.setMediaSource(mediaSource);
    content.setMimeType(new ContentType(mediaSource.getContentType()));
    newDocument.setContent(content);

    String gdocsFilename = new String("My Filename");
    newDocument.setTitle(new PlainTextConstruct(gdocsFilename));
    out.println("OK");
    // Push it into Google Docs!! 
    DocumentListEntry uploadedRef = docsService.insert(new URL("https://docs.google.com/feeds/default/private/full/"), newDocument);
} catch(Exception e) {
   out.println(e.toString());
} finally {            
    out.close();
}

When I run it locally, I encounter the following error:

com.google.gdata.util.InvalidEntryException: We're sorry, a server error occurred. Please try again. GDataInvalidEntryExceptionWe're sorry, a server error occurred. Please try again.

When i run the version deployed on the Internet ( Jelastic cloud ), I get this:

java.lang.NoClassDefFoundError: com/google/gdata/data/extensions/QuotaBytesTotal
com.google.gdata.data.docs.MetadataEntry.declareExtensions(MetadataEntry.java:86)
com.google.gdata.data.ExtensionProfile.addDeclarations(ExtensionProfile.java:71)
com.google.gdata.data.BaseFeed.declareExtensions(BaseFeed.java:235)
com.google.gdata.client.docs.DocsService.declareExtensions(DocsService.java:171)
com.google.gdata.client.docs.DocsService.<init>(DocsService.java:108)
bose.google.UploadToDocs.processRequest(UploadToDocs.java:30)
bose.google.UploadToDocs.doGet(UploadToDocs.java:79)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

Please get me a workaround?

1

1 Answers

0
votes

It seems like you are missing one of the required dependencies, probably gdata-core-1.0.jar.

Also, check this page for external dependencies: https://developers.google.com/gdata/articles/java_client_lib