Rewrite in EARs with skinny wars

Splash Forums Rewrite Users Rewrite in EARs with skinny wars

This topic contains 4 replies, has 2 voices, and was last updated by  Lincoln Baxter III 3 years, 1 month ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #24223

    kasulzke
    Participant

    I have an EAR with two webapps, both of them using Rewrite. Everything works as expected.

    When I change packaging to use skinny wars (using Maven EAR plugin), Rewrite no longer starts up. There are no error messages, Rewrite is simply ignored. I use JBoss 7.1.1, by the way.

    I tried configuring Rewrite with Annotations, the SPI and the CDI extension.

    How can I force Rewrite to startup when it is located in an EAR’s lib directory?

    #24226

    Hmmm… I’m guessing that in order for this to work, you will need to manually add Rewrite to your web.xml in each WAR file. The default servlet filter registration for Rewrite is done in a web-fragment.xml, which is probably not picked up by WARs when you are referencing libraries from the EAR deployment classpath.

    The Servlet 3.0 spec section 8.2.1 says: “Only jar files that are packaged in
    WEB-INF/lib are scanned for META-INF/web-fragment.xml”

    So you’ll need to add this to each web.xml:

       <listener>
          <listener-class>org.ocpsoft.rewrite.servlet.impl.RewriteServletRequestListener</listener-class>
       </listener>
    
       <listener>
          <listener-class>org.ocpsoft.rewrite.servlet.impl.RewriteServletContextListener</listener-class>
       </listener>
    
       <filter>
          <filter-name>OCPsoft Rewrite Filter</filter-name>
          <filter-class>org.ocpsoft.rewrite.servlet.RewriteFilter</filter-class>
          <async-supported>true</async-supported>
       </filter>
       <filter-mapping>
          <filter-name>OCPsoft Rewrite Filter</filter-name>
          <url-pattern>/*</url-pattern>
          <dispatcher>FORWARD</dispatcher>
          <dispatcher>REQUEST</dispatcher>
          <dispatcher>INCLUDE</dispatcher>
          <dispatcher>ASYNC</dispatcher>
          <dispatcher>ERROR</dispatcher>
       </filter-mapping>

    Once that is done, you should be up and running. If you encounter any other strange behavior, it may be due to some ServiceLoader issues but we can work through those if they are a problem. EAR’s are weird 🙂

    #24234

    I have just updated the documentation to reflect this:

    http://ocpsoft.org/rewrite/docs/configuration/install

    Let me know how this goes for you and I’ll keep updating the docs. Thanks!

    #24238

    kasulzke
    Participant

    Your solution works perfectly. Thanks for the quick reply and for updating the documentation.

    I’d like to use this place to document a minor problem that I stepped into using the auto-deploy feature of my IDE:
    Upon ear creation, the maven-ear-plugin removes the duplicate jars from the war files. Your IDE might not do this. In my environment (Eclipse, JBoss Tools, JBoss AS 7, Maven) a deployment was produced that contained Rewrite both in the ear’s lib and each war, resulting in errors: “Cannot forward after response has been committed”.

    The solution was to set the scope of Rewrite in the wars to provided.
    Now the EAR works both in the IDE and when manually built with Maven.

    #24240

    Great! I’m glad you got this working, and I’ll update the documentation with your notes!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

Comments are closed.