current page url?

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

current page url?

Rusty Wright-4
How do I get the url for the current page?  I need it for a redirect back to the current page after the user logs in.  I've tried the following things (in the log.debugs) with no success:

    public String getLoginUrl() {
        this.log.debug("uri: " + this.context.getRequest().getRequestURI());
        this.log.debug("url: " + this.context.getRequest().getRequestURL());
        this.log.debug("contextPath: " + this.context.getRequest().getContextPath());
        this.log.debug("pathInfo: " + this.context.getRequest().getPathInfo());
        this.log.debug("requestedPath: " + HttpUtil.getRequestedPath(this.context.getRequest()));
        this.log.debug("sourcePage: " + this.context.getSourcePage());

        // FIX ME
        return (this.googleUserService.createLoginURL("/"));
    }

Thanks

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: current page url?

Freddy D.
Hi Rusty,

> How do I get the url for the current page?  I need it for a redirect back
> to the current page after the user logs in.

Here's how I do it in the Stripes book:

    public String getLastUrl() {
        HttpServletRequest req = getContext().getRequest();
        StringBuilder sb = new StringBuilder();

        // Start with the URI and the path
        String uri = (String)
            req.getAttribute("javax.servlet.forward.request_uri");
        String path = (String)
            req.getAttribute("javax.servlet.forward.path_info");
        if (uri == null) {
            uri = req.getRequestURI();
            path = req.getPathInfo();
        }
        sb.append(uri);
        if (path != null) { sb.append(path); }

        // Now the request parameters
        sb.append('?');
        Map<String,String[]> map =
            new HashMap<String,String[]>(req.getParameterMap());

        // Remove previous locale parameter, if present.
        map.remove(MyLocalePicker.LOCALE);

        // Append the parameters to the URL
        for (String key : map.keySet()) {
            String[] values = map.get(key);
            for (String value : values) {
                sb.append(key).append('=').append(value).append('&');
            }
        }
        // Remove the last '&'
        sb.deleteCharAt(sb.length() - 1);

        return sb.toString();
    }
 
Cheers,
Freddy
http://www.stripesbook.com

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: New edition of your book?

Freddy D.
Hi Marcus,

> >> How do I get the url for the current page?  I need it for a
> >> redirect back to the current page after the user logs in.
> >>    
> >
> > Here's how I do it in the Stripes book:
> >
> > [...]
>
>
> I am just curious about this: Is there something like a second edition
> of your book? I have the pdf version of your book, but I cannot find
> your posted solution.

The code of the method is not printed in the book; the editor decided
not
to include it to reduce code "noise", since the method is just a lot of
interaction with the Servlet API, and not with Stripes.

Nevertheless, the method is included in the source code bundle[1], and
I refer to it in sections 11.3 and 14.4 (pages 235, 236, and 316 of the
PDF version.)

[1]: http://www.pragprog.com/titles/fdstr/code

Hope that helps.

Cheers,
Freddy
http://www.stripesbook.com

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: current page url?

Rusty Wright-4
In reply to this post by Freddy D.
Lordy, that's a lot of code!  (Seems to me that that could be part of HttpUtil.)

Thanks Freddy.


Freddy Daoud wrote:

> Hi Rusty,
>
>> How do I get the url for the current page?  I need it for a redirect back
>> to the current page after the user logs in.
>
> Here's how I do it in the Stripes book:
>
>     public String getLastUrl() {
>         HttpServletRequest req = getContext().getRequest();
>         StringBuilder sb = new StringBuilder();
>
>         // Start with the URI and the path
>         String uri = (String)
>             req.getAttribute("javax.servlet.forward.request_uri");
>         String path = (String)
>             req.getAttribute("javax.servlet.forward.path_info");
>         if (uri == null) {
>             uri = req.getRequestURI();
>             path = req.getPathInfo();
>         }
>         sb.append(uri);
>         if (path != null) { sb.append(path); }
>
>         // Now the request parameters
>         sb.append('?');
>         Map<String,String[]> map =
>             new HashMap<String,String[]>(req.getParameterMap());
>
>         // Remove previous locale parameter, if present.
>         map.remove(MyLocalePicker.LOCALE);
>
>         // Append the parameters to the URL
>         for (String key : map.keySet()) {
>             String[] values = map.get(key);
>             for (String value : values) {
>                 sb.append(key).append('=').append(value).append('&');
>             }
>         }
>         // Remove the last '&'
>         sb.deleteCharAt(sb.length() - 1);
>
>         return sb.toString();
>     }
>  
> Cheers,
> Freddy
> http://www.stripesbook.com
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> Stripes-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/stripes-users

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: current page url?

Freddy D.
> Lordy, that's a lot of code!

Haha - yep, that's why it wasn't printed in the
Stripes book ;)

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

SpringInterceptor defect?

Leonard Gestrin
Hello,
It appears there is a small defect in SpringInterceptor in stripes-1.5.1

I have two interceptors declared.

SpringInterceptor ,
SecurityInterceptor

Security interceptor checks permissions and might redirect request to outside application if permissions don't pass by doing

RedirectResolution ret = new RedirectResolution("http://landingapp.com", false);


However, when it gets back springInterceptor.
This line

        log.debug("Running Spring dependency injection for instance of ",
                  context.getActionBean().getClass().getSimpleName());

produces NPE because there is actionBean

my work around for now is to make sure SpringInterceptor goes after SecurityIntercepor.

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: SpringInterceptor defect?

Newman, John W
I ran into this one a while ago .. but we switched to a 403 error instead of a redirect resolution so I didn't bother to report it.


I do have a small problem with:

 log.debug("Running Spring dependency injection for instance of ",
                  context.getActionBean().getClass().getSimpleName());

Since there's a good chance the log4j.properties isn't even turned up to debug.  I know the java doc for the log class says

* <p>A <em>wafer thin</em> wrapper around Commons logging that uses var-args to make it
 * much more efficient to call the logging methods in commons logging without having to
 * surround every call site with calls to Log.isXXXEnabled().  All the methods on this
 * class take a variable length list of arguments and, only if logging is enabled for
 * the level and channel being logged to, will those arguments be toString()'d and
 * appended together.</p>

That is great on the surface, the string building is avoided and the varargs is very nice.  

But you see log.trace("string1", reallyExpensiveOperation(), "or", runtimeException(), "or", infiniteLoop()); can be just as bad as the unnecessary string building the log class tried to take care of.
 
IDK if it were my code I'd use isXXXenabled everywhere, but I can see why one would want to avoid that. Just something to consider, it may be worth looking at any references to Log and see if it's worth making the change.  


-----Original Message-----
From: Leonard Gestrin [mailto:[hidden email]]
Sent: Tuesday, October 13, 2009 5:40 PM
To: Stripes Users List
Subject: [Stripes-users] SpringInterceptor defect?

Hello,
It appears there is a small defect in SpringInterceptor in stripes-1.5.1

I have two interceptors declared.

SpringInterceptor ,
SecurityInterceptor

Security interceptor checks permissions and might redirect request to outside application if permissions don't pass by doing

RedirectResolution ret = new RedirectResolution("http://landingapp.com", false);


However, when it gets back springInterceptor.
This line

        log.debug("Running Spring dependency injection for instance of ",
                  context.getActionBean().getClass().getSimpleName());

produces NPE because there is actionBean

my work around for now is to make sure SpringInterceptor goes after SecurityIntercepor.

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: current page url?

Chris Cheshire
In reply to this post by Freddy D.
Freddy,

Is there an accompanying download for the book? I bought the book this
week, and got stuck on this bit of the redirect after login until I
found this thread.

Cheers,

Chris

On Sun, Oct 11, 2009 at 12:11 AM, Freddy Daoud <[hidden email]> wrote:
> Hi Rusty,
>
>> How do I get the url for the current page?  I need it for a redirect back
>> to the current page after the user logs in.
>
> Here's how I do it in the Stripes book:
>
>     public String getLastUrl() {
>


> Lordy, that's a lot of code!

Haha - yep, that's why it wasn't printed in the
Stripes book ;)

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_123012
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: current page url?

Freddy D.
Hi Chris,

There sure is. You can download all the code here:
http://pragprog.com/titles/fdstr/code

Hope that helps.
I hope you enjoy the book!

Cheers,
Freddy

On Sat, Jan 5, 2013, at 09:12 PM, Chris Cheshire wrote:

> Freddy,
>
> Is there an accompanying download for the book? I bought the book this
> week, and got stuck on this bit of the redirect after login until I
> found this thread.
>
> Cheers,
>
> Chris
>
> On Sun, Oct 11, 2009 at 12:11 AM, Freddy Daoud <[hidden email]>
> wrote:
> > Hi Rusty,
> >
> >> How do I get the url for the current page?  I need it for a redirect back
> >> to the current page after the user logs in.
> >
> > Here's how I do it in the Stripes book:
> >
> >     public String getLastUrl() {
> >
>
>
> > Lordy, that's a lot of code!
>
> Haha - yep, that's why it wasn't printed in the
> Stripes book ;)
>
> ------------------------------------------------------------------------------
> Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
> MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
> with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
> MVPs and experts. ON SALE this month only -- learn more at:
> http://p.sf.net/sfu/learnmore_123012
> _______________________________________________
> Stripes-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/stripes-users

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_123012
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: current page url?

Chris Cheshire
Cheers :)

I actually have an alteration to suggest to the getCurrentUrl() code.
It doesn't take into account when the web code is deployed to a
context path other than the default (no path).

For instance, I deploy on my sandbox under a context path equal to the
branch name (in git) when I am developing. So everything is available
at /foo/someAction instead of /someAction.

The getLastUrl() contains the full path including context path and
when that is coupled with a RedirectResolution it ends up as
/foo/foo/someAction, since RedirectResolution automatically prepends
the context path where necessary.

So to fix this I changed getLastUrl() to strip off the context path :

        String contextPath = this.context.getServletContext().getContextPath();

        if (uri == null) {
            uri = req.getRequestURI();
            if (!"".equals(contextPath) && uri.startsWith(contextPath)) {
                uri = uri.substring(contextPath.length());
            }
            path = req.getPathInfo();
        }

Chris

PS Liking the book so far -  it is easy to understand and follow. I
picked it up as a reference to find things that I can do better in my
code.


On Sat, Jan 5, 2013 at 9:21 PM, Freddy Daoud <[hidden email]> wrote:

> Hi Chris,
>
> There sure is. You can download all the code here:
> http://pragprog.com/titles/fdstr/code
>
> Hope that helps.
> I hope you enjoy the book!
>
> Cheers,
> Freddy
>
> On Sat, Jan 5, 2013, at 09:12 PM, Chris Cheshire wrote:
>> Freddy,
>>
>> Is there an accompanying download for the book? I bought the book this
>> week, and got stuck on this bit of the redirect after login until I
>> found this thread.
>>
>> Cheers,
>>
>> Chris
>>
>> On Sun, Oct 11, 2009 at 12:11 AM, Freddy Daoud <[hidden email]>
>> wrote:
>> > Hi Rusty,
>> >
>> >> How do I get the url for the current page?  I need it for a redirect back
>> >> to the current page after the user logs in.
>> >
>> > Here's how I do it in the Stripes book:
>> >
>> >     public String getLastUrl() {
>> >
>>
>>
>> > Lordy, that's a lot of code!
>>
>> Haha - yep, that's why it wasn't printed in the
>> Stripes book ;)
>>

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_123012
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users