clean urls and login interceptor problem

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

clean urls and login interceptor problem

Chris Cheshire
I have my web site configured to use the clean urls with no prefix (so
no *.action binding) and also working on implementing the login
interceptor from the Stripes book.

For the most part it is working, except for where I have urls in the
format /someUrl/{someParameter}. When the login interceptor traps a
call to one of these actions, eg. /edit/1234, getLastUrl() is building
a url that looks like /edit/1234?id=1234 (id is the parameter I have
bound in the URL).

Is this just an artifact of the clean urls and binding the fields into
the url like that, or is there something I can do so that the field
name and value isn't passed also as a discrete parameter in the
request parameter map?

Thanks

Chris

------------------------------------------------------------------------------
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: clean urls and login interceptor problem

VANKEISBELCK Remi
Hi Chris,

Le 7 janv. 2013 à 00:37, Chris Cheshire a écrit :

> I have my web site configured to use the clean urls with no prefix (so
> no *.action binding) and also working on implementing the login
> interceptor from the Stripes book.

Are you using DynamicMappingFilter ?

>
> For the most part it is working, except for where I have urls in the
> format /someUrl/{someParameter}. When the login interceptor traps a
> call to one of these actions, eg. /edit/1234, getLastUrl() is building
> a url that looks like /edit/1234?id=1234 (id is the parameter I have
> bound in the URL).

What's getLastUrl() ? Could you post a snippet maybe (don't have the Stripes Book under hand... boooo bad bad bad) ?

>
> Is this just an artifact of the clean urls and binding the fields into
> the url like that, or is there something I can do so that the field
> name and value isn't passed also as a discrete parameter in the
> request parameter map?

Should not repeat your argument anyways if you're using some Stipes API (RediretcResolution.addParameter, s:link, etc.)

Cheers

Remi
------------------------------------------------------------------------------
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. SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122412
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: clean urls and login interceptor problem

Chris Cheshire
On Mon, Jan 7, 2013 at 6:14 PM, Remi VANKEISBELCK <[hidden email]> wrote:

> Hi Chris,
>
> Le 7 janv. 2013 à 00:37, Chris Cheshire a écrit :
>
>> I have my web site configured to use the clean urls with no prefix (so
>> no *.action binding) and also working on implementing the login
>> interceptor from the Stripes book.
>
> Are you using DynamicMappingFilter ?
>

Yes I am. Relevant web.xml config :

  <filter>
    <description>Dynamically maps URLs to ActionBeans.</description>
    <display-name>Stripes Dynamic Mapping Filter</display-name>
    <filter-name>DynamicMappingFilter</filter-name>
    <filter-class>net.sourceforge.stripes.controller.DynamicMappingFilter</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
  </filter-mapping>

  <filter-mapping>
    <filter-name>StripesFilter</filter-name>
    <url-pattern>*.jsp</url-pattern>
    <dispatcher>REQUEST</dispatcher>
  </filter-mapping>

  <filter-mapping>
    <filter-name>StripesFilter</filter-name>
    <servlet-name>StripesDispatcher</servlet-name>
    <dispatcher>REQUEST</dispatcher>
  </filter-mapping>

  <filter-mapping>
    <filter-name>DynamicMappingFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
  </filter-mapping>


>>
>> For the most part it is working, except for where I have urls in the
>> format /someUrl/{someParameter}. When the login interceptor traps a
>> call to one of these actions, eg. /edit/1234, getLastUrl() is building
>> a url that looks like /edit/1234?id=1234 (id is the parameter I have
>> bound in the URL).
>
> What's getLastUrl() ? Could you post a snippet maybe (don't have the Stripes Book under hand... boooo bad bad bad) ?
>

    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();
    }

>>
>> Is this just an artifact of the clean urls and binding the fields into
>> the url like that, or is there something I can do so that the field
>> name and value isn't passed also as a discrete parameter in the
>> request parameter map?
>
> Should not repeat your argument anyways if you're using some Stipes API (RediretcResolution.addParameter, s:link, etc.)
>
> Cheers
>

