[Prev][Next][Index][Thread]

Re: CGI POST experiment - negative results



John Brown wrote:
> 
> I thought would let you all know the outcome of an experiment
> I tried in order to work around the problem noted in
> the original message cited below. Since this problem is
> now fixed in JavaWebServer (see 'Post on Windows 95' in
> http://jserv.javasoft.com/products/java-server/documentation/webserver1.0.2/release_notes.html
> ) I tried using their patched JRE with Jigsaw. It still
> didn't work. Also, Jigsaw doesn't produce any
> PATH_TRANSLATED environment variable at all.
> 
> original message:
> http://lists.w3.org/Archives/Public/www-jigsaw/msg05537.html
> Subject: cgi POST on NT 4.0 & 3.51
> From: Chris Tomlinson <C.Tomlinson@rosette.com>
> Date: Sat, 12 Apr 1997 18:46:23 -0500
> --------------------------------------------------------------------------------
> I believe that there is a problem with jdk 1.1.1 (and 1.1 I believe)
> that
> prevents the aguments in a POST from reaching the exec'd cgi process.
> It
> appears that the stream that is returned by getOutputStream doesn't
> actually deliver anything that is written on the stream. This leads to
> cgi
> (legacy stuff sometimes just has to be hanled this way) not being
> functional in jisaw (and Sun's Java Webserver as well)
> ciao,
> Christine Tomlinson
> 

One comment concerning the PATH_TRANSLATED problem: 
the same problem has occured in the (very similiar) Java servlet
interface.
This problem was fixed by an update which I have gotten from w3. I have
added the update to this mail. I think that a similar correction would
fix your problem.
	Andreas Bufe

(remark: the POST method works fine with the servlet interface).
<BASE HREF=3D"file:///D|/Jigsaw/upd1.htm">

=46rom - Tue Sep 16 12:57:02 1997
Received: from mail.fth.sbs.de (mail.fth.sbs.de [192.129.41.35]) by marin=
a.fth.sbs.de (8.8.5/8.8.2) with ESMTP id KAA08585 for <Bufe@sbs.de>; Tue,=
 16 Sep 1997 10:57:36 +0200 (MET DST)
Received: from ns.sbs.de (firewall.fth.sbs.de [192.129.41.254])
	by mail.fth.sbs.de (8.8.6/8.8.6) with ESMTP id KAA06779
	for <Bufe@sbs.de>; Tue, 16 Sep 1997 10:58:12 +0200 (MET DST)
Received: from www19.w3.org (www19.w3.org [18.29.0.19])
	by ns.sbs.de (8.8.3/8.8.6) with ESMTP id LAA26361
	for <Bufe@sbs.de>; Tue, 16 Sep 1997 11:00:08 +0200 (MDT)
Received: by www19.w3.org (8.8.5/8.6.12) id EAA21691; Tue, 16 Sep 1997 04=
:36:08 -0400 (EDT)
Resent-Date: Tue, 16 Sep 1997 04:36:08 -0400 (EDT)
Resent-Message-Id: <199709160836.EAA21691@www19.w3.org>
Message-Id: <199709160832.KAA17918@www43.inria.fr>
X-Mailer: exmh version 1.6.9 8/22/96
To: Ross Golder <rossg@cpd.co.uk>
cc: Yves Lafon <ylafon@w3.org>, www-jigsaw@w3.org, bmahe@www43.inria.fr
In-reply-to: Your message of "Mon, 15 Sep 1997 10:21:50 BST."
             <341CFE2D.8F74BAC@cpd.co.uk> =

Mime-Version: 1.0
Content-Type: text/plain; charset=3Diso-8859-1
Date: Tue, 16 Sep 1997 10:32:44 +0200
From: Benoit Mahe <Benoit.Mahe@sophia.inria.fr>
Subject: Re: ServletDirectory resource =

X-List-URL: http://www.w3.org/pub/WWW/Archives/Public/www-jigsaw/
Resent-From: www-jigsaw@w3.org
X-Mailing-List: <www-jigsaw@w3.org> archive/latest/1746
X-Loop: www-jigsaw@w3.org
Sender: www-jigsaw-request@w3.org
Resent-Sender: www-jigsaw-request@w3.org
Precedence: list
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from quoted-printable to 8bit by marina.fth.sbs.de =
id KAA08585
X-UIDL: f08553dbe9e78f5bd4c0ef9bc3d6d2b8
Status: U
X-Mozilla-Status: 0011
Content-Length: 10543


 Hi all!

 I made some modifications in the servlet support of jigsaw in order
 to remove some bugs. One of These bugs appears when the Servlet class =

 file is in the classpath. In this case, the servlet is destroyed and =

 inited on each invocation. This is due to the LocalServletLoader.

 new version of LocalServletLoader.java (in w3c/jigsaw/servlet/ )

---------------
// ServletLoader.java
// $Id: LocalServletLoader.java,v 1.9 1997/09/15 09:56:30 bmahe Exp $
// (c) COPYRIGHT MIT and INRIA, 1996.
// Please first read the full copyright statement in file COPYRIGHT.html

package w3c.jigsaw.servlet;

import java.io.*;
import java.net.*;
import java.util.*;
import java.util.zip.*;

class ServletClassEntry {
  =

  long   classStamp   =3D 0;
  Class  servletClass =3D null;
  File   classFile    =3D null;
  boolean systemClass =3D false;

  public boolean isModified() {
    return (classFile.lastModified() > classStamp);
  }

  public void update() {
    classStamp   =3D classFile.lastModified();
  }

  public ServletClassEntry (File classFile, =

			    Class servletClass, =

			    boolean systemClass) =

  {
    this.classFile    =3D classFile;
    this.servletClass =3D servletClass;
    this.classStamp   =3D classFile.lastModified();
    this.systemClass  =3D  systemClass;
  }

}


/**
 * LocalServletLoader : =

 * @author Benoit Mahe <bmahe@inria.fr>
 */


public class LocalServletLoader extends ClassLoader {
  private static final boolean debug =3D false;
  private Hashtable classes =3D null;

  ServletWrapper wrapper =3D null;

  private void trace(String msg) {
    System.out.println("["+wrapper.getURLPath()+"]: "+msg);
  }

  private String packaged(String name) {
    String cname =3D new String(name);
    try {
      if (cname.endsWith(".class")) {
	int idx =3D cname.lastIndexOf(".");
	cname =3D cname.substring(0,idx);
      } =

      return cname.replace('.', '/')+".class";
    } catch (Exception ex) {
      return null;
    }
  }


  /**
   * Given the class name, return its File name.
   * @param name The class to be loaded.
   * @return The File for the class.
   */

  protected File locateClass(String name) {
    File classfile =3D null;
    File base =3D wrapper.getServletDirectory();
    String cname =3D null;

    cname =3D packaged(name);
    classfile =3D new File(base, cname);

    if (classfile !=3D null)
      if (classfile.exists()) return classfile;
    =

    String classpath =3D (String)System.getProperties().get("java.class.p=
ath");
    StringTokenizer st =3D new StringTokenizer(classpath, ":");
    while (st.hasMoreTokens()) {
      String path =3D st.nextToken();
      if (path.endsWith(".zip")) {
	try {
	  ZipFile zfile =3D new ZipFile(path);
	  ZipEntry zentry =3D zfile.getEntry(cname);
	  if (zentry !=3D null)
	    return new File(path);
	} catch (IOException ex) {}
      } else {
	classfile =3D new File(path,cname);
	if (classfile.exists())
	  return classfile;
      }
    }
    return null;
  }
  =


  public URL getResource(String name) {
    String url =3D wrapper.getServletDirectory().getAbsolutePath();
    // Return the location of that resource (name resolved by j.l.Class)
    if ( File.separatorChar !=3D '/' )
      url =3D url.replace(File.separatorChar, '/');
    try {
      return new URL("file", "localhost", url+"/"+name);
    } catch (MalformedURLException ex) {
      // Shouldn't fall here
      return null;
    }
  }
  =

  /**
   * Get a resource as a stream.
   * @param name The name of the resource to locate.
   */
  =

  public InputStream getResourceAsStream(String name) {
    try {
      URLConnection c =3D getResource(name).openConnection();
      return c.getInputStream();
    } catch (IOException ex) {
      return null;
    }
  }
  =

  protected Class loadClassFile(File file) =

    throws ClassNotFoundException
  {
    byte data[] =3D null;
    if ( file =3D=3D null )
      throw new ClassNotFoundException("invalid servlet base");
    if ( debug )
      trace(" located at "+file);
    try {
      BufferedInputStream in      =3D =

	new BufferedInputStream( new FileInputStream( file) );
      ByteArrayOutputStream out   =3D new ByteArrayOutputStream(512);
      byte                  buf[] =3D new byte[512];
      for (int got =3D 0 ; (got =3D in.read(buf)) > 0 ; )
	out.write(buf, 0, got);
      data =3D out.toByteArray();
      in.close();
    } catch (Exception ex) {
      if (debug) =

	ex.printStackTrace();
      throw new ClassNotFoundException(file.getAbsolutePath());
    }
    // Define the class:
    return defineClass(data, 0, data.length);
  }

  protected Class loadServletClass(String name, boolean resolve)
    throws ClassNotFoundException
  {
    Class c =3D null;
    if ( debug )
      trace("loading servlet class : "+name);

    // Look for a cached class first:
    ServletClassEntry entry =3D (ServletClassEntry)classes.get(name);
    if (entry !=3D null) {
      if (! entry.isModified())
	return entry.servletClass;
      else if (! entry.systemClass) {
	entry.servletClass =3D  loadClassFile(entry.classFile);
	if ( resolve )
	  resolveClass(entry.servletClass);
	entry.update();
	return entry.servletClass;
      }
    }

    SecurityManager s =3D System.getSecurityManager();
    if ( s !=3D null ) {
      int i =3D name.lastIndexOf('.');
      if ( i >=3D 0 )
	s.checkPackageAccess(name.substring(0, i));
    }

    File  file    =3D locateClass(name);
    // Then look for a system class:
    try {
      if ((c =3D findSystemClass(name)) !=3D null) {
	classes.put(name, new ServletClassEntry(file,c,true));
    	return c;
      }
    } catch (Exception ex) {}

    c             =3D loadClassFile(file);
    if ( resolve )
      resolveClass(c);
    classes.put(name, new ServletClassEntry(file,c,false));
    if ( debug )
      trace(name+": loading done.");
    return c;
  }

  protected Class loadClass(String name, boolean resolve)
    throws ClassNotFoundException
  {
    Class c =3D null;
    if ( debug )
      trace("loading class : "+name);

    // Look for a cached class first:
    ServletClassEntry entry =3D (ServletClassEntry)classes.get(name);
    if (entry !=3D null) {
      if (! entry.isModified())
	return entry.servletClass;
      else if (! entry.systemClass) {
	entry.servletClass =3D  loadClassFile(entry.classFile);
	if ( resolve )
	  resolveClass(entry.servletClass);
	entry.update();
	return entry.servletClass;
      }
    }

    SecurityManager s =3D System.getSecurityManager();
    if ( s !=3D null ) {
      int i =3D name.lastIndexOf('.');
      if ( i >=3D 0 )
	s.checkPackageAccess(name.substring(0, i));
    }
    =

    // Then look for a system class:
    try {
      if ((c =3D findSystemClass(name)) !=3D null)
    	return c;
    } catch (Exception ex) {
    }

    File  file    =3D locateClass(name);
    c             =3D loadClassFile(file);
    if ( resolve )
      resolveClass(c);
    classes.put(name, new ServletClassEntry(file,c,false));
    if ( debug )
      trace(name+": loading done.");
    return c;
  }

  protected LocalServletLoader(ServletWrapper wrapper) {
    super();
    this.wrapper =3D wrapper;
    this.classes =3D new Hashtable(13);
  }

  protected LocalServletLoader(LocalServletLoader loader) {
    super();
    this.wrapper =3D loader.wrapper;
    //    this.classes =3D loader.classes;
    this.classes =3D new Hashtable(13);
  }

  public File getClassFile(String name) {
    ServletClassEntry entry =3D (ServletClassEntry)classes.get(name);
    if (entry !=3D null)
      return entry.classFile;
    return null;
  }

  public boolean classChanged(String name) {
    ServletClassEntry entry =3D (ServletClassEntry)classes.get(name);
    if (entry !=3D null) {
      if (debug) {
	System.out.println("entry    : "+name);
	System.out.println("file     : "+entry.classFile.getAbsolutePath());
	System.out.println("Stamp    : "+entry.classStamp);
	System.out.println("System   : "+entry.systemClass);
	System.out.println("modified : "+entry.isModified());
      }
      return entry.isModified();
    }
    return true;
  }

}

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

  in ServletWrapper.java change method launchServlet() by

  protected boolean launchServlet() {
    // Get and check the servlet class:
    if ( servlet !=3D null )
      destroyServlet();
    String clsname =3D getServletClass();
    if ( clsname =3D=3D null ) {
      getServer().errlog(this, "no servlet class attribute defined.");
      return false;
    } else {
      Class c =3D null;
      try {
	if (loader.classChanged(clsname))
	  loader =3D new LocalServletLoader(this.loader);
	c =3D loader.loadServletClass(clsname, true);
      } catch (ClassNotFoundException ex) {
	if ( debug )
	  ex.printStackTrace();
	String msg =3D ("unable to load servlet class \""+
		      getServletClass()+
		      "\" : "+
		      ex.getMessage());
	getServer().errlog(msg);
      }
      return (c !=3D null) ? launchServlet(c) : false;
    }
  }

 =

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

 in JigsawHttpServletRequest.java change method getPathTranslated by

   public  String getPathTranslated()
  {
    String pathinfo =3D getPathInfo();
    if ( pathinfo !=3D null ) {
      httpd server =3D request.getClient().getServer();
      HTTPResource root =3D server.root;
      try {
	LookupState ls =3D new LookupState(pathinfo);
	LookupResult lr =3D new LookupResult(root);
	HTTPResource path =3D null;
	if (root.lookup(ls,lr))
	  path =3D lr.getTarget();
	if (path !=3D null)
	  if (path instanceof FileResource)
	    return ((FileResource)path).getFile().getAbsolutePath();
	  else if (path instanceof DirectoryResource)
	    return ((DirectoryResource)path).getDirectory().getAbsolutePath();
	  else return null;
	else return null;
      }
      catch (HTTPException ex) {return null;}
    }
    return null;
  }

 thanks to Andreas Bufe <AndreasBufe@compuserve.com>
 =

--------

 in JigsawHttpServletResponse.java change method containsHeader

 public boolean containsHeader(String header) {
    return reply.hasHeader(header);
  }

-------

 So, that's all. (I hope :) )
 I made some tests and it seems to work correctly now.

 =

- Beno=EEt Mah=E9 -------------------------------------------------------=

World Wide Web Consortium                       bmahe@sophia.inria.fr =

Architecture domain - Jigsaw Team               tel : 04 93 65 79 89
---------------------------------------------------------------------




References: