Google Docs API: UnsupportedDataTypeException MIME type application/atom+xml

Problem

When trying to use the Google Docs API inside an OSGi bundle, the following exception is thrown, for instance when trying to upload a document:

javax.activation.UnsupportedDataTypeException: no object DCH for MIME type application/atom+xml
        at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:877)
        at javax.activation.DataHandler.writeTo(DataHandler.java:302)

Solution

Again this problem requires some tweaking with classloaders. The following code added before and after updateMedia helped in my case:

Thread cur = Thread.currentThread();
                
ClassLoader ccl = cur.getContextClassLoader();
                 ClassLoader classLoader = this.getClass().getClassLoader();
                 cur.setContextClassLoader(classLoader);
MediaMultipart.loadMimeMappings();

entry.setMediaSource(source);
entry.setEtag(“*”);

DocumentListEntry e = entry.updateMedia(true);

cur.setContextClassLoader(ccl);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s