[Seaside] Running ZnZincServerAdaptor outside WAServerManager

Sven Van Caekenberghe sven at stfx.eu
Mon Jan 7 13:10:09 UTC 2013


Hi,

In response to some questions by Norbert Hartl I committed some experimental changes to 'Zinc-Seaside' to make it possible to run ZnZincServerAdaptor outside WAServerManager through an explicitly created and installed ZnSeasideServerAdaptorDelegate. I managed to do this without changing the architecture and thus reusing existing code.

The normal flow is to do something like

	ZnZincServerAdaptor startOn: 8080

This will instanciate a ZnZincServerAdaptor under control of WAServerManager. Upon start a ZnServer will be created automatically, containing a single ZnSeasideServerAdaptorDelegate that forwards the native <--> seaside conversions to the ZnZincServerAdaptor instance. As this is a #register-ed adaptor, WAServerManager will stop/start it automatically on image save/startup.

Some people want more control to let their ZnServer do more work, not just do Seaside serving. What is needed is a way to threat ZnSeasideServerAdaptorDelegate like any other Zn delegate, allowing it to be arbitrarily composed with other delegates.

In the latest version of the code, the following is now possible:

	ZnServer startDefaultOn: 1701.
	ZnSeasideServerAdaptorDelegate installInDefaultServer.

The result of this is that the Zn server runs on port 1701, handling all the standard Zn responses (/welcome, /help, ..), and that additionally, Seaside runs under /seaside.

The main code code doing this is

ZnSeasideServerAdaptorDelegate  class>>#installInServer: znServer underPrefix: prefix
	"Install a ZnSeasideServerAdaptorDelegate in znServer under prefix,
	provided znServer contains a ZnDefaultServerDelegate instance as primary delegate.
	Note that the incoming request is destructively modified.
	Note that a global #serverPath is added to the default Seaside dispatcher."

	| seasideDelegate |
	seasideDelegate := self forServer: znServer.
	znServer delegate
		map: 'seaside'
		to: [ :request | 
			request uri removeFirstPathSegment.
			seasideDelegate handleRequest: request ].
	WAAdmin defaultDispatcher serverPath: prefix.
	^ seasideDelegate

No #start of the adaptor is needed (since it is used inside am already running server). The adaptor is also #unregister-ed (in #forServer:) to prevent WAServerManager from seeing it or doing anything.

I am not a Seaside expert, but as far as I could see, everything works as expected. Remarks ?

Using this technique, more complicated setups with static file serving, redirects, etc.. should be possible.

Sven

--
Sven Van Caekenberghe
http://stfx.eu
Smalltalk is the Red Pill



More information about the seaside mailing list