This is past the URL building phase of the Stripes API. The URL is
correctly built as /action/1234 (where 1234 is bound to the field id).
When it goes through the interceptor it hits the above function. What
is happening is that req.getRequestURI() is returning /action/1234,
and then req.getParameter map also contains a key of id, with value of
1234. The resultant url is then /action/1234?id=1234.

It seems like a problem with the DynamicMappingFilter and how it
treats bound parameters.

Chris

------------------------------------------------------------------------------
Master SQL Server Development, Administration, T-SQL, SSAS, SSIS, SSRS
and more. Get SQL Server skills now (including 2012) with LearnDevNow -
200+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only - learn more at:
http://p.sf.net/sfu/learnmore_122512
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: clean urls and login interceptor problem

VANKEISBELCK Remi

Le 8 janv. 2013 à 16:27, Chris Cheshire a écrit :



What's getLastUrl() ? Could you post a snippet maybe (don't have the Stripes Book under hand... boooo bad bad bad) ?


   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();
   }


Is this just an artifact of the clean urls and binding the fields into
the url like that, or is there something I can do so that the field
name and value isn't passed also as a discrete parameter in the
request parameter map?

Should not repeat your argument anyways if you're using some Stipes API (RediretcResolution.addParameter, s:link, etc.)

Cheers


This is past the URL building phase of the Stripes API. The URL is
correctly built as /action/1234 (where 1234 is bound to the field id).
When it goes through the interceptor it hits the above function. What
is happening is that req.getRequestURI() is returning /action/1234,
and then req.getParameter map also contains a key of id, with value of
1234. The resultant url is then /action/1234?id=1234.

DMF is OK, the problem is your "getLastUrl" method : it concats the param anyway, regardless of the URL binding...

Check our how s:link does the job : it uses the UrkBinding info to recreate correct URLs even with the "clean" URLs.

Cheers

Remi

------------------------------------------------------------------------------
Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery
and much more. Keep your Java skills current with LearnJavaNow -
200+ hours of step-by-step video tutorials by Java experts.
SALE $49.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122612 
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: clean urls and login interceptor problem

Chris Cheshire
OK thanks, I'll take a poke under the hood then.

On Wed, Jan 9, 2013 at 3:35 AM, Remi VANKEISBELCK <[hidden email]> wrote:

>
> Le 8 janv. 2013 à 16:27, Chris Cheshire a écrit :
>
>
>
>
> What's getLastUrl() ? Could you post a snippet maybe (don't have the Stripes
> Book under hand... boooo bad bad bad) ?
>
>
>
>    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();
>    }
>
>
> Is this just an artifact of the clean urls and binding the fields into
>
> the url like that, or is there something I can do so that the field
>
> name and value isn't passed also as a discrete parameter in the
>
> request parameter map?
>
>
> Should not repeat your argument anyways if you're using some Stipes API
> (RediretcResolution.addParameter, s:link, etc.)
>
>
> Cheers
>
>
>
> This is past the URL building phase of the Stripes API. The URL is
> correctly built as /action/1234 (where 1234 is bound to the field id).
> When it goes through the interceptor it hits the above function. What
> is happening is that req.getRequestURI() is returning /action/1234,
> and then req.getParameter map also contains a key of id, with value of
> 1234. The resultant url is then /action/1234?id=1234.
>
>
> DMF is OK, the problem is your "getLastUrl" method : it concats the param
> anyway, regardless of the URL binding...
>
> Check our how s:link does the job : it uses the UrkBinding info to recreate
> correct URLs even with the "clean" URLs.
>
> Cheers
>
> Remi
>

------------------------------------------------------------------------------
Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery
and much more. Keep your Java skills current with LearnJavaNow -
200+ hours of step-by-step video tutorials by Java experts.
SALE $49.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122612 
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users