Re: Cannot get URL param on facebook redirect

Splash Forums PrettyFaces Users Cannot get URL param on facebook redirect Re: Cannot get URL param on facebook redirect

#21158

fabiofrp
Participant

Hey Christian, thanks for the follow up on this.

Actually, my problem was the following:

I had an address of the following format:

http://localhost:8080/app/faces/Index.xhtml?shortURLcode=KTAGFaX&code=HQEzI3qAV8MEeTasFkdZy9dhMZHFzO3F9DvKY7IaSDw.eyJpdiI6Ikl6TnFtQ1pCWkVnbDZyalRnNTFQc2cifQ.n23DuzTG4bzoIp-P7fhF2RSFr-7iy9lKV_kJ0C9sRjHCVvCQjH3QxISF22r4cbydV1qhSPWaa_d23gg79q900a2irSamcabq87KakxqiDqihI

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” />

</url-mapping>

<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 :)