Posted by: Josh | October 25, 2009

Sun Jersey 1.0.3.1 and Google App Engine 1.2.6

You most likely have come across the following “warning” level log entry in your Google App Engine logs if you’ve been using Sun’s jersey-core 1.0.x jar and the Google App Engine 1.2.6 SDK:

com.sun.jersey.core.spi.component.ProviderFactory __getComponentProvider: The provider class, class com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$App, could not be instantiated. Processing will continue but the class will not be utilized
java.lang.SecurityException: Unable to get members for class com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$App
at com.google.appengine.runtime.Request.process-819e5bfbf2e72052(Request.java)
at java.lang.Class.getMethods(Class.java:180)
at com.sun.jersey.core.reflection.MethodList.<init>(MethodList.java:57)
at com.sun.jersey.core.spi.component.ComponentConstructor.getPostConstructMethod(ComponentConstructor.java:121)
at com.sun.jersey.core.spi.component.ComponentConstructor.<init>(ComponentConstructor.java:115)
at com.sun.jersey.core.spi.component.ProviderFactory.__getComponentProvider(ProviderFactory.java:158)
at com.sun.jersey.core.spi.component.ProviderFactory.getComponentProvider(ProviderFactory.java:130)
at com.sun.jersey.core.spi.component.ProviderServices.getComponent(ProviderServices.java:190)
at com.sun.jersey.core.spi.component.ProviderServices.getProvidersAndServices(ProviderServices.java:120)
at com.sun.jersey.core.spi.factory.MessageBodyFactory.getProviderMap(MessageBodyFactory.java:136)
at com.sun.jersey.core.spi.factory.MessageBodyFactory.initReaders(MessageBodyFactory.java:110)
at com.sun.jersey.core.spi.factory.MessageBodyFactory.init(MessageBodyFactory.java:105)
at com.sun.jersey.api.client.Client.<init>(Client.java:257)
at com.sun.jersey.api.client.Client.<init>(Client.java:133)
at com.sun.jersey.api.client.Client.create(Client.java:444)
at com.socialjava.TinyFBClient.<init>(TinyFBClient.java:42)
at com.socialjava.TinyFBClient.<init>(TinyFBClient.java:47)
at com.socialjava.TinyFBClient.<init>(TinyFBClient.java:58)
Pictured: a broken jar.

A broken jar.

… and so on, for a lot longer.

In my case, this was due to the Jersey implementation that goes along side Social Java’s Tiny Facebook Client. The App engine admin panel reports that these exceptions are using up a lot of cpu time per request, which is never a good thing. Here’s how to silence them.

 

 

The problem just appears to be related to Google App Engine’s restrictive nature on allowed JRE classes. The following prevents these classes from ever being invoked.

Method 1:

Use this JAR I made. Replace your current implementation of jersey-core.jar with the one I’ve packaged.

Download jersey-core-gae.jar (compiled for Java 1.5) . Full Readme. (change the file extension from .zip to .jar)

Changes:
Commented out calls to com.sun.jersey.core.reflection.MethodList in the following classes:
com.sun.jersey.core.spi.component.ComponentConstructor
com.sun.jersey.core.spi.component.ComponentInjector
com.sun.jersey.core.spi.component.ComponentDestructor

Eclipse project SVN link. I extracted the original jersey-core.jar, removed the classes I overrode, and recompiled it as a .jar.

 

Method 2:

DIY class over-riding. The key is to load the unmodifier .jar first, and then override its implementation with your own.

You might like to do it yourself, if for whatever reason you can’t use method 1. You can keep the original jersey-core.jar in your classpath (/war/WEB-INF/lib), and in your build path (/src) add the package com.sun.jersey.core.spi.component and drop in these 3 java classes.

 

I’m not sure what the side effects of making it GAE compatible are, but so far, the implementation of Social Java’s Tiny Facebook Client seems to be unaffected. Enjoy!


Responses

  1. […] And if you’re interested in the fix on the Sun Jersey Core library, see my post here. […]

  2. Has the Jersey team been made aware of this bug? Should be a great improvement to make Jersey GAE-friendly out-of-the-box.


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

Categories

%d bloggers like this: