PrettyFaces – Bypass filtering a pattern

Splash Forums PrettyFaces Users PrettyFaces – Bypass filtering a pattern

This topic contains 5 replies, has 3 voices, and was last updated by  rbento 4 years, 7 months ago.

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

    rbento
    Participant

    Hello,

    I have an webapp that currently is deployed with the context /. This really sucks, I hope we could give it a context right now, but it would break links that are pointing to it.

    The problem is that every request is passing through its PrettyFilter.

    For example, in GlassFish I have a virtual directory with the name image, which creates a virtual context to a folder. So an image would have a url like http://localhost:8080/image/image_name.png

    Because this app’s filter is filtering context /, once you access it, instead of the image I get to the error page.

    When I give a context to this app, the image is displayed properly.

    So, to correct this, I was thinking if it was possible to write a rule that would make this app’s filter completely bypass the requests to this image context.

    I tried creating a rewrite rule with redirect chain, but it didn’t work.

    Could you help me with this?

    Thanks a lot,

    Rod

    #23052

    Because this app’s filter is filtering context /, once you access it, instead of the image I get to the error page.

    I understand your problem. However I’m a bit surprised that the filter chain of your application gets processed even if the request URL actually accesses a virtual directory that is configured for your app server. But that seems to be a Glassfish issue.

    What I don’t understand is: Why do you get an error page just because the request for an image is processed by the PrettyFilter? What kind of error do you get? If you don’t have any mapping defined for the requested URL or any rewrite rule that matches it, the PrettyFilter shouldn’t to anything with the request.

    Could you perhaps post the relevant parts of your configuration? Your web.xml and pretty-config.xml? Which version of PrettyFaces are you using?

    #23053

    This doesn’t make sense to me :) PrettyFaces shouldn’t be taking action unless you have told it to – I think there may be something else going on. But yes, please post your pretty-config.xml.

    Sorry for the late response, I have been at JavaOne this week.

    ~Lincoln

    #23054

    rbento
    Participant

    Hello, thanks for answering.

    Here is my environment:

    – GlassFish 3.1.2.2

    – PrettyFaces 3.3.3

    – No PrettyFaces config in web.xml (works fine!)

    Now that you mentioned the error page, I guess the culprit is this rule:

    <url-mapping id="load">
    <pattern value="/#{ /[A-Z0-9]{32}/ key : myBean.key }" />
    <view-id value="/index.xhtml" />
    <action>#{myBean.load}</action>
    </url-mapping>

    It is probably taking /image as a key parameter, even if it fails the regex evaluation.

    Is there any way to make it ignore the /image? Could you please help me fix this?

    Hugs,

    Rod

    #23055

    I don’t think that this mapping is the problem. This pattern will only match if the key is exactly 32 characters, which isn’t the case for /image/something. But you could try to remove the mapping and check if this fixes the error.

    Any other configuration in your pretty-config.xml? Any <rewrite> rules?

    #23056

    rbento
    Participant

    Nope, my pretty-config has 3 simple mappings other than that.

    But it happens that it has nothing to do with PrettyFaces. I did a backup then deleted the pretty-config and removed the maven dependency for PrettyFaces. Then deployed the project and the problem persisted.

    I noticed that changing the Faces Servlet mapping solves this problem. Of course I can’t change it otherwise it breaks my application. Taking out the application context was really an awful last minute idea.

    I’ll refactor it bringing back the context as it solves all the problems. Sorry for bothering you guys, I should have tested it better first.

    Also in the near future I’ll start migrating to //rewrite because I liked it so much, it feels pretty solid.

    Well, anyway, here is my web.xml and glassfish-web.xml. Nothing weird there other than the damn / context.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
    <glassfish-web-app error-url="/error.xml">
    <context-root>/</context-root>
    <class-loader delegate="true"/>
    <parameter-encoding default-charset="UTF-8"/>
    </glassfish-web-app>

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

    <!-- Facelets -->

    <context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
    </context-param>

    <context-param>
    <param-name>javax.faces.FACELETS_DEVELOPMENT</param-name>
    <param-value>false</param-value>
    </context-param>

    <context-param>
    <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
    <param-value>true</param-value>
    </context-param>

    <context-param>
    <param-name>javax.faces.VALIDATE_EMPTY_FIELDS</param-name>
    <param-value>true</param-value>
    </context-param>

    <context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.xhtml</param-value>
    </context-param>

    <context-param>
    <param-name>javax.faces.FACELETS_VIEW_MAPPINGS</param-name>
    <param-value>*.xhtml</param-value>
    </context-param>

    <context-param>
    <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
    <param-value>true</param-value>
    </context-param>

    <context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
    </context-param>

    <context-param>
    <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
    <param-value>true</param-value>
    </context-param>

    <!-- PrimeFaces -->

    <context-param>
    <param-name>com.sun.faces.allowTextChildren</param-name>
    <param-value>true</param-value>
    </context-param>

    <context-param>
    <param-name>primefaces.THEME</param-name>
    <param-value>none</param-value>
    </context-param>

    <!-- Servlets -->

    <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>

    <!-- Other settings -->

    <session-config>
    <session-timeout>
    30
    </session-timeout>
    </session-config>

    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>

    <!-- Error handling -->

    <error-page>
    <location>/error.xhtml</location>
    </error-page>

    </web-app>

    Thanks a lot!

    Hugs,

    Rod

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

You must be logged in to reply to this topic.

Comments are closed.