W3C home > Mailing lists > Public > www-jigsaw@w3.org > January to February 1998

Re: Config Jigsaw 2.0alpha1 for VirtualHosting

From: Yves Lafon <ylafon@w3.org>
Date: Tue, 10 Feb 1998 11:51:17 +0100 (MET)
To: Stefan Speidel <sp@tp-cad.com>
cc: www-jigsaw@w3.org
Message-ID: <Pine.SOL.3.91.980210114358.12458B-200000@tarantula.inria.fr>
On Tue, 4 Feb 1997, Stefan Speidel wrote:

> How can I configurate Jigsaw 2.0alpha1 for Doing VirtualHosting?
> Thanks for Helping.

You will have to add and compile the attached source code.
It must be in the org.w3c.jigsaw.frames package.
The way to configure it is more or less like in the previous version.
1/ create a ContainerResource 
(org.w3c.tools.resources.ContainerResource). Let's call it 'virtual' 
2/ add a VirtualHostFrame to this resource 
(org.w3c.jigsaw.frames.VirtualHostFrame).
3/ Then change the followup in the attributes of this frame (setting it 
to 'root' is a safe bet)
4/ In the properties, change the root resource to be 'virtual' or 
whatever name you choose.
5/ add PassDirectories to the space you want to export with the 
name(:port if not 80) of your virtual host.

6/ Don't forget to add an HTTPFrame to those PassDirectories!
Save everything and you are set up :)

      /\          - Yves Lafon - World Wide Web Consortium - 
  /\ /  \                Architecture Domain - Jigsaw
 /  \    \/\    
/    \   /  \   http://www.w3.org/People/Lafon - ylafon@w3.org    


// VirtualHostFrame.java
// $Id: VirtualHostFrame.java,v 1.1 1998/02/09 14:54:51 ylafon Exp $
// (c) COPYRIGHT MIT and INRIA, 1998.
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.jigsaw.frames;

import org.w3c.tools.resources.*;
import org.w3c.jigsaw.http.* ;

public class VirtualHostFrame extends HTTPFrame {

    /**
     * Attribute index - The default root (for unknown hosts)
     */
    protected static int ATTR_FOLLOWUP = -1;

    static {
	Class     c = null;
	Attribute a = null;

	try {
	    c = Class.forName("org.w3c.jigsaw.frames.VirtualHostFrame");
	} catch (Exception ex) {
	    ex.printStackTrace();
	    System.exit(1);
	}
	// Register our default root:
	a = new StringAttribute("followup"
				, null
				, Attribute.EDITABLE);
	ATTR_FOLLOWUP = AttributeRegistry.registerAttribute(c, a);
    }

    protected ResourceReference followup = null;

    /**
     * Get the name of the resource used as a followup.
     * @return A String giving the name of the resource to be used as the
     * default.
     */

    public String getFollowup() {
	return getString(ATTR_FOLLOWUP, null);
    }

    public void registerResource(FramedResource resource) {
	super.registerOtherResource(resource);
    }

    /**
     * Lookup the followup resource.
     * @return The loaded resource for the current followup.
     */

    public synchronized ResourceReference lookupFollowup() {
	if ( followup == null ) {
	    String name  = getFollowup();
	    if ( name != null ) 
		followup = getServer().loadRoot(name);
	    if ( followup == null ) {
		getServer().errlog(getIdentifier()
				   + "[" + getClass().getName() + "]: "
				   + "unable to restore \"" + name + "\" "
				   + " from root store.");
	    }
	}
	return followup;
    }

    public boolean lookupOther(LookupState ls, LookupResult lr) 
	throws ProtocolException
    {
        // If this is an internal lookup, it's pretty easy:
	if ( ls.isInternal() ) {
	    return super.lookupOther(ls, lr);
	}
	// Try to lookup on the host header:
	ResourceReference vrroot = null;
	ContainerResource root = null;
	
	root = (ContainerResource)getResource();
	Request r = (Request)ls.getRequest();
	if ( r != null ) {
	    String  host = r.getHost();
	    if ( host != null ) {
		vrroot = root.lookup(host.toLowerCase());
	    }
	}
	if ( vrroot == null )
	    vrroot  = lookupFollowup();
	// Check for what we got:
	if (vrroot == null)
	    return super.lookupOther(ls, lr);
	try {
	    FramedResource resource = (FramedResource) vrroot.lock();
	    return (resource != null ) ? resource.lookup(ls, lr) : false;
	} catch (InvalidResourceException ex) {
	    return false;
	} finally {
	    vrroot.unlock();
	}
    }
}
Received on Tuesday, 10 February 1998 05:51:42 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 9 April 2012 12:13:27 GMT