Mapping a servlet to a prettier url thanks to pretty faces: is that possible?

Splash Forums PrettyFaces Users Mapping a servlet to a prettier url thanks to pretty faces: is that possible?

This topic contains 13 replies, has 3 voices, and was last updated by  Lincoln Baxter III 6 years, 5 months ago.

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

    balteo
    Participant

    Hello,

    I have the following servlet/pattern:

    (app/ConfirmationAbonneServlet?abonneToken=6e0201e0-922d-43fd-b7a0-f2b80dfaef0f)

    I would like for the users only to see a pattern such as:

    (app/confirmationAbonne/6e0201e0-922d-43fd-b7a0-f2b80dfaef0f)

    Is that possible with pretty faces? Can someone help with some sample code or a pointer to the relevant section in the documentation please?

    Note that in this case there’s no jsf implied.

    Thanks in advance,

    Julien.

    #20903

    I for myself always use PrettyFaces in conjunction with JSF, so I’m not a real expert here but you should try something like this:

    <url-mapping id="confirm">
    <pattern value="/confirmationAbonne/#{abonneToken}"/>
    <view-id>/ConfirmationAbonneServlet</view-id>
    </url-pattern>

    See this page for details:

    http://ocpsoft.com/docs/prettyfaces/3.2.0/en-US/html/Configuration.html#config.pathparams

    Or perhaps with a rewrite rule:

    <rewrite match="^/confirmationAbonne/([w-]+)$" substitute="/ConfirmationAbonneServlet?abonneToken=$1" redirect="chain"/>

    See here:

    http://ocpsoft.com/docs/prettyfaces/3.2.0/en-US/html/inbound_rewriting.html#inbound_rewriting.matching

    I hope this helps

    Christian

    #20904

    balteo
    Participant

    Thanks a lot Christian!

    #20905

    balteo
    Participant

    Sorry Christian: One last question: how do I deal with the ampersand in the substitute clause? See below:

    (substitute=”/RedirigeVersSculptureServlet?abonneLocale=$1&sculptureID=$2″)

    J.

    #20906

    balteo
    Participant

    Here is what I tried:

    <rewrite match=”^/redirigeVersSculpture/([w-]+)$/([w-]+)$” substitute=”/RedirigeVersSculptureServlet?abonneLocale=$1#38;sculptureID=$2″ redirect=”chain”/>

    It just won’t match…

    Any idea why?

    J.

    #20907

    balteo
    Participant

    Me again:

    I refined the match clause as follows:

    <rewrite match=”^/redirigeVersSculpture/(fr|en)/(d+)” substitute=”/RedirigeVersSculptureServlet?abonneLocale=$1#38;sculptureID=$2″ redirect=”chain”/>

    I am now getting this:

    ***********************

    com.ocpsoft.pretty.PrettyException: Error occurred during canonicalization of request <[/redirigeVersSculpture/fr/1]>

    com.ocpsoft.pretty.PrettyFilter.rewrite(PrettyFilter.java:223)

    com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:74)

    org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)

    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

    com.jeanbaptistemartin.util.DisableUrlSessionFilter.doFilter(DisableUrlSessionFilter.java:70)

    cause m�re

    ***********************

    I use PF 3.2.1.

    J.

    #20908

    In your first try the first $ character was wrong. $ means “end of line” in a regular expression.

    So it should be something like:

    <rewrite match="^/redirigeVersSculpture/([w-]+)/([w-]+)$" ... />

    Regarding the exception you are seeing. Could you perhaps post so complete stacktrace. There should be a “caused by” part below the stacktrace you have posted.

    #20909

    balteo
    Participant

    Hello Christian,

    Here is my new config:

    <rewrite match=”^/redirigeVersSculpture/(fr|en)/(d+)$” substitute=”/RedirigeVersSculptureServlet?abonneLocale=$1&sculptureID=$2″ redirect=”chain”/>

    Here is the stacktrace:

    ***********************************

    1 mai 2011 14:43:08 org.apache.catalina.core.StandardContext filterStart

    GRAVE: Exception au d�marrage du filtre Pretty Filter

    com.ocpsoft.pretty.PrettyException: Failed to load configuration.

    at com.ocpsoft.pretty.faces.config.PrettyConfigurator.configure(PrettyConfigurator.java:90)

    at com.ocpsoft.pretty.PrettyFilter.init(PrettyFilter.java:305)

    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)

    at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397)

    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)

    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3709)

    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4363)

    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)

    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)

    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)

    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:627)

    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)

    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)

    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)

    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)

    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)

    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)

    at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)

    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)

    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)

    at org.apache.catalina.core.StandardService.start(StandardService.java:516)

    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)

    at org.apache.catalina.startup.Catalina.start(Catalina.java:578)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)

    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

    Caused by: com.ocpsoft.pretty.PrettyException: Failed to parse PrettyFaces configuration from /WEB-INF/pretty-config.xml

    at com.ocpsoft.pretty.faces.config.spi.DefaultXMLConfigurationProvider.loadConfiguration(DefaultXMLConfigurationProvider.java:59)

    at com.ocpsoft.pretty.faces.config.PrettyConfigurator.configure(PrettyConfigurator.java:63)

    … 28 more

    Caused by: org.xml.sax.SAXParseException: The reference to entity “sculptureID” must end with the ‘;’ delimiter.

    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)

    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)

    at com.ocpsoft.shade.org.apache.commons.digester.Digester.parse(Digester.java:1887)

    at com.ocpsoft.pretty.faces.config.DigesterPrettyConfigParser.parse(DigesterPrettyConfigParser.java:69)

    at com.ocpsoft.pretty.faces.config.spi.DefaultXMLConfigurationProvider.loadConfiguration(DefaultXMLConfigurationProvider.java:55)

    … 29 more

    1 mai 2011 14:43:08 org.apache.catalina.core.ApplicationContext log

    INFO: Closing Spring root WebApplicationContext

    1 mai 2011 14:43:09 org.apache.catalina.core.ApplicationContext log

    INFO: ContextListener: contextInitialized()

    1 mai 2011 14:43:09 org.apache.catalina.core.ApplicationContext log

    INFO: SessionListener: contextInitialized()

    #20910

    The & character has a special meaning in XML documents. You should try to replace & with &_amp; (please remove the underscore between & and amp;, I just added it because the forum markup seems to replace this sequence with &).

    See:

    http://www.w3.org/TR/2000/REC-xml-20001006#syntax

    #20911

    balteo
    Participant

    Thank a lot.

    Works very well now and is much cleaner than before thanks to PF!!

    J.

    #20912

    You’re welcome! Let us know if you have any further problems! :)

    #20913

    Is there a reason you opted to use rewrite instead of a url-mapping?

    It looks like what you are doing is simple enough to be done with a pattern and a few query-parameters, unless I’m reading this wrong :)

    -lincoln

    #20914

    <url-mapping>

    <pattern value=/”confirmationAbonne/#{abonneToken}”>

    <view-id value=”/ConfirmationAbonneServlet”>

    </url-mapping>

    That should do what you initially requested, for example.

    #20915

    Sorry, I see now christian posted the same solution.

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

You must be logged in to reply to this topic.

Comments are closed.