Accessing current session in RestfulFilter

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Accessing current session in RestfulFilter

Esteban A. Maringolo
The RESTful filter is part of the Component as a decorator of it, but
if I try to access the current session dynamic variable it is not
available.

How do I do to retrieve the current session in the filter?

Is it possible?

Regards!

Esteban A. Maringolo
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Accessing current session in RestfulFilter

Sven Van Caekenberghe-2
I am sure you know this, but is it not a goal of a REST interface to be stateless, to not have or need a session ?

On 28 May 2014, at 02:08, Esteban A. Maringolo <[hidden email]> wrote:

> The RESTful filter is part of the Component as a decorator of it, but
> if I try to access the current session dynamic variable it is not
> available.
>
> How do I do to retrieve the current session in the filter?
>
> Is it possible?
>
> Regards!
>
> Esteban A. Maringolo
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Accessing current session in RestfulFilter

jtuchel
Sven,

is it possible you mixed in a "not" too much into your post? (sorry,
but  I am not a native english speaker, so I may as well be wrong)
I think you wanted to say that "pure" RESTful interfaces should not need
a session or any other kind of state that survives a single request
cycle. Some implementations or guidelines suggest putting state
information into the request data so that subsequent requests from the
same client can be identified.

BUT this is not a requirement and there is no standard that forbids
using sessions. You can chose to have server side sessions and this may
make perfect sense for some areas where you need to make tradeoffs
between performance/traffic and the share nothing principle.

Joachim

Am 28.05.14 07:28, schrieb Sven Van Caekenberghe:

> I am sure you know this, but is it not a goal of a REST interface to be stateless, to not have or need a session ?
>
> On 28 May 2014, at 02:08, Esteban A. Maringolo <[hidden email]> wrote:
>
>> The RESTful filter is part of the Component as a decorator of it, but
>> if I try to access the current session dynamic variable it is not
>> available.
>>
>> How do I do to retrieve the current session in the filter?
>>
>> Is it possible?
>>
>> Regards!
>>
>> Esteban A. Maringolo
>> _______________________________________________
>> seaside mailing list
>> [hidden email]
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>


--
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          mailto:[hidden email]
Fliederweg 1                         http://www.objektfabrik.de
D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Accessing current session in RestfulFilter

Sven Van Caekenberghe-2

On 28 May 2014, at 08:39, [hidden email] wrote:

> Sven,
>
> is it possible you mixed in a "not" too much into your post? (sorry, but  I am not a native english speaker, so I may as well be wrong)

I don't think so, but English is not my native language either.

> I think you wanted to say that "pure" RESTful interfaces should not need a session or any other kind of state that survives a single request cycle. Some implementations or guidelines suggest putting state information into the request data so that subsequent requests from the same client can be identified.

Yes, that is what I meant.

> BUT this is not a requirement and there is no standard that forbids using sessions. You can chose to have server side sessions and this may make perfect sense for some areas where you need to make tradeoffs between performance/traffic and the share nothing principle.

It would no longer be (pure) REST to me. Think about how your REST clients would have to handle this state, it would make them much more complex.

> Joachim
>
> Am 28.05.14 07:28, schrieb Sven Van Caekenberghe:
>> I am sure you know this, but is it not a goal of a REST interface to be stateless, to not have or need a session ?
>>
>> On 28 May 2014, at 02:08, Esteban A. Maringolo <[hidden email]> wrote:
>>
>>> The RESTful filter is part of the Component as a decorator of it, but
>>> if I try to access the current session dynamic variable it is not
>>> available.
>>>
>>> How do I do to retrieve the current session in the filter?
>>>
>>> Is it possible?
>>>
>>> Regards!
>>>
>>> Esteban A. Maringolo
>>> _______________________________________________
>>> seaside mailing list
>>> [hidden email]
>>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>> _______________________________________________
>> seaside mailing list
>> [hidden email]
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>>
>
>
> --
> -----------------------------------------------------------------------
> Objektfabrik Joachim Tuchel          mailto:[hidden email]
> Fliederweg 1                         http://www.objektfabrik.de
> D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
> Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1
>
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Accessing current session in RestfulFilter

Johan Brichau-2
Esteban,

