WASession


Seaside-Session

Comment:

I am a Seaside session. A new instance of me gets created when an user accesses an application for the first time and is persistent as long as the user is interacting with it.

If the session has not been used for #defaultTimeoutSeconds, it is garbage collected by the system. To manually expire a session call #expire.

Hierarchy:

ProtoObject
Object
WARequestHandler
WAExpiringHandler
WASession

Summary:

instance variables:

application continuations currentRequest escapeContinuation monitor state

methods:

instance class
accessing cookies expiring initializing printing request handling responding state as yet unclassified

Detail:

instance variables:

application
inferredType:
UndefinedObject
continuations
inferredType:
UndefinedObject
currentRequest
inferredType:
UndefinedObject
escapeContinuation
inferredType:
UndefinedObject
monitor
inferredType:
UndefinedObject
state
inferredType:
UndefinedObject

instance methods:

accessing
application

	^ application
mainClass

	^ application preferenceAt: #mainClass

cookies
checkForCookies

	| check |
	check _ WAExternalID new asString.
	self redirectWithCookie: 
		(WACookie new
			key: check;
			value: 'yes';
			expireIn: (Duration seconds: 2);
			yourself).
	^ currentRequest cookies includesKey: check
redirectWithCookie: aCookie

	self redirectWithCookies: (Array with: aCookie)
redirectWithCookies: aCollection

	| response |
	self respond:
		[:url |
		response _ WAResponse redirectTo: url asString.
		aCollection do: [:ea | response addCookie: ea].
		response]

expiring
defaultTimeoutSeconds

	^(self application preferenceAt: #sessionExpirySeconds)
		ifNil: [super defaultTimeoutSeconds]
pageExpired

	state restoreLastSnapshot.
	self redirectWithMessage: 'That page has expired.' delay: 3.
	WAPageExpired raiseSignal.

initializing
initialize

initializeWithApplication: anApplication

	application _ anApplication.
	continuations _ WALRUCache new.
	monitor _ WAProcessMonitor new.
	state _ WAStateRegistry new.
	self initialize.

printing
printOn: aStream

	super printOn: aStream.
	aStream nextPutAll: '(', (application urlForRequestHandler: self) asString, ')'

request handling
actionField

	^ '_k'
currentRequest

	^ currentRequest
errorHandler

	^ application preferenceAt: #errorHandler
incomingRequest: aRequest

	((aRequest fields includesKey: 'terminate')
		and: [(self application preferenceAt: #deploymentMode) not])
			ifTrue: [monitor terminate.  ^ WAResponse new nextPutAll: 'Process terminated'].
			
	^ monitor
		critical: [self responseForRequest: aRequest]
		ifError: [:e | WAResponse internalError: e]
performRequest: aRequest

	| key continuation |
	key _ aRequest fields at: self actionField ifAbsent: [^ self start: aRequest].
	continuation _ continuations at: key ifAbsent: [^ self unknownRequest: aRequest].
	continuation value: aRequest
responseForRequest: aRequest

	currentRequest _ aRequest.
	^ self withEscapeContinuation:
		[WACurrentSession use: self during: [self withErrorHandler: [self performRequest: aRequest]]]
start: aRequest

	self mainClass new start: aRequest
unknownRequest: aRequest

	self pageExpired
withErrorHandler: aBlock

	^ [aBlock
		on: Error
		do: [:e | self errorHandler handleError: e. WAPageExpired raiseSignal]]
		on: Warning
		do: [:w | self errorHandler handleWarning: w. WAPageExpired raiseSignal]
withEscapeContinuation: aBlock

	^ EscapeContinuation currentDo:
			[:cc |
			escapeContinuation := cc.
			aBlock value.
			self pageIntentionallyLeftBlank]

responding
actionUrlForContinuation: aContinuation

	^ self actionUrlForKey: (continuations store: aContinuation)
actionUrlForKey: aString

	^ (application urlForRequestHandler: self)
		addParameter: self actionField value: aString;
		yourself
closePopup

	^ self respond:
		[:url |
		WAResponse new
			nextPutAll: '<html><script>';
			nextPutAll: 'self.close();';
			nextPutAll: 'self.opener.location=self.opener.location';
			nextPutAll: '</script></html>';
			yourself]
closePopupAndContinue

	^ self respond:
		[:url |
		WAResponse new
			nextPutAll: '<html><script>';
			nextPutAll: 'self.close();';
			nextPutAll: 'self.opener.location=',url asString printString;
			nextPutAll: '</script></html>';
			yourself]
pageIntentionallyLeftBlank

	self returnResponse: WAResponse new
redirect

	^ self respond: [:url | WAResponse redirectTo: url asString]
redirectTo: urlString

	self returnResponse: (WAResponse redirectTo: urlString)
redirectWithMessage: aString delay: aNumber

	self respond:
		[:url |
		WAResponse
			refreshWithMessage: aString
			location: url asString
			delay: aNumber].
respond: responseBlock

	|request snapshotHolder response oldEscape |
	snapshotHolder _ ValueHolder new.
	oldEscape _ escapeContinuation.
	escapeContinuation _
		[:v |
		snapshotHolder contents: state snapshot.
		oldEscape value: v].
	request _ 
	ResponseContinuation currentDo:
		[:cc ||url|
		url _ self actionUrlForContinuation: cc.
		response _ responseBlock value: url.
		self returnResponse: response].
	state restoreSnapshot: snapshotHolder contents.
	^ request 
returnResponse: aResponse

	escapeContinuation value: aResponse
script: aString

	self redirectWithMessage: '<script>', aString, '</script>' delay: 0

state
registerObjectForBacktracking: anObject

	state registerObject: anObject

class methods:

as yet unclassified
application: anApplication

	^ self basicNew initializeWithApplication: anApplication

^top


- made by Dandelion -