You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andrea Vettori <ma...@andreavettori.com> on 2008/05/27 08:58:25 UTC

[S2] Can an interceptor save the request to use it later ?

Hi,

I have a login interceptor that checks the presence of a token in the  
session. If the token is not present it returns LOGIN; if present it  
invokes the action. LOGIN is a global result that calls the login  
action.

What I want to do is: after the login is completed the system should  
process the original request with all the parameters.

I already can do this composing the request URL getting the action  
name, context, parameters name and values from ActionInvocation in the  
interceptor and storing it in a session variable and after the login  
redirect to that URL.

What I want to know is if it exists a better way to do this, for  
example saving the ActionInvocation object insted of composing the URL  
and then use that to execute the original action in the interceptor.



Something like this :


public String intercept (ActionInvocation ai) {

	if (session contains saved invocation)
		continue that invocation and clear session saved invocation
	else {
		if (session contains token)
			ai.invoke()
		else
			return LOGIN
	}
}



I dont' like using the "composed URL method" even if it works, because  
it has some "hardcoded" values (i.e. the .action suffix) and because  
it converts all parameters to strings and then back to their original  
variables type when the URL is used in the redirect.


Thanks

--
Ing. Andrea Vettori
Consulente per l'Information Technology


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] Can an interceptor save the request to use it later ?

Posted by Andrea Vettori <ma...@andreavettori.com>.
Thanks.

It would also be nice to solve using struts2 objects...

Il giorno 27/mag/08, alle ore 18:03, dusty ha scritto:

>
> That is a problem.  Normally, in the world of redirects you have a  
> handle on
> the current request (POST) and you can dispatch that with the POST  
> method
> and parameters in tact.  But since we have to store the URL and then
> recreate the POST later, then I the only thing I can think of (or  
> found by
> googling) is that you actually have to create a POST request with  
> something
> like HttpClient!  Not ideal.
>
> If I get some time, I will dig into the Spring Security code and see  
> how
> they do it, since I am sure its handled there...
>
>
>
> Andrea Vettori wrote:
>>
>>
>> Il giorno 27/mag/08, alle ore 17:35, dusty ha scritto:
>>
>>>
>>> So you are talking to the ActionInvocation and getting the
>>> components of the
>>> request and then constructing the URL....  If you don't want to
>>> recreate the
>>> URL you could decend a little lower in your interceptor and get the
>>> HttpRequest.   From there you can get the URL as it was sent to the
>>> server
>>> and store that.
>>
>>
>> But what can I do if it was a POST request ?
>>
>>
>>
>> --
>> Ing. Andrea Vettori
>> Consulente per l'Information Technology
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/-S2--Can-an-interceptor-save-the-request-to-use-it-later---tp17484291p17493853.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

--
Ing. Andrea Vettori
Consulente per l'Information Technology


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] Can an interceptor save the request to use it later ?

Posted by dusty <du...@yahoo.com>.
That is a problem.  Normally, in the world of redirects you have a handle on
the current request (POST) and you can dispatch that with the POST method
and parameters in tact.  But since we have to store the URL and then
recreate the POST later, then I the only thing I can think of (or found by
googling) is that you actually have to create a POST request with something
like HttpClient!  Not ideal.   

If I get some time, I will dig into the Spring Security code and see how
they do it, since I am sure its handled there...



Andrea Vettori wrote:
> 
> 
> Il giorno 27/mag/08, alle ore 17:35, dusty ha scritto:
> 
>>
>> So you are talking to the ActionInvocation and getting the  
>> components of the
>> request and then constructing the URL....  If you don't want to  
>> recreate the
>> URL you could decend a little lower in your interceptor and get the
>> HttpRequest.   From there you can get the URL as it was sent to the  
>> server
>> and store that.
> 
> 
> But what can I do if it was a POST request ?
> 
> 
> 
> --
> Ing. Andrea Vettori
> Consulente per l'Information Technology
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-S2--Can-an-interceptor-save-the-request-to-use-it-later---tp17484291p17493853.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] Can an interceptor save the request to use it later ?

Posted by Andrea Vettori <ma...@andreavettori.com>.
Il giorno 27/mag/08, alle ore 17:35, dusty ha scritto:

>
> So you are talking to the ActionInvocation and getting the  
> components of the
> request and then constructing the URL....  If you don't want to  
> recreate the
> URL you could decend a little lower in your interceptor and get the
> HttpRequest.   From there you can get the URL as it was sent to the  
> server
> and store that.


But what can I do if it was a POST request ?



--
Ing. Andrea Vettori
Consulente per l'Information Technology


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] Can an interceptor save the request to use it later ?

Posted by dusty <du...@yahoo.com>.
So you are talking to the ActionInvocation and getting the components of the
request and then constructing the URL....  If you don't want to recreate the
URL you could decend a little lower in your interceptor and get the
HttpRequest.   From there you can get the URL as it was sent to the server
and store that.

I have moved to using Spring Security which works great.  With Acegi
Security the XML was a little overwhelming, but with Spring Security the XML
config has gotten much easier to handle.




Andrea Vettori wrote:
> 
> Hi,
> 
> I have a login interceptor that checks the presence of a token in the  
> session. If the token is not present it returns LOGIN; if present it  
> invokes the action. LOGIN is a global result that calls the login  
> action.
> 
> What I want to do is: after the login is completed the system should  
> process the original request with all the parameters.
> 
> I already can do this composing the request URL getting the action  
> name, context, parameters name and values from ActionInvocation in the  
> interceptor and storing it in a session variable and after the login  
> redirect to that URL.
> 
> What I want to know is if it exists a better way to do this, for  
> example saving the ActionInvocation object insted of composing the URL  
> and then use that to execute the original action in the interceptor.
> 
> 
> 
> Something like this :
> 
> 
> public String intercept (ActionInvocation ai) {
> 
> 	if (session contains saved invocation)
> 		continue that invocation and clear session saved invocation
> 	else {
> 		if (session contains token)
> 			ai.invoke()
> 		else
> 			return LOGIN
> 	}
> }
> 
> 
> 
> I dont' like using the "composed URL method" even if it works, because  
> it has some "hardcoded" values (i.e. the .action suffix) and because  
> it converts all parameters to strings and then back to their original  
> variables type when the URL is used in the redirect.
> 
> 
> Thanks
> 
> --
> Ing. Andrea Vettori
> Consulente per l'Information Technology
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-S2--Can-an-interceptor-save-the-request-to-use-it-later---tp17484291p17493253.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org