JigKill

Here is a small tool that allows you to kill (and save!) Jigsaw without
JigAdmin.
Just put the JigKill.java file in Jigsaw/src/classes/org/w3c/jigsaw/admin/ and
compile it (javac JigKill.java).

Usage:

  java org.w3c.jigsaw.admin.JigKill -u <username> -p <password> <admin server
url>

Regards, Benoit.

PS: this tool will be in the next distribution.

--
- Benoît Mahé -------------------------------------------------------
                      World Wide Web Consortium (W3C)
                    Architecture domain - Jigsaw Team

  http://www.w3.org/People/Mahe - bmahe@w3.org - +33.4.92.38.79.89
---------------------------------------------------------------------
// JigKill.java
// $Id: JigKill.java,v 1.1 1999/02/18 10:16:47 bmahe Exp $
// (c) COPYRIGHT MIT, INRIA and Keio, 1999.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.jigsaw.admin;
 
import java.net.URL;
import java.net.MalformedURLException;

import java.util.Vector;

import org.w3c.www.http.HttpCredential;
import org.w3c.www.http.HttpFactory;

import org.w3c.tools.codec.Base64Encoder;

/**
 * Simple class used to kill (and save) Jigsaw.
 * @version $Revision: 1.1 $
 * @author  Benoît Mahé (bmahe@w3.org)
 */
public class JigKill {
    URL    adminURL   = null;
    String username   = null;
    String password   = null;

    /**
     * Usage description.
     */
    protected static void usage() {
	System.err.println("Usage:");
	System.err.println("\tjava JigKill -u <username> -p <password> "+
			   "<admin server url>\n");
	System.exit(-1);
    }

    /**
     * Get all the server's ControlResource.
     * @param admin the admin server (a RemoteResource)
     * @return an array of RemoteResource
     */
    protected RemoteResource[] getControls(RemoteResource admin) 
	throws RemoteAccessException
    {
	String names[] = admin.enumerateResourceIdentifiers();
	Vector vcontrols = new Vector(2);
	for (int i = 0 ; i < names.length ; i++) {
	    if ((! names[i].equals("control")) && 
		(! names[i].equals("realms"))) {
		RemoteResource srr = admin.loadResource(names[i]);
		//load the control node
		RemoteResource control = srr.loadResource("control");
		vcontrols.addElement(control);
	    }
	}
	RemoteResource controls[] = new RemoteResource[vcontrols.size()];
	vcontrols.copyInto(controls);
	return controls;
    }

    /**
     * Kill and save the configuration of the servers and the admin server
     * @exception RemoteAccessException if any remote error occurs.
     */
    protected void kill() 
	throws RemoteAccessException
    {
	AdminContext ctxt = new AdminContext(adminURL);
	HttpCredential credential = HttpFactory.makeCredential("Basic");
	Base64Encoder encoder = new Base64Encoder(username+":"+password);
	credential.setAuthParameter("cookie", encoder.processString());
	ctxt.setCredential(credential);
	ctxt.initialize();
	RemoteResource adminServer = ctxt.getAdminResource();
	RemoteResource ctrls[] = getControls(adminServer);
	//servers
	for (int i = 0 ; i < ctrls.length ; i++) {
	    ctrls[i].loadResource("save");
	    ctrls[i].loadResource("stop");
	}
	//admin servers
	RemoteResource ctrl = adminServer.loadResource("control");
	ctrl.loadResource("save");
	ctrl.loadResource("stop");
	//done
    }

    /**
     * Contructor.
     * @param adminURL the admin server URL
     * @param username the username
     * @param password the password
     */
    public JigKill(URL adminURL, String username, String password) {
	this.adminURL = adminURL;
	this.username = username;
	this.password = password;
    }

    public static void main(String args[]) {
	String username = null;
	String password = null;
	String url      = null;

	try {
	    for (int i = 0 ; i < args.length ; i++) {
		if (args[i].equals("-u")) {
		    username = args[++i];
		} else if (args[i].equals("-p")) {
		    password = args[++i];
		} else {
		    url = args[i];
		}
	    }
	} catch (Exception ex) {}

	if ((username == null) || (password == null) || (url == null))
	    usage();

	URL adminURL = null;
	try {
	    adminURL = new URL(url);
	} catch (MalformedURLException ex) {
	    System.err.println("Invalid URL : "+url);
	    System.exit(-1);
	}
	try {
	    (new JigKill(adminURL, username, password)).kill();
	    System.out.println("Servers killed.");
	} catch (RemoteAccessException ex) {
	    String msg = ex.getMessage();
	    if (msg.equals("Unauthorized"))
		System.err.println("Invalid username/password.");
	    else
		System.err.println("Error : "+msg);
	}
    }
}

Received on Thursday, 25 February 1999 04:56:44 UTC