Reply To: Rewrite in EARs with skinny wars

Splash Forums Rewrite Users Rewrite in EARs with skinny wars Reply To: Rewrite in EARs with skinny wars

#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 🙂