Cannot get URL param on facebook redirect

Splash Forums PrettyFaces Users Cannot get URL param on facebook redirect

This topic contains 8 replies, has 3 voices, and was last updated by  Christian Kaltepoth 10 years, 6 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
  • #17992


    Hey guys,

    I’m new to prettyfaces so I don’t know if I’m doing something wrong…

    I have the following URL:


    Where the shortURLcode is generated on my application using some code like:

    String callbackURL = “/app/faces/Index.xhtml?shortURLcode=” + URLGenerator.getInstance().getRandomURLKey();

    String redirect_uri = “”;

    redirect_uri = “http://localhost:8080” + FacesContext.getCurrentInstance().getExternalContext().encodeResourceURL(callbackURL);

    return “” +

    client_id + “&display=page&redirect_uri=” +

    redirect_uri +”&scope=”+ StringUtil.delimitObjectsToString(“,”, perms);

    and then facebook redirects to the callbackURL, appending the code parameter.

    I’m trying to having something like


    and I was able to accomplish this using the inbound url rewritting like this:

    <rewrite match=”?code=.+” substitute=”/” redirect=”301″ />

    but then I lose the reference to the code.. which I need to have stored somewhere..

    using url-mappings like the one below don’t seem to work..

    <url-mapping id=”rooms”>

    <pattern value=”/#{ shortURLcode }/#{ /\?code=.+/ code } ” />

    <view-id value=”/app/faces/Index.xhtml” />


    Any suggestions? I’ve been stuck on this for hours :(


    Try a custom rewrite Processor:

    You can create a class to do rewrites in Java, or, if you wait until the morning, I will show you how to use the currently upcoming and unreleased OCPSoft Rewrite library (with the understanding that it is very alpha, but already very stable.) You can try that out if you like. Hang tight.



    Hi Lincoln, thanks for the fast reply.

    I tried to write my own rewrite processor but I had no success (btw, I think the documentation is a bit outdated on that right? I had to implement two methods, one for inbound rewrites and one for outbound, is this correct?)

    I’d be glad to try the new rewrite library if you show me how.



    I don’t know for sure if I fully understand your usecase, but my guess is that you are looking for something like this:

    <rewrite match="/callback/(w+)?code=(w+)" substitute="/faces/Index.xhtml?shortURLcode=$1&code=$2" redirect="301" />

    This way requests like this:


    will be redirected to:


    This way you won’t have to change your existing code as the incoming request is automatically redirected to the URL with the two query parameters.

    I hope this helps :)



    Sorry, there were some typos in my example. Just fixed them! :)



    Hi Christian,

    thanks for the post, but what I really want is a friendly url in the form of

    localhost/shortURLcode (e.g.: localhost/KTAGFaX)

    ..while at the same time store the code parameter (=HQEzI3qAV8MEeTasFkdZy9dhMZHFzO3F9DvKY7IaSDw…….) in the HTTP Servlet request parameter map or in a managed bean (and not show it on the url bar), so I can use it in the code for something else..

    Any hints? Thanks


    Sorry for my late reply. I was very busy the last days.

    Did you find a solution for your problem?

    If not I suggest you to take a look at the custom rewrite processor to implement something like this. My understanding is that you want to create a shorter version of the ugly long code and use this for the callback that Facebook redirects the users to?

    You could try something like this (untested):

    <rewrite match="/shortcode/(w+)" processor="com.example.myapp.MyCustomProcessor" redirect="chain" />

    And the custom rewrite processor:

    public class MyCustomProcessor implements Processor {

    public String processInbound(HttpServletRequest request, HttpServletResponse response, RewriteRule rule, String url) {

    // get the short code by parsing the URL
    String shortCode = getShortCodeFromUrl(url);

    // get the long version of the code
    String code = URLGenerator.getInstance().getCodeFromShortCode(shortCode);

    // forward to the new URL
    return "/faces/Index.xhtml?code="+code;


    public String processOutbound(HttpServletRequest request, HttpServletResponse response, RewriteRule rule, String url) {
    // do nothing
    return url;




    Hey Christian, thanks for the follow up on this.

    Actually, my problem was the following:

    I had an address of the following format:


    I wanted to get the “code” paramater and store it somewhere else.

    I wanted to get the “shortURLcode” parameter and make a pretty URL with it, of the format:

    localhost:8080/shortURLcode (e.g.: localhost:8080/KTAGFaX).

    I managed to do this using the following approach:

    1. Two rules on the prettyfaces config

    <url-mapping id=”rule1″>

    <pattern value=”/#{ shortURLcode }” />

    <view-id value=”/faces/Index.xhtml” />


    <rewrite match=”code=(.+)” processor=”myapp.util.URLProcessor” redirect=”301″ />

    They have to be in this order, so first we have a “pretty” URL pointing to “/faces/Index.xhtml” and then we remove the “code” parameter of the url using…

    2. a custom processor

    public String processInbound(HttpServletRequest request, HttpServletResponse response, RewriteRule rule, String url) {

    String fbAuthCode = url.substring(url.indexOf(“=”) + 1, url.length());

    //System.out.println(“FB code: ” + fbAuthCode);

    // do whatever we want with fb auth code…

    //remove the parameter part appended by facebook

    String returnUrl = url.substring(0, url.indexOf(“?”));

    //return only the pretty url generated by the first rule.

    return returnUrl;


    Thanks a lot for the help, keep up the good work :)


    You’re welcome! Great to hear you got it working!

    Feel free to post again if you have any questions or ideas for improving PrettyFaces! :)


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

The forum ‘PrettyFaces Users’ is closed to new topics and replies.

Comments are closed.