Did you take a look at WARestfulComponentFilter?
This was something new Philippe introduced in Seaside 3.1 and I believe this is what you need.

Johan

On 28 May 2014, at 09:11, Sven Van Caekenberghe <[hidden email]> wrote:

>
> On 28 May 2014, at 08:39, [hidden email] wrote:
>
>> Sven,
>>
>> is it possible you mixed in a "not" too much into your post? (sorry, but  I am not a native english speaker, so I may as well be wrong)
>
> I don't think so, but English is not my native language either.
>
>> I think you wanted to say that "pure" RESTful interfaces should not need a session or any other kind of state that survives a single request cycle. Some implementations or guidelines suggest putting state information into the request data so that subsequent requests from the same client can be identified.
>
> Yes, that is what I meant.
>
>> BUT this is not a requirement and there is no standard that forbids using sessions. You can chose to have server side sessions and this may make perfect sense for some areas where you need to make tradeoffs between performance/traffic and the share nothing principle.
>
> It would no longer be (pure) REST to me. Think about how your REST clients would have to handle this state, it would make them much more complex.
>
>> Joachim
>>
>> Am 28.05.14 07:28, schrieb Sven Van Caekenberghe:
>>> I am sure you know this, but is it not a goal of a REST interface to be stateless, to not have or need a session ?
>>>
>>> On 28 May 2014, at 02:08, Esteban A. Maringolo <[hidden email]> wrote:
>>>
>>>> The RESTful filter is part of the Component as a decorator of it, but
>>>> if I try to access the current session dynamic variable it is not
>>>> available.
>>>>
>>>> How do I do to retrieve the current session in the filter?
>>>>
>>>> Is it possible?
>>>>
>>>> Regards!
>>>>
>>>> Esteban A. Maringolo
>>>> _______________________________________________
>>>> seaside mailing list
>>>> [hidden email]
>>>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>>> _______________________________________________
>>> seaside mailing list
>>> [hidden email]
>>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>>>
>>
>>
>> --
>> -----------------------------------------------------------------------
>> Objektfabrik Joachim Tuchel          mailto:[hidden email]
>> Fliederweg 1                         http://www.objektfabrik.de
>> D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
>> Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1
>>
>> _______________________________________________
>> seaside mailing list
>> [hidden email]
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Accessing current session in RestfulFilter

Philippe Marschall
In reply to this post by Esteban A. Maringolo
On Wed, May 28, 2014 at 2:08 AM, Esteban A. Maringolo
<[hidden email]> wrote:
> The RESTful filter is part of the Component as a decorator of it,

Are you sure you meant to say component? Didn't you want to say application?

> but
> if I try to access the current session dynamic variable it is not
> available.
>
> How do I do to retrieve the current session in the filter?
>
> Is it possible?

The application looks up the session and sets up the dynamic variable.
The filter runs earlier.

What are you trying to achieve?

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Accessing current session in RestfulFilter

EstebanLM
Hi,

AFAIK, REST purpose is to be stateless, and because of that you do not have the session available when passing through the filter.
Nevertheless, I hacked the REST filter to use it as an bookmarked entry point for my applications (to provide readable urls). What I did is to add this:

(notice that is kind of a hack… probably there is a better way to do this).

MyRestFilter>>#continueWithRoot: aBlock
        "Continues the execution of the application.
         I will execute aBlock with the root component of app"
        | requestContext application session rootComponent |
       
        requestContext := self requestContext.
        application := requestContext application.
        session := self obtainSessionWithApplication: application context: requestContext.

        requestContext
                push: session
                during: [
                        rootComponent := requestContext rootComponentIfAbsent: [ nil ].
                        rootComponent ifNil: [
                                rootComponent := (application preferenceAt: #rootClass) new.
                                requestContext rootComponent: rootComponent ].
                        aBlock value: rootComponent.
                        self next handleFiltered: requestContext ].

MyRestFilter>>#obtainSessionWithApplication: application context: requestContext
        | sessionKey session |
       
        sessionKey  := application trackingStrategy keyFromContext: requestContext.
        session := sessionKey ifNotNil: [  
                application cache
                        at: sessionKey  
                        ifAbsent: [ nil] ].
       
        session  ifNil: [
                session := application newSession.
                application register: session ].
               
        ^ session

with that, I can add some filters like this:

MyRestFilter>>#newScan
        <get>
        <path: '/new'>

        self continueWithRoot: [ :root |
                root show: EveSpyNewTrackPanel new ].

If I understand what I’m doing, this will:

a) look for an active session
a.1) retrieve a new one if not found
b) obtain the root component for active session
c) use #show:, to display the component I want to display.

