views:

553

answers:

1

I'm working on a web application that uses a standalone ehcache server to cache certain data. The ehcache server is accessed via REST (as opposed to SOAP).

For functional testing purposes, I need to run an embedded instance of the ehcache server. The echcache-server project itself does this for its own functional tests, using the Cargo Maven2 plugin. I tried doing the same thing in my application's pom.xml, but the Cargo plugin insists on deploying my own web application's WAR, even when I configure it to use ehcache's WAR instead.

Therefore, I am trying to use the Cargo Container API directly to do the deployment and container instantiation. Here is the relevant code:

String localRepositoryPath = "/home/zoltan/.m2/repository";
String jettyHomeDirectory = "/tmp/cargoJettyHome";

LocalConfiguration configuration = new Jetty6xEmbeddedStandaloneLocalConfiguration(jettyHomeDirectory);
Deployable war = new WAR(localRepositoryPath + "/net/sf/ehcache/ehcache-server/0.7/ehcache-server-0.7.war");
configuration.addDeployable(war);

EmbeddedLocalContainer container = new Jetty6xEmbeddedLocalContainer(configuration);
container.start();

The Jetty container starts, and ehcache itself seems to partially start, based on various messages that look the same as what is generated when starting the standalone server. However, the RESTful web service fails to start, with the following exception:

com.sun.jersey.spi.service.ServiceConfigurationError: com.sun.jersey.spi.container.WebApplicationProvider: The class com.sun.jersey.impl.container.WebApplicationProviderImpl implementing provider interface com.sun.jersey.spi.container.WebApplicationProvider could not be instantiated: null
    at com.sun.jersey.spi.service.ServiceFinder.fail(ServiceFinder.java:346)
    at com.sun.jersey.spi.service.ServiceFinder.access$600(ServiceFinder.java:144)
    at com.sun.jersey.spi.service.ServiceFinder$LazyObjectIterator.hasNext(ServiceFinder.java:638)
    at com.sun.jersey.spi.container.WebApplicationFactory.createWebApplication(WebApplicationFactory.java:61)
    at com.sun.jersey.spi.container.servlet.ServletContainer.create(ServletContainer.java:570)
    at com.sun.jersey.spi.container.servlet.ServletContainer.load(ServletContainer.java:538)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:207)
    at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:433)
    at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:256)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:616)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
    at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.Server.doStart(Server.java:222)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.cargo.container.jetty.internal.JettyExecutorThread.run(JettyExecutorThread.java:68)
Caused by: java.lang.ClassCastException
    at java.lang.Class.cast(Class.java:2990)
    at com.sun.jersey.spi.service.ServiceFinder$LazyObjectIterator.hasNext(ServiceFinder.java:596)
    ... 26 more

Here are the relevant dependencies from my pom.xml:

<dependency>
  <groupId>com.sun.jersey</groupId>
  <artifactId>jersey-server</artifactId>
  <version>1.0</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>com.sun.jersey</groupId>
  <artifactId>jersey-client</artifactId>
  <version>1.0</version>
</dependency>
<dependency>
  <groupId>com.sun.jersey</groupId>
  <artifactId>jersey-spring</artifactId>
  <version>1.0</version>
  <scope>test</scope>
  <exclusions>
    <exclusion>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
    </exclusion>
    <exclusion>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
    </exclusion>
    <exclusion>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aop</artifactId>
    </exclusion>
    <exclusion>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
    </exclusion>
    <exclusion>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context-support</artifactId>
    </exclusion>
    <exclusion>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>jetty-servlet-tester</artifactId>
  <version>6.1.11</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.codehaus.cargo</groupId>
  <artifactId>cargo-core-api-container</artifactId>
  <version>1.0</version>
</dependency>
<dependency>
  <groupId>org.codehaus.cargo</groupId>
  <artifactId>cargo-core-api-generic</artifactId>
  <version>1.0</version>
</dependency>
<dependency>
  <groupId>org.codehaus.cargo</groupId>
  <artifactId>cargo-core-container-jetty</artifactId>
  <version>1.0</version>
</dependency>
<dependency>
  <groupId>net.sf.ehcache</groupId>
  <artifactId>ehcache-server</artifactId>
  <version>0.7</version>
  <type>war</type>
</dependency>

Does anyone know what might cause this exception? Perhaps I'm using mismatched versions of jetty and jersey? Do I have to somehow register a WebApplicationProviderImpl? Any ideas would be much appreciated.

A: 

I don't have a solution to this: instead, my functional tests are using a standalone ehcache server.

Someone on the ehcache mailing list suggested an alternative approach.

Zoltan Szilagyi