Rewrite configuration is not working

Splash Forums Rewrite Users Rewrite configuration is not working

This topic contains 13 replies, has 2 voices, and was last updated by  Christian Kaltepoth 2 months, 1 week ago.

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #28352

    SubhojitM
    Participant

    Hi,
    I am migrating an application from weblogic to Jboss. In weblogic it is working fine. In weblogic the version of rewrite I used was 2.0.12. I am using rewrite 3.4.2 for the JBoss EAP 7. Added the below in web.xml
    <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>/app/*</url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>ERROR</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    <dispatcher>ASYNC</dispatcher>

    </filter-mapping>
    <listener>
    <listener-class>org.ocpsoft.rewrite.servlet.impl.RewriteServletRequestListener</listener-class>
    </listener>
    <listener>
    <listener-class>org.ocpsoft.rewrite.servlet.impl.RewriteServletContextListener</listener-class>
    </listener>

    Added xml based url mappling configuration both the web.xml and pretty-faces.xml files are in WEB-INF directory of the web application.
    During startup I am getting the logs like:
    2018-10-03 05:48:17,966 INFO [org.ocpsoft.rewrite.faces.RewritePhaseListener] (ServerService Thread Pool — 66) RewritePhaseListener starting up.
    ……
    2018-10-03 05:48:53,717 INFO [org.ocpsoft.rewrite.servlet.RewriteFilter] (default task-1) Loaded [4] org.ocpsoft.rewrite.servlet.spi.RewriteLifecycleListener [org.ocpsoft.rewrite.prettyfaces.PrettyFacesRewriteLifecycleListener<-100>, org.ocpsoft.rewrite.faces.FacesRewriteLifecycleListener<0>, org.ocpsoft.rewrite.servlet.config.lifecycle.JoinRewriteLifecycleListener<2147483647>, org.ocpsoft.rewrite.servlet.impl.DefaultRewriteLifecycleListener<2147483647>]
    2018-10-03 05:48:53,718 INFO [org.ocpsoft.rewrite.servlet.RewriteFilter] (default task-1) Loaded [1] org.ocpsoft.rewrite.servlet.spi.RequestCycleWrapper [org.ocpsoft.rewrite.servlet.impl.HttpRewriteRequestCycleWrapper<0>]
    ……..
    2018-10-03 05:48:54,025 INFO [org.ocpsoft.rewrite.servlet.RewriteFilter] (default task-1) Rewrite 3.4.2.Final initialized.

    Still the url redirect feature is not working. There is no error in server log.

    #28353

    Usually you don’t need to add anything to web.xml at all. All the required filters and listeners are automatically registered via the web-fragment.xml located in the Rewrite archive.

    Could you share your pom.xml and other configuration?

    #28354

    SubhojitM
    Participant

    The Jars for rewerite added in WEB-INF/lib are
    rewrite-config-prettyfaces-3.4.2.Final.jar
    rewrite-integration-faces-3.4.2.Final.jar
    rewrite-integration-spring-3.4.2.Final.jar
    rewrite-servlet-3.4.2.Final.jar

    Attachments:
    1. pretty-config.xml
    #28356

    SubhojitM
    Participant

    The Jars for rewerite added in WEB-INF/lib are
    rewrite-config-prettyfaces-3.4.2.Final.jar
    rewrite-integration-faces-3.4.2.Final.jar
    rewrite-integration-spring-3.4.2.Final.jar
    rewrite-servlet-3.4.2.Final.jar

    Project is built using Ant. So there is no pom.xml file

    #28358

    SubhojitM
    Participant

    Adding logs for both JBoss and weblogic. In weblogic the RewriteFilter is creating view in between HeaderFilter and WindowScopeFilter.

    But in case of JBoss the filter chain is not progressing after the headerFilter.

    #28361

    Could you provide a MCVE app to reproduce this issue?

    #28363

    SubhojitM
    Participant

    Can I use rewrite using configuration xml file like this below
    <pretty-config xmlns=”http://ocpsoft.org/schema/rewrite-config-prettyfaces”
    xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
    xsi:schemaLocation=”http://ocpsoft.org/schema/rewrite-config-prettyfaces
    http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config-prettyfaces.xsd“>
    <url-mapping id=”App”>
    <pattern value=”/app/test”/>
    <view-id value=”test.html” />
    </url-mapping>
    </pretty-config>

    And can we pass normal html file apart from xhtml and jsf?

    #28364

    Yes, you can use such XML configuration files if you include the rewrite-config-prettyfaces module.

    And yes, you can rewrite all URLs, because Rewrite doesn’t depend on JSF.

    #28366

    SubhojitM
    Participant

    Hi,

    I have createda dummy project. But it is not working. Adding the details. Please check.

    @Component
    public class MyConfigurationProvider extends HttpConfigurationProvider {

    @Override
    public Configuration getConfiguration(ServletContext context) {

    System.out.println(“*********loading rewrite configurations**********”);
    return ConfigurationBuilder.begin()

    /* add your rules here */

    .addRule(Join.path(“/app”).to(“/test.html”));
    }

    @Override
    public int priority() {
    return 10;
    }

    }

    #28369

    Could you please private the project in source form? Some Maven project which I can deploy to an app server?

    #28370

    SubhojitM
    Participant

    Hi,

    As requested, PFA the project.

    Attachments:
    1. rewrite.zip
    #28372

    SubhojitM
    Participant

    Hi,

    I want to run this in jboss 7 server only.

    #28373

    Thanks! I’ll try to find some time to have a deeper look at the app at the weekend.

    #28374

    I just had a look at your app. The sample was very helpful. Two things I would like to mention.

    First you really don’t need to add any configuration to your web.xml for Rewrite to work correctly. This is done automatically. So you can remove the Rewrite filter and listener configuration.

    So real problem seems to be your context path. You defined a custom context path with jboss-web.xml. This file contains a context path definition like this:

    <context-root>/dummy/</context-root>
    

    The problem here is that this is actually not a valid context path. Or let’s call it “uncommon”. The trailing slash is the problem. JBoss seems to return exactly this string via request.getContextPath(), but the result of this method usually doesn’t contain trailing slashes. And that’s why Rewrite gets confused.

    To fix the problem, simply replace the context path definition with this (no trailing slash):

    <context-root>/dummy</context-root>
    

    And now your app works. At least it does with Wildfly 14. That was the version I tested with.

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

You must be logged in to reply to this topic.

Comments are closed.