Rewrite Rules when using with ADF/Webcenter

Splash Forums PrettyFaces Users Rewrite Rules when using with ADF/Webcenter

This topic contains 5 replies, has 2 voices, and was last updated by  Siddharth 1 year, 4 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #27030

    Siddharth
    Participant

    Hi All ,

    I’m in the process of integrating pretty faces with webcenter . for a very basic case with static rule i’m getting what i’m looking for as below .

    pretty-config.xml as below :

    <rewrite outbound="false" match="^/*$" toCase="lowercase" trailingSlash="append" redirect="301" />
     <rewrite inbound="false" match=".*(/abc)+.*" processor="view.PrettyFacesAdfProcessor" redirect="301" />
     <rewrite inbound="false" match=".*(/de)+.*" processor="view.PrettyFacesAdfProcessor" redirect="301" />
            <url-mapping > 
              <pattern value="/de" /> 
              <view-id value="/xyz/Emp" />
           </url-mapping>
           <url-mapping > 
              <pattern value="/abc" /> 
              <view-id value="/xyz/Main" />
           </url-mapping>

    So when user hits http://localhost:7001/pretty/abc , contents of Main page are shown and when user switches to /de , Emp page is shown . All works fine till now .
    But I cannot add all the pages , which are around 4000 in the pretty config with URL mapping .Is there any way using regex that i can do so .What i want is if request comes as /de/<rest-of-string> , it should hit target /xyz/<rest-of-string> and get the result with maintaining URL as /de/<rest-of-string> only in browser. I tried below rule but couldn’t make it work .

    <url-mapping > 
              <pattern value="/de/(.*)" /> 
              <view-id value="/xyz/$1" />
           </url-mapping>

    What changes should i make or my approach is wrong?

    Regards,
    Siddharth

    #27031

    Hi Siddharth,

    Without seeing what is in your view.PrettyFacesAdfProcessor, I can’t really suggest what your problem might be. There could be a bug in that. However, for the type of large-scale configuration you are using, I would recommend using Rewrite directly (PrettyFaces is a configuration extension for Rewrite):

    http://ocpsoft.org/rewrite/

    An example rule that would do what you want:

    .addRule(Join.path("/de/{p}").to("/xyz/{p}"))
    .where("p").matches(".*")

    ~Lincoln

    #27032

    Siddharth
    Participant

    Hi Lincoln ,
    Thanks for replying.
    Below is the code for PrettyFacesAdfProcessor that i’m using .

        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")) {
           
        String newUrl = url + "?_adf.ctrl-state=" + request.getParameterValues("_adf.ctrl-state")[0];
    
        return newUrl;
    
        }
    
            
        return url;
    
        }

    I’ll try to integrate rewrite with webcenter and will provide results on this thread . Thanks .

    Regards,
    Siddharth

    #27035

    Siddharth
    Participant

    Hi Lincoln ,

    I tried to integrate Rewrite with my sample app and using following rule.

            return ConfigurationBuilder.begin()
                .addRule(Join.path("/mylifeportal/{p}")
                         .to("/faces/{p}"))
                .where("p").matches(".*")
                ;

    so my URL becomes http://127.0.0.1:7101/prettyRewrite/mylifeportal/Main.jspx?_adf.ctrl-state=heqobfqb3_4&_afrLoop=16871011112338 . which is fine .

    But if i remove all the params and hit enter , the URL becomes :

    http://127.0.0.1:7101/prettyRewrite/mylifeportal/Main.jspx?p=Main.jspx&p=Main.jspx&p=Main.jspx&p=Main.jspx&_afrWindowMode=0&_afrLoop=16935526785590&_adf.ctrl-state=heqobfqb3_24

    Rewrite adds many params in the URL .How can i stop this ?

    Other issue is If I have a page like “New Page” with a space in the middle , i get the following error

    java.lang.IllegalArgumentException: [/prettyRewrite/faces/New Page?p=New+Page&p=New+Page&p=New+Page&p=New+Page&_afrWindowId=llz5etwak_21&_afrWindowMode=0&_afrLoop=16457928559785&_adf.ctrl-state=llz5etwak_29] is not a valid URL fragment. Consider encoding relevant portions of the URL with [class org.ocpsoft.urlbuilder.util.Encoder]
    	at org.ocpsoft.urlbuilder.AddressBuilder.create(AddressBuilder.java:89)
    	at org.ocpsoft.rewrite.servlet.impl.HttpRewriteWrappedResponse.encodeURL(HttpRewriteWrappedResponse.java:396)
    	at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:86)
    	at com.sun.faces.context.ExternalContextImpl.encodeActionURL(ExternalContextImpl.java:375)

    Full stack trace is attached .

    I tried by replacing space with %20 but still no luck . Kindly suggest .

    Regards,
    Siddharth

    #27036

    Siddharth
    Participant

    Adding caused by from logs as had errors while uploading file :

    Caused by: java.net.URISyntaxException: Illegal character in path at index 24: /prettyRewrite/faces/New Page?p=New+Page&p=New+Page&p=New+Page&p=New+Page&_afrWindowId=llz5etwak_21&_afrWindowMode=0&_afrLoop=16457928559785&_adf.ctrl-state=llz5etwak_29
    	at java.net.URI$Parser.fail(URI.java:2809)
    	at java.net.URI$Parser.checkChars(URI.java:2982)
    	at java.net.URI$Parser.parseHierarchical(URI.java:3066)
    	at java.net.URI$Parser.parse(URI.java:3024)
    	at java.net.URI.(URI.java:578)
    	at org.ocpsoft.urlbuilder.AddressBuilder.create(AddressBuilder.java:79)
    #27037

    Siddharth
    Participant

    Upon integrating with webcenter , i’m getting this warning .

    [URI: /webcenter/portal/home] Response has already been committed, and further write operations are not permitted. This may result in an IllegalStateException being triggered by the underlying application. To avoid this situation, consider adding a Rule .when(Direction.isInbound().and(Response.isCommitted())).perform(Lifecycle.abort()), or figure out where the response is being incorrectly committed and correct the bug in the offending code.

    what could be the problem for this ?

    Regards,
    Siddharth

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

You must be logged in to reply to this topic.

Comments are closed.