It works… I don’t know if it can be done better… but that’s how I provide readable urls to my apps usually :)

cheers,
Esteban

On 28 May 2014, at 06:00, Philippe Marschall <[hidden email]> wrote:

> On Wed, May 28, 2014 at 2:08 AM, Esteban A. Maringolo
> <[hidden email]> wrote:
>> The RESTful filter is part of the Component as a decorator of it,
>
> Are you sure you meant to say component? Didn't you want to say application?
>
>> but
>> if I try to access the current session dynamic variable it is not
>> available.
>>
>> How do I do to retrieve the current session in the filter?
>>
>> Is it possible?
>
> The application looks up the session and sets up the dynamic variable.
> The filter runs earlier.
>
> What are you trying to achieve?
>
> Cheers
> Philippe
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Accessing current session in RestfulFilter

Esteban A. Maringolo
In reply to this post by Sven Van Caekenberghe-2
2014-05-28 2:28 GMT-03:00 Sven Van Caekenberghe <[hidden email]>:
> I am sure you know this, but is it not a goal of a REST interface to be stateless, to not have or need a session ?

Yes I know. And because of that I have a separate RestfulHandler which
doesn't need a session at all (or does, by using auth tokens).

In this case what I want, by means of the filter, is a URI that,
whitin the context of a Seaside session, will respond what I want. I
thought the WARestfulFilter was meant to do that. Apparently it
doesn't.

Regards!

Esteban A. Maringolo
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Accessing current session in RestfulFilter

Philippe Marschall
In reply to this post by EstebanLM
On Wed, May 28, 2014 at 1:40 PM, Esteban Lorenzano <[hidden email]> wrote:

> Hi,
>
> AFAIK, REST purpose is to be stateless, and because of that you do not have the session available when passing through the filter.
> Nevertheless, I hacked the REST filter to use it as an bookmarked entry point for my applications (to provide readable urls). What I did is to add this:
>
> (notice that is kind of a hack… probably there is a better way to do this).
>
> MyRestFilter>>#continueWithRoot: aBlock
>         "Continues the execution of the application.
>          I will execute aBlock with the root component of app"
>         | requestContext application session rootComponent |
>
>         requestContext := self requestContext.
>         application := requestContext application.
>         session := self obtainSessionWithApplication: application context: requestContext.
>
>         requestContext
>                 push: session
>                 during: [
>                         rootComponent := requestContext rootComponentIfAbsent: [ nil ].
>                         rootComponent ifNil: [
>                                 rootComponent := (application preferenceAt: #rootClass) new.
>                                 requestContext rootComponent: rootComponent ].
>                         aBlock value: rootComponent.
>                         self next handleFiltered: requestContext ].
>
> MyRestFilter>>#obtainSessionWithApplication: application context: requestContext
>         | sessionKey session |
>
>         sessionKey  := application trackingStrategy keyFromContext: requestContext.
>         session := sessionKey ifNotNil: [
>                 application cache
>                         at: sessionKey
>                         ifAbsent: [ nil] ].
>
>         session  ifNil: [
>                 session := application newSession.
>                 application register: session ].
>
>         ^ session
>
> with that, I can add some filters like this:
>
> MyRestFilter>>#newScan
>         <get>
>         <path: '/new'>
>
>         self continueWithRoot: [ :root |
>                 root show: EveSpyNewTrackPanel new ].
>
> If I understand what I’m doing, this will:
>
> a) look for an active session
> a.1) retrieve a new one if not found
> b) obtain the root component for active session
> c) use #show:, to display the component I want to display.
>
> It works… I don’t know if it can be done better… but that’s how I provide readable urls to my apps usually :)

Here's what you should do:
- subclass WARestfulComponentFilter
- add it to your application
- implement the methods for the URL patterns you need
- send #startSessionWithRoot: in your methods

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside