The Artima Developer Community
Sponsored Link

Agile Buzz Forum
More HttpServerTags

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
More HttpServerTags Posted: Feb 2, 2007 5:30 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: More HttpServerTags
Feed Title: Michael Lucas-Smith
Feed URL: http://www.michaellucassmith.com/site.atom
Feed Description: Smalltalk and my misinterpretations of life
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Michael Lucas-Smith

Advertisement

I decided to do some more work on HttpServerTags. I like them so much and they've turned out to be a really good abstraction. Now that I'm using them on a server, it's annoying to have to write start/stop scripts to listen for sockets and run stuff.. so I figured I could make the socket listening pragmas as well. As well as that come a number of other small enhancements, so take a gander below as well as the examples even further down.

Changes:

  • You now subclass ServletTags to add your servlets.
  • ServletTags class side can now define the server addresses to listen on, url matching for requests that come in and host name matching for requests that come in. See examples below.
  • ServletTags instances are given the server, request, response and session as instance variables to avoid passing those around everywhere.
  • Defineing a server address on the class side of a ServletTags subclass automatically starts up a server for you, making development even easier. Servers auto-start on image startup too.

Subclasses of ServletTags are used to define a listener for the TagServer as well as servlets that will respond to requests. This is done using pragmas/tags that define the server address. You can implement a class side method on your subclass of ServletTags with the following pragmas:

examples
	<address: 'http://0.0.0.0' host: 'mycomputer.com'>
	<address: 'http://127.0.0.1' host: 'localhost' url: #( 'thisprogram' )>
	Transcript cr; show: 'My server has started!'

Then on the instance side of your class, you can implement methods that accept the following pragmas:

Tags to define what you're answering:
<get: #()>
<get: #('index.html')>
<get: #('subpage' 'blah.css')>
<post: #('actions')>
<delete: #('webdav')>
<put: #('webdav')>

Tags to define how you're answering:

myMethod
	<get: #()>
	response
		contentType: 'text/plain';
		bodyBlock: [:stream | stream asStringStream nextPutAll: 'Hello World']

myMethod: writer
	<get: #()>
	<html>
	writer html body div text: 'Hello World!'

myMethod: writer
	<get: #()>
	<xml>
	writer helloWorld text: 'Hello World!'

myMethod: stream
	<get: #()>
	<stream: 'text/plain'>
	stream asStringStream nextPutAll: 'Hello World!'

myMethod
	<get: #()>
	<string: 'text/plain'>
	^'Hello World!'

Tags to modify the response and request:

myMethod
	<get: #()>
	<string: 'text/plain'>
	<session>
	^session id printString

Read: More HttpServerTags

Topic: Storp = Store Glorp Previous Topic   Next Topic Topic: Bad philosophy of the west

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use