W3C home > Mailing lists > Public > www-jigsaw@w3.org > July to August 1997

Follow up on multipart/x-mixed-replace

From: Nirmalkumar - Patil <npatil@cs.tamu.edu>
Date: Sun, 3 Aug 1997 15:47:01 -0500 (CDT)
Message-Id: <199708032047.PAA12582@dilbert.cs.tamu.edu>
To: www-jigsaw@w3.org

Hi

I wrote the following piece to implement the multipart/x-mixed-replace
MIME type.  It appears that everything is being written onto the 
socket connection fine but Netscape is not able to interpret whatever
is received...

Can anyone tell me where I am going wrong here.

Thanks,
  Nirmal.
  npatil@cs.tamu.edu

-------------

// JigsawTest4.java
package w3c.jigsaw.contrib;

import java.util.*;
import java.io.*;

import w3c.jigsaw.http.*;
import w3c.jigsaw.forms.*;
import w3c.jigsaw.html.*;

import w3c.tools.store.*;
import w3c.www.http.*;
import w3c.www.mime.*;
import w3c.jigsaw.resources.*;

public class JigsawTest4 extends HTTPResource {

  StringBuffer buf = null;
  String contents = null;
  static int testvar = 1;
  //private Thread tr = null;
  InputStream in = null;
  DataOutputStream dos = null;

  // Boundary attribute index
  protected static int ATTR_BOUNDARY = -1;

  static {
    Attribute a = null;
    Class cls   = null;
    try {
      cls = Class.forName("w3c.jigsaw.contrib.JigsawTest4");
    } catch(Exception e) { e.printStackTrace(); System.exit(1); }

    a = new     StringAttribute("boundary","somebdry",Attribute.EDITABLE);
    ATTR_BOUNDARY = AttributeRegistry.registerAttribute(cls,a);
  }

  public Reply get(Request request) 
  //public Reply post(Request request) 
                throws HTTPException {

    String pnames[] = {"boundary"};
    String pvalues[] = new String[1];
    pvalues[0] = (String)getValue(ATTR_BOUNDARY,null);
    MimeType mtype = new MimeType("multipart","x-mixed-replace",pnames,pvalues);

    Client client = request.getClient();

    if ( client != null ) 
      dos = client.getOutputStream();
    else System.out.println("Could not get ref. to output stream");

    // Dump the headers
    Reply reply = request.makeReply(HTTP.OK);
    reply.setContentType(mtype);
    reply.setKeepConnection(true);
    reply.dump(dos);
    //System.out.println("So far so Good");

    try {
      //dos.writeChars("Content-Type: multipart/x-mixed-replace;boundary=somebdry\n");
      dos.writeChars("--somebdry\n");
      dos.flush();
    } catch( Exception e) {e.printStackTrace();}


    String separator = "--"+getValue(ATTR_BOUNDARY,null)+"\n";
    System.out.println(separator);


    // Write the boundary to the stream before 
    //buf = new StringBuffer();
    while( client.isRunning() ) {
      if( client.isInterrupted() ) 
        break;
      buf = new StringBuffer();
      buf.append("Content-Type: text/plain \n\n");
      buf.append("I am testing !! "+(new Integer(testvar)).toString()+"\n");
      testvar++;
      buf.append("\n");
      buf.append(separator+"\n");
      try {
        dos.writeChars(buf.toString());
        dos.flush();
      } catch (IOException e) { 
        e.printStackTrace(); 
        Thread th = Thread.currentThread();
        th.stop();
      }  
      try { 
        System.out.println("Sleeping now");
        Thread.sleep(1500);
      } catch (Exception e) { e.printStackTrace(); }
     
    }

    reply.setStream((InputStream)null);
    return reply;
    //return null;
  }

}



-------------
Received on Sunday, 3 August 1997 16:49:14 GMT

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