[Seaside] Accessing current session in RestfulFilter
estebanlm at gmail.com
Wed May 28 11:40:44 UTC 2014
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).
"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.
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: [
ifAbsent: [ nil] ].
session ifNil: [
session := application newSession.
application register: session ].
with that, I can add some filters like this:
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 :)
On 28 May 2014, at 06:00, Philippe Marschall <philippe.marschall at gmail.com> wrote:
> On Wed, May 28, 2014 at 2:08 AM, Esteban A. Maringolo
> <emaringolo at gmail.com> 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?
>> if I try to access the current session dynamic variable it is not
>> 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?
> seaside mailing list
> seaside at lists.squeakfoundation.org
More information about the seaside