How do I instantiate a Swazoo site - I just get 404?

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

How do I instantiate a Swazoo site - I just get 404?

Tim M
How do I instantiate a swazoo site - I looked at how tests do it, but
when I try something similar it just doesn't appear in IE?

SwazooServer start.
MySite := Site new name: 'test';  addAlias: (SiteIdentifier
                        ip: '127.0.0.1'
                        port: 8300
                        host: 'localhost').

MySite addResource: (HelloWorldResource uriPattern: 'hello.html').
MySite start.
MySite isServing.

In IE I try: http://localhost:8300/hello.html' and I get a 404.

If I do MySite stop - I get a dns error, so it seems like i'm doing
something right?

Tim


Reply | Threaded
Open this post in threaded view
|

Re: How do I instantiate a Swazoo site - I just get 404?

TimM-3
Hmmm it looks like I always have to have a CompositeResource? Not sure if
anyone can confirm this?

E.g. I had to do the following:

MySite := Site new name: 'test';  addAlias: (SiteIdentifier
ip: '127.0.0.1'
port: 8300
host: 'localhost').

MySite addResource: ((CompositeResource uriPattern: '/')  addResource:
(HelloWorldResource uriPattern: 'hello.html'); yourself).
MySite start.
MySite isServing.


"TimM" <[hidden email]> wrote in message
news:[hidden email]...

> How do I instantiate a swazoo site - I looked at how tests do it, but
> when I try something similar it just doesn't appear in IE?
>
> SwazooServer start.
> MySite := Site new name: 'test';  addAlias: (SiteIdentifier
> ip: '127.0.0.1'
> port: 8300
> host: 'localhost').
>
> MySite addResource: (HelloWorldResource uriPattern: 'hello.html').
> MySite start.
> MySite isServing.
>
> In IE I try: http://localhost:8300/hello.html' and I get a 404.
>
> If I do MySite stop - I get a dns error, so it seems like i'm doing
> something right?
>
> Tim
>


Reply | Threaded
Open this post in threaded view
|

Re: How do I instantiate a Swazoo site - I just get 404?

Andy Bower-3
Tim,

> Hmmm it looks like I always have to have a CompositeResource? Not
> sure if anyone can confirm this?

I don't think you always have to create a CompositeResource but, for
what you are doing, I think this will be the case. Take a look at the
setup methods for the Object Arts Swazoo website and you'll see that,
for the DalekTron and Alchemetrics sites it is possible to use just a
FileResource without first creating a composite:

---
ObjectArtsCentralSwazooServer>>createServer
        self initializeLogs.
        SwazooSiteRegistry
                addSite: self createSite;
                addSite: self createAlchemetricsSite;
                addSite: self createDalektronSite.
        self swazooServer start

ObjectArtsCentralSwazooServer>>createSite
        | thisSite root content mydolphin |
        thisSite := Site new.
        thisSite addAlias: self siteIdentifier.
        thisSite addResource: (FileResource uriPattern: '/' filePath: self
contentPath).
        thisSite addResource: (root := CompositeResource uriPattern: '/').
        root addResource: (CommunityEditionRegistrationResource uriPattern:
'dceregistration' templatePath: self myDolphinTemplatePath).
        root addResource: (ProfessionalTrialRegistrationResource uriPattern:
'trialregistration' templatePath: self myDolphinTemplatePath).
        root addResource: (content := CompositeResource uriPattern: 'content').
        content addResource: (mydolphin := CompositeResource uriPattern:
'mydolphin').
        mydolphin addResource: (MyDolphinResource uriPattern: 'mydolphin'
templatePath: self myDolphinTemplatePath).
        ^thisSite

ObjectArtsCentralSwazooServer>>createAlchemetricsSite
        | thisSite root content mydolphin |
        thisSite := Site new.
        thisSite addAlias: (SiteIdentifier
                                ip: self ipAddress
                                port: self port
                                host: 'www.alchemetrics.org').
        thisSite addResource: (FileResource uriPattern: '/' filePath:
'C:\InetPub\FtpRoot\Alchemetrics\').
        ^thisSite

ObjectArtsCentralSwazooServer>>createDalektronSite
        | thisSite root content mydolphin |
        thisSite := Site new.
        thisSite addAlias: (SiteIdentifier
                                ip: self ipAddress
                                port: self port
                                host: 'www.dalektron.org').
        thisSite addResource: (FileResource uriPattern: '/' filePath:
'C:\InetPub\FtpRoot\Dalektron\').
        ^thisSite
---

Best regards,

--
Andy Bower
Dolphin Support
www.object-arts.com


Reply | Threaded
Open this post in threaded view
|

Swazoo tutorial (was Re: How do I instantiate a Swazoo site - I just get 404?)

Janko Mivšek
In reply to this post by Tim M
Hi Tim,

Recently I posted on [hidden email] short docs and
tutorial. It can help you too:

Swazoo documentation is scarse if non existent. But after you grasp a
few concepts, it is easy. Let me start with those concepts:

1. *Site* : Swazoo can serve many sites at once (virtual sites). Class
   Site is therefore a main class to start configuring your server. It
   holds an IP, port and hostname of your site.
2. *SwazooServer singleton* : return one and only one server which
   holds the Sites.
3. *Resource* is an abstract class for all so called web resources.
   Such resource has its url address and can serve with responding to
   web requests. Every resource need to #answerTo: aHTTPRequest with
   aHTTPResponse. Site is a subclass of a Resource. You can subclass it
   with your own implementation. There is also a CompositeResource,
   which can hold many subresources. Site is also aCopmpositeResource
   and therefore you can add your own resources to your site.
4. classes *HTTPRequest*, *HTTPResponse* are obvious ones.

Here are fewest steps possible to make your Swazoo site running. Do
them from workspace:

   |site|
   site := Site new name: 'test'. "name is just for convinience"
   site host: 'localhost' ip: '127.0.0.1' port: 8888.
   SwazooServer singleton addSite: site.
   site start.

Now let we do our own web resource with url '/helloworld.html' to
return a web page with ' Hello Word!' :

1. Make new class MyResource by subclassing Swazoo.Resource,
2. implement (actually override) a method answerTo: aRequest :

   | response |
   response := Swazoo.HTTPResponse ok.
   response entity: '<html><body><h1>Hello World!</h1></body></html>'.
   ^response

3. from workspace, make instance of your resource, define its url and
   add it to your site:

   | resource composite |
   resource := MyResource new uriPattern: 'helloworld.html'.
   composite := CompositeResource new uriPattern: '/'.
   composite addResource: resource.
   (SwazooServer singleton siteNamed: 'test') addResource: composite.


4. open http://localhost:8888/helloworld.html .


Best regards
Janko Mivšek


TimM wrote:

> How do I instantiate a swazoo site - I looked at how tests do it, but
> when I try something similar it just doesn't appear in IE?
>
> SwazooServer start.
> MySite := Site new name: 'test';  addAlias: (SiteIdentifier
> ip: '127.0.0.1'
> port: 8300
> host: 'localhost').
>
> MySite addResource: (HelloWorldResource uriPattern: 'hello.html').
> MySite start.
> MySite isServing.
>
> In IE I try: http://localhost:8300/hello.html' and I get a 404.
>
> If I do MySite stop - I get a dns error, so it seems like i'm doing
> something right?
>
> Tim