Redirect request.contextPath for HTTPS protocol

Splash Forums PrettyFaces Users Redirect request.contextPath for HTTPS protocol

This topic contains 11 replies, has 4 voices, and was last updated by  Lincoln Baxter III 5 years, 9 months ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #17869

    Event
    Participant

    Is there a better way to pass seamlessly from http to https in regards to the following class:

    #{request.contextPath}

    <url-mapping id=”home”>

    <pattern value=”/home” />

    <view-id>#{url.getHomeUrl}</view-id>

    </url-mapping>

    We can create a two step redirect but there must be a better way, please help if you’ve come across this ideally I am looking for a solution that would be represented below:

    <url-mapping id=”store”>

    <pattern value=”https://website/store&#8221; />

    <view-id>#{url.getStoreUrl}</view-id>

    </url-mapping>

    Thank you in advance

    #20663

    What exactly is your requirement? Do you want to redirect the user to the https:// URL every time he tries to use http://?

    I’m note sure if you can handle this with existing PrettyFaces features. But many special use cases can be implemented by building a customer rewrite processor:

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

    Perhaps something like this:

    <rewrite processor="com.example.ForceSSLProcessor" />

    public class ForceSSLProcessor implements Processor {

    public String process(final RewriteRule rewrite, final String url) {
    return url.replaceAll("^http://", "https://");
    }

    }

    #20664

    Event
    Participant

    Most of the site is in http, however I need to change protocol (http>https) when the user clicks the purchase button and is redirected to the secure purchase page, i.e. the store in the URL-mapping.

    I’m hoping there is a simpler way of doing this than using a custom processor.

    #20665

    Hey Event,

    I’m sorry, I had another look at the PrettyFaces code and just saw that my suggested solution won’t work as I initially thought. Its because rewrite processors are also based on working with URLs relative to the webapps context path.

    I think currently you have only one option:

    <rewrite match="^/store$" url="https://website/store" redirect="301" />

    Unfortunately this will work only for exactly one URL. So you will have to add multiple rules if you want multiple URLs to be automatically redirected to the https version.

    I know that this is not a very nice solution. But it will work.

    If you have any idea how to integrated something like this better into PrettyFaces, let us know. We are always open for any kind of suggestion.

    Perhaps something like this?

    <rewrite match="^/store.*$" redirect="301" sslRequired="true" />

    #20666

    I should add that we are working on enhancing the Processor interface to provide access to both HttpServletRequest and HttpServletResponse objects. This will mean that you can ‘literally’ do any kind of custom rewriting needed.

    #20667

    Event
    Participant

    Thank you for the replies.

    I’ve found a simple turnaround in my code: I can set all my buttons to redirect to the store page (https section of the site) like this:

    Home

    Store

    I have tested it but it seems not working, it gives me the “page not found” error. I think that pretty is using the original context path (http://website/) and cannot map with this “new” context path.

    Do you know if there is a way to change the context path?

    #20668

    So you are manually creating <a> links? Could you explain “page not found” error? What URL is not working?

    And what do you mean by “old” and “new” context path? You are using one web application, right? But it should be accessible via http and https or am I mistaken? So there will be just one context path.

    #20669

    bcn
    Participant

    Hello,

    I am facing the same problem. Has the latest version any enhancement to redirect to https?

    When a user clicks the login button, I redirect to the same page by ExternalContext.redirect(), but with https scheme. But then, any navigation with pretty:link fails with

    com.ocpsoft.pretty.PrettyException: Mapping id was null when attempting to build URL for component: com.ocpsoft.pretty.faces.component.Link@7b021ddc <pretty_services_sub_17>

    Thanks

    #20670

    bcn
    Participant

    This is indeed very strange, because if I access the https page directly after deployment, all links work as expected. I can navigate the whole site in http or https, but I cannot redirect from one to the other without the pretty links stopping to work.

    #20671

    bcn
    Participant

    I found the cause of the exception, one link was missing the mappingId attribute.

    The original question about any enhancement stays the same.

    Thanks

    #20672

    Unfortunately there is are no enhancements regarding SSL at the moment.

    But perhaps you could take a look at Rewrite which will be the new core for PrettyFaces 4.0. Rewrite offers much more features. But there is currently no documentation and only some sample code.

    http://ocpsoft.com/rewrite/

    #20673

    What kind of enhancements would you like to see regarding this issue? Suggestions welcome :)

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

You must be logged in to reply to this topic.

Comments are closed.