Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-757

ClassCastException running two RESTEasy WARs in JBoss AS 7

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Obsolete
    • Icon: Major Major
    • None
    • 2.3.4.Final
    • None
    • None

      Found this while trying to get s-ramp and s-ramp-ui deployed and working together on JBoss AS 7. In our case, s-ramp is a RESTEasy WAR that provides some rest endpoints. Then s-ramp-ui is a GWT UI for s-ramp, and uses RESTEasy as a client to access those endpoints. I was getting ClassCast exceptions in the client (which I worked around - more later).

      Note #1: we are using a newer version of RESTEasy than what JBoss AS 7 packages, and we include it in our WARs.

      Note #2: we exclude the JBoss RESTEasy module using the jboss-deployment-structure.xml file included in both WARs.

      Ultimately, the problem seems to be that RESTEasy stores an instance of the ProviderFactory in a static variable in RuntimeDelegate. Since JBoss AS 7 provides this class, the instance is stored in a static variable shared by both WAR deployments. However, the instance itself has a class that comes from one of the WARs. So when the other WAR tries to create its own instance, you get a class cast exception.

      I have created a stripped down maven project to show this problem. Attached to this ticket are:

      1) the full maven project (parent project with two WAR modules)
      2) two RESTEasy WARs

      To reproduce this problem, simply deploy the two WARs to JBoss AS 7 and then hit the following URLs in order:

      http://localhost:8080/rest-easy-test-first/feed
      http://localhost:8080/rest-easy-test-second/feed
      http://localhost:8080/rest-easy-test-first/feed

      The first URL will work and show an Atom feed. The second URL will also work and show an Atom feed. The third URL will fail with:

      java.lang.ClassCastException: org.jboss.resteasy.core.ThreadLocalResteasyProviderFactory cannot be cast to org.jboss.resteasy.spi.ResteasyProviderFactory
      org.jboss.resteasy.spi.ResteasyProviderFactory.getInstance(ResteasyProviderFactory.java:351)
      org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:222)
      org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
      org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

              patriot1burke@gmail.com Bill Burke (Inactive)
              ewittman@redhat.com Eric Wittmann
              Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: