PrettyFaces Processor and Rewrite rules for ADF developers

Splash Forums PrettyFaces Users PrettyFaces Processor and Rewrite rules for ADF developers

This topic contains 1 reply, has 2 voices, and was last updated by  Christian Kaltepoth 5 years, 11 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #18090

    clemmonsm
    Participant

    I thought I would share my solution for other ADF developers to use when they are programming an ADF app with PrettyFaces. Hopefully this will save them some time.

    Below are the pretty-config.xml rewrite rules. Inbound match regex avoids the processing of inbound requests that include ADF parameters. Without this, ADF goes into an infinite loop. Outbound match regex allows processing of only urls for which you have defined url-mappings.

    <!-- inbound rewrite rules -->
    <!-- append trailing slash, set url to lowercase (not including trailing query params) -->
    <rewrite outbound="false" match="^[^?.]*$" toCase="lowercase" trailingSlash="append" redirect="301" /> <!-- matches strings w/o "?" or "." -->

    <!-- outbound rewrite rules -->
    <!-- process outbound urls via PrettyFacesAdfProcessor -->
    <rewrite inbound="false" match=".*(^/$|/part-of-url-mapping1/|/part-of-url-mapping2/|/part-of-url-mapping3/)+.*" processor="siteUtils.PrettyFacesAdfProcessor" redirect="301" />

    Below is the processor implementation. On the outbound url writing, you add the _adf.ctrl-state param to the url.

    public class PrettyFacesAdfProcessor implements Processor {

    public String processInbound(final HttpServletRequest request, final HttpServletResponse response, final RewriteRule rewrite, final String url) {
    return url;
    }

    public String processOutbound(final HttpServletRequest request, final HttpServletResponse response, final RewriteRule rewrite, final String url) {

    if (request.getParameterValues("_adf.ctrl-state") != null && !url.contains("_adf.ctrl-state")) {
    // param exists and is not assigned to url, so append _adf.ctrl-state key/value to query string
    String newUrl = url + "?_adf.ctrl-state=" + request.getParameterValues("_adf.ctrl-state")[0];
    return newUrl;
    }

    return url;
    }
    }

    Feel free to add any enhancements to this for future reference.

    #21687

    Thanks for providing this detailed description. I also hope that it will help others! :)

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

You must be logged in to reply to this topic.

Comments are closed.