users@jersey.java.net

[Jersey] Re: CDIExtension not found error - probably a bug?

From: Jacques <jacques_at_yapmap.com>
Date: Fri, 6 Apr 2012 09:26:58 -0700

I searched for a generic way to do init parameters and couldn't find one.
 The only thing I could find was references to using Jersey specific
files/properties to add "features" like example 1 below. Ultimately it
didn't seem to always work correctly so we actually moved to using explicit
initialization like example 2 below.

Good Luck,
Jacques


*Example 1: Extending a ResourceConfig*
import javax.ws.rs.ApplicationPath;
import com.sun.jersey.api.core.PackagesResourceConfig;
import com.sun.jersey.api.json.JSONConfiguration;

@ApplicationPath("/rs/*")
public class ApplicationConfig extends PackagesResourceConfig {

  public OldApplicationConfig() {
    super("com.test.package");
    getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, true);
  }
}


*Example 2: Explicit Initialization*
import java.util.HashSet;
import java.util.Set;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
import org.jboss.seam.rest.exceptions.SeamExceptionMapper;
import org.jboss.seam.rest.templating.TemplatingMessageBodyWriter;

@ApplicationPath("/rs/*")
public class ApplicationConfig extends Application {

  private final static Logger logger =
LoggerFactory.getLogger(ApplicationConfig.class);

  public ApplicationConfig() {
    logger.info("Finished setting up JAX-RS");
  }

  @Override
  public Set<Class<?>> getClasses() {
      Set<Class<?>> classes = new HashSet<Class<?>>();
      classes.add(MyResourceClass1.class);
      classes.add(SeamExceptionMapper.class);
      classes.add(TemplatingMessageBodyWriter.class);
      return classes;
  }

  @Override
  public Set<Object> getSingletons() {
      Set<Object> classes = new HashSet<Object>();
      classes.add(new JacksonStringReaderProvider());
      classes.add(new JacksonJaxbJsonProvider());
      return classes;
  }


On Fri, Apr 6, 2012 at 3:23 AM, John Lister <john.lister_at_kickstone.com>wrote:

> My experience is i get this if i try to configure jersey via web.xml.
>>
> If i use the Application annotation it goes away.
>
> Do you have an example? I currently have jersey configured as a servlet
> filter (can't remember why - it was done to solve a problem back in the
> early days that I suspect doesn't exist any more) and also pass a number of
> init-params (including a couple of custom ones for my providers) and I
> can't see how this is possible using annotations?
>
> Thanks
>
> John
>
>
> On Apr 5, 2012 10:05 AM, "John Lister" wrote:
>> >Hi, I'm trying to use jersey 1.12 with glassfish 3.1.2 with multiple
>>
> virtual hosts and I'm getting the following exception. I
>
>> >have 2 virtual hosts both of which are running jersey applications. If
>>
> I request a page from 1 virtual host only, it works
>
>> >(doesn't matter which) but as soon as I request a page from the second
>>
> one (again order is unimportant) the second
>
>> >immediately fails with the following exception trace. I've tried to
>>
> set the system property as mentioned in bug 610, but it
>
>> >doesn't seem to make any difference...
>>
>
>
> --
> www.pricegoblin.co.uk
>
>