W3C home > Mailing lists > Public > www-jigsaw@w3.org > March to April 1997

Setting up a multipart mime?

From: Brian Millett <bpm@techapp.com>
Date: Fri, 14 Mar 1997 17:53:05 -0600
To: www-jigsaw@w3.org
Message-ID: <19970314235305.AAA21630@vlad.terraweb.com>
Anselm, I am trying to have a resource generate a multipart mime
replace page.  The general idea is I want a mime type generated of
MimeType.APPLICATION_X_JAVA_AGENT sent with some information, then
replace that part with a regular text/html Content-type.  But I can
not get the Content-type of the reply set!  The part of my code:

ourLocations =
(DirectoryLocations)Naming.lookup( DirectoryLocations.REGISTERED_NAME
);
Vector vector = ourLocations.getDefaultList();

just returns a vector of host names where I have a Directory Service
object running.  Here is the code: (at the end is a trace of
telnetting and GETing the page).  When you look at the trace, you can
see that the Content-Type is not being reset:
"Content-Type: text/html"

What am I doing wrong?
Thanks

// DirSvcLocator.java
// $Id: DirSvcLocator.java,v 1.0
// (c) COPYRIGHT Technology Applications Inc, 1997.
// Please first read the full copyright statement in file COPYRIGHT.html

package w3c.jigsaw.dirsvc;

import java.net.InetAddress;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Enumeration;
import java.util.Vector;

import COM.techapp.dirSvc.server.DirectoryLocations;

import w3c.tools.store.*;
import w3c.www.http.HTTP;
import w3c.jigsaw.http.*;
import w3c.jigsaw.resources.*;
import w3c.jigsaw.forms.*;
import w3c.jigsaw.auth.*;
import w3c.jigsaw.html.*;
import w3c.www.mime.*;

public class DirSvcBootStrap extends HTTPResource {
         
	// The client class application attribute
	protected static int ATTR_CLASSNAME = -1 ;

	// The directory where the DirSvcLocator app is attribute
	protected static int ATTR_DIRSVC_URL = -1 ;
	
    private DirectoryLocations ourLocations;

	static {
		Attribute a   = null ;
		Class     cls = null ;
                 
		try {
			cls = Class.forName("w3c.jigsaw.dirsvc.DirSvcBootStrap");
		} catch (Exception ex) {
			ex.printStackTrace() ;
			System.exit(1) ;
		}
		// Register the client class attribute:
		a = new StringAttribute("Client_Name", null, Attribute.EDITABLE);
		ATTR_CLASSNAME = AttributeRegistry.registerAttribute(cls, a) ;

		// Register the DirSvcLocator attribute:
		a = new StringAttribute("DirSvcLocator_URL", null, Attribute.EDITABLE);
		ATTR_DIRSVC_URL = AttributeRegistry.registerAttribute(cls, a) ;

	}

	// Get the client name attribute as a string
	public String getClassName() {
	return getString(ATTR_CLASSNAME, null);
    }

	// Get the URL of the bootstrap resource
	public String getURLofDirSvcLocator() {
	return getString(ATTR_DIRSVC_URL, null);
    }
	
  	public Reply createMultiPartReply(Request request, int status) {
		Reply reply = super.createDefaultReply(request, status);
		try {
			MimeType multipart = new MimeType("multipart/x-mixed-replace;boundary=*BOUNDARY*");
			reply.setNoStore(true);
			reply.setContentType(null);
			reply.setContentType(multipart);
			reply.addPragma("no-cache");
			return reply;
		} catch ( Exception e ) {
			// We ignore this until the last time.
			HtmlGenerator g = new HtmlGenerator( "ERROR Dude!!" );
			g.append("createMultiPartReply caught the Exception: " + e);
			g.append("Message is ", e.getMessage());
			e.printStackTrace();
			reply.setStream(g);
			return reply;
		}
	}

	/**
	  * Handle a post & get request equally.
	  * @param request The request to handle.
	  * @param data The form decoded data.
	  * @return An HTTP Reply instance.
	  */
	
    public Reply get(Request request) {
		Reply reply = createMultiPartReply(request, HTTP.OK);
		reply.setStream(makeBootStrapPage());
		return reply;
	}
	
    public Reply post(Request request) {
		Reply reply = createMultiPartReply(request, HTTP.OK);
		reply.setStream(makeBootStrapPage());
		return reply;
	}

	public HtmlGenerator makeBootStrapPage() {
		String clientName = getClassName();
		String dirSvcLocator = getURLofDirSvcLocator();
		HtmlGenerator g = new HtmlGenerator( "Start " + clientName + " Client Application" );
		
		g.append( " This is a preamble that is ignored\n" );
		g.append( "\n--*BOUNDARY*\n" );

		g.append( "Content-Type: application/x-java-agent\n\n" );
		try	{
			ourLocations =
				(DirectoryLocations)Naming.lookup( DirectoryLocations.REGISTERED_NAME );
			Vector vector = ourLocations.getDefaultList();
			
			g.append( clientName + " -hosts " );
			for ( Enumeration enumeration = vector.elements();
				  enumeration.hasMoreElements();
					) {
				InetAddress current = (InetAddress) enumeration.nextElement();
				String aHost = current.getHostName();
				g.append(aHost, " ");
			}
			g.append( "\n\n" );
			g.append( "\n--*BOUNDARY*\n" );
			g.append( "Content-Type: text/html\n\n" );
			g.append( "<HTML><HEAD><TITLE>Start ",
					  clientName,
					  " Client Application</TITLE></HEAD><BODY>" );
			g.append( "<h1>"+clientName+" Application Page</h1>" );
			g.append( "\n--*BOUNDARY*--\n" );
			return g;
		}
		
		catch ( Exception e ) {
			// We ignore this until the last time.
			g.append("findDirSvcLocations caught RemoteException: " + e);
			g.append("Message is ", e.getMessage());
			e.printStackTrace();
			return g;
		}
    }
}

-----TRACE----
vlad: telnet vlad 8001
Trying 204.233.138.15 ...
Connected to vlad.
Escape character is '^]'.
GET /CGI/BootStrap HTTP/1.0
 
HTTP/1.0 200 OK
Cache-Control: no-store
Date: Fri, 14 Mar 1997 23:37:19 GMT
Pragma: no-cache
Content-Length: 476
Content-Type: text/html
Last-Modified: Fri, 14 Mar 1997 23:30:44 GMT
Server: Jigsaw/1.0alpha5
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Draft//EN">
<HTML><HEAD>
<TITLE>Start Holiday Client Application</TITLE>
</HEAD>
<BODY> This is a preamble that is ignored
 
--*BOUNDARY*
Content-Type: application/x-java-agent
 
Content-Transfer-Encoding: Quoted-printable
 
Holiday -hosts vlad.terraweb.com 
 
 
--*BOUNDARY*
Content-Type: text/html
 
<HTML><HEAD><TITLE>Start Holiday Client Application</TITLE></HEAD>
<BODY><h1>Holiday Application Page</h1>
--*BOUNDARY*--
</BODY>
</HTML>Connection closed by foreign host.
vlad: 

-- 
Brian Millett                    
Technology Applications Inc.     "Heaven can not exist,
(314) 530-1981                          If the family is not eternal"
bpm@techapp.com                   F. Ballard Washburn
Received on Friday, 14 March 1997 18:48:36 GMT

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