users@jersey.java.net

Re: [Jersey] Problem using Jersey client from openoffice java extension

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 29 Dec 2009 10:52:40 +0100

Hi Angel,

What version of Jersey are you using?

I think this might be a class loading issue from within the OpenOffice
environment. Jersey loads classes declared in META-INF/services files.
 From the log output it certainly finds those services files but it
cannot find the classes declared in those files because
ClassNotFoundException is thrown.

Jersey uses the thread context class loader to load such classes.
Perhaps you can do the following:

    
Thread
.currentThread
().setContextClassLoader(this.getClass().getClassLoader());

Paul.

On Dec 22, 2009, at 6:35 PM, Angel Luis Jimenez Martinez wrote:

> Hi,
>
> I'm trying to use Jersey client library from inside an Openoffice
> extension. The problem is that this simple code desn't work:
>
> Client client = Client.create();
> WebResource webResource = client.resource("http://ws.audioscrobbler.com/2.0/
> ");
>
> MultivaluedMap queryParams = new MultivaluedMapImpl();
> queryParams.add("api_key", "LASTFM_API_KEY_HERE");
> queryParams.add("method", "album.search");
> queryParams.add("album", "believe");
> String s =
> webResource.queryParams(queryParams).get(String.class);
> System.out.println(s);
>
> Of course I have tested this from a console java program (using the
> same libraries) and works perfectly.
>
> I think that the problem is related to these messages outputted by
> Openoffice when trying to execute this code:
>
> Dec 22, 2009 6:06:19 PM com.sun.jersey.spi.service.ServiceFinder
> $LazyObjectIterator hasNext
> WARNING: The class
> com.sun.jersey.core.impl.provider.header.LocaleProvider implementing
> the provider interface com.sun.jersey.spi.HeaderDelegateProvider is
> not found. The provider implementation is ignored.
> Dec 22, 2009 6:06:19 PM com.sun.jersey.spi.service.ServiceFinder
> $LazyObjectIterator hasNext
> WARNING: The class
> com.sun.jersey.core.impl.provider.header.EntityTagProvider
> implementing the provider interface
> com.sun.jersey.spi.HeaderDelegateProvider is not found. The provider
> implementation is ignored.
> Dec 22, 2009 6:06:19 PM com.sun.jersey.spi.service.ServiceFinder
> $LazyObjectIterator hasNext
> WARNING: The class
> com.sun.jersey.core.impl.provider.header.MediaTypeProvider
> implementing the provider interface
> com.sun.jersey.spi.HeaderDelegateProvider is not found. The provider
> implementation is ignored.
> Dec 22, 2009 6:06:19 PM com.sun.jersey.spi.service.ServiceFinder
> $LazyObjectIterator hasNext
> WARNING: The class
> com.sun.jersey.core.impl.provider.header.CacheControlProvider
> implementing the provider interface
> com.sun.jersey.spi.HeaderDelegateProvider is not found. The provider
> implementation is ignored.
> Dec 22, 2009 6:06:19 PM com.sun.jersey.spi.service.ServiceFinder
> $LazyObjectIterator hasNext
> WARNING: The class
> com.sun.jersey.core.impl.provider.header.NewCookieProvider
> implementing the provider interface
> com.sun.jersey.spi.HeaderDelegateProvider is not found. The provider
> implementation is ignored.
> Dec 22, 2009 6:06:19 PM com.sun.jersey.spi.service.ServiceFinder
> $LazyObjectIterator hasNext
> WARNING: The class
> com.sun.jersey.core.impl.provider.header.CookieProvider implementing
> the provider interface com.sun.jersey.spi.HeaderDelegateProvider is
> not found. The provider implementation is ignored.
> Dec 22, 2009 6:06:19 PM com.sun.jersey.spi.service.ServiceFinder
> $LazyObjectIterator hasNext
> WARNING: The class
> com.sun.jersey.core.impl.provider.header.URIProvider implementing
> the provider interface com.sun.jersey.spi.HeaderDelegateProvider is
> not found. The provider implementation is ignored.
> Dec 22, 2009 6:06:19 PM com.sun.jersey.spi.service.ServiceFinder
> $LazyObjectIterator hasNext
> WARNING: The class
> com.sun.jersey.core.impl.provider.header.DateProvider implementing
> the provider interface com.sun.jersey.spi.HeaderDelegateProvider is
> not found. The provider implementation is ignored.
> Dec 22, 2009 6:06:19 PM com.sun.jersey.spi.service.ServiceFinder
> $LazyObjectIterator hasNext
> WARNING: The class
> com.sun.jersey.core.impl.provider.header.StringProvider implementing
> the provider interface com.sun.jersey.spi.HeaderDelegateProvider is
> not found. The provider implementation is ignored.
> terminate called after throwing an instance of
> 'com::sun::star::uno::RuntimeException'
>
> As no more stack trace messages where available I attached eclipse
> to debug this code and using jersey's source found some place where
> a MediaTypeProvider was instanced as null. So I think the solution
> is related to those warnings.
>
> If it helps I can provide a simple Netbeans project with this code.
>
> Thanks in advance.
>
> --
> Angel.