Howdy folks.

I'm having trouble with my servlet again...please don't laugh at my 
attempts! I have placed the jess.Main file into my servlet, and I've been 
fiddling with it to try and get it to work. I'm getting the following error, 
and I can't work out why. Please note that the code compiles just fine.
Also note, my jess folder is located within the servlet directory (it 
wouldn't work for me otherwise):

c:\jdk1.2.2\jsdk2.1\examples\Web-inf\servlets\jess

but the source jess file (proto.clp) would only open when I placed it in the 
server root directory:

c:\jdk1.2.2\jsdk2.1

and I moved the scriptlib.clp file there also, otherwise I got "can't open 
file error" in the Dos window.

With all that "fixed", I run my servlet Proto.class, from an html page with 
this code:

<FORM METHOD=GET ACTION="../servlet/Proto">Enter "start"
          <INPUT TYPE=TEXT NAME="name">
          <P>
          <INPUT TYPE=SUBMIT>
          </FORM>

and that submits ok, but then the response I get is:

Error: 500
Internal Servlet Error:

java.lang.NullPointerException
        at Proto.doGet(Proto.java:35)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:715)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
        at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:140)
        at com.sun.web.core.InvokerServlet.service(InvokerServlet.java:169)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
        at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:140)
        at com.sun.web.core.Context.handleRequest(Context.java:375)
        at com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:135)



My source code (adapted jess.Main) is as follows:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.net.*;
import jess.*;

public class Proto extends HttpServlet implements Serializable, JessListener 
{


  private Rete m_rete;
  private Reader m_fis;
  private Jesp m_j;
  private boolean m_readStdin = true;



// invoked by the browser doing a GET

        public void doGet(HttpServletRequest req, HttpServletResponse res)
                throws ServletException, IOException
        {
                res.setContentType("text/html");
                PrintWriter out = res.getWriter();



                String name = req.getParameter("name");
                String s = "proto.clp";


          if (name.equals("start"))
                {
                Proto m = new Proto();
                m.initialize(s, new Rete());
                m_rete.addOutputRouter("t", res.getWriter()); //send standard output 
from JESS to the servlet's output

                m.execute(true);
          }


        }


/** **********************************************************************
* A command-line interface for Jess; also displayed in a window by the
* Console classes.
* <P>
* (C) 1998 E.J. Friedman-Hill and the Sandia Corporation
********************************************************************** */





  /**
   * Set a Main object up for later execution.
   * @param argv Command-line arguments
   * @param r An initialized Rete object, with routers set up
   */
  public Proto initialize(String proto, Rete r)
  {
    m_rete = r;

/*
    // 
**********************************************************************
    // Process any command-line switches
    int argIdx = 0;
    boolean doLogo=false;

    if (argv.length > 0)
      while(argIdx < argv.length && argv[argIdx].startsWith("-"))
      {
        if (argv[argIdx].equals("-nologo"))
          doLogo = false;
        argIdx++;
      }

    // 
**********************************************************************

  */
    // 
**********************************************************************
    // Open a file if requested
    m_fis = m_rete.getInputRouter("t");
    String name = proto;

    try
      {
        if (name != null)
          {
            if (m_rete.getApplet() == null)
              m_fis = new FileReader(name);
            else
              {
                URL url
                  = new URL(m_rete.getApplet().getDocumentBase(),
                            name);
                m_fis = new InputStreamReader(url.openStream());
              }
            m_readStdin = false;
          }
      }
    catch (IOException ioe)
      {
        m_rete.getErrStream().println("File not found or cannot open file:" 
+
                                 ioe.getMessage());
        m_rete.getErrStream().flush();
        System.exit(0);
      }


    // 
**********************************************************************
    // Load in optional packages, but don't fail if any are missing.
    String [] packages = { "jess.BagFunctions",
                           "jess.ViewFunctions" };

    for (int i=0; i< packages.length; i++)
      {
        try
          {
            m_rete.addUserpackage((Userpackage)
                                Class.forName(packages[i]).newInstance());
          }
        catch (Throwable t) { /* Optional package not present, OK */ }
      }

    // 
**********************************************************************
    // Arrange for handling of the 'bsave' & 'bload' commands

    try
      {
        DumpFunctions df = new DumpFunctions();
        m_rete.addUserpackage(df);
        df.addJessListener(this);

    // 
**********************************************************************
    // Read script library file, if one exists; arrange to have it reloaded 
on CLEAR

        m_rete.executeCommand("(batch scriptlib.clp)");
        m_rete.addJessListener(new JessListener() {
          public void eventHappened(JessEvent je) {
            if (je.getType() == JessEvent.CLEAR)
              {
                try
                  {
                    m_rete.executeCommand("(batch scriptlib.clp)");
                  }
                catch (JessException re) {}
              }
          }
        });
      }
    catch (JessException re)
      {
        m_rete.getErrStream().println("Error processing script library 
file:");
        re.printStackTrace(m_rete.getErrStream());
        if (re.getNextException() != null)
          {
            m_rete.getErrStream().println("Nested exception is:");
            re.getNextException().printStackTrace(m_rete.getErrStream());
          }
        m_rete.getErrStream().flush();
      }

    return this;
  }

  /**
   * Repeatedly parse and excute commands, from location determined during 
initialize().
   * @param doPrompt True if a prompt should be printed, false otherwise.
   * Prompts will never be printed during a (batch) command.
   */

  public void execute(boolean doPrompt)
  {
    // 
**********************************************************************
    // Process input from file or keyboard

    if (m_fis != null)
      {
        m_j = new Jesp(m_fis, m_rete);
        do
          {
            try
              {
                // Argument is 'true' for prompting, false otherwise
                m_j.parse(doPrompt && m_readStdin);
              }
            catch (BloadException re)
              {
                m_rete.getErrStream().println("(bload) called, engine 
restarting...");
              }
            catch (JessException re)
              {
                if (re.getNextException() != null)
                  {
                    m_rete.getErrStream().write(re.toString());
                    m_rete.getErrStream().write("\nNested exception is:\n");
                    
re.getNextException().printStackTrace(m_rete.getErrStream());
                  }
                else
                  re.printStackTrace(m_rete.getErrStream());
              }
            catch (Exception e)
              {
                m_rete.getErrStream().println("Unexpected exception:");
                e.printStackTrace(m_rete.getErrStream());
              }
            finally
              {
                m_rete.getErrStream().flush();
                m_rete.getOutStream().flush();
              }
          }
        // Loop if we're using the command line
        while (m_readStdin);
      }
    // If called again, read stdin, not batch file
    m_readStdin = true;
    m_fis = m_rete.getInputRouter("t");
  }

  /**
   * @param je
   * @exception BloadException
   */
  public void eventHappened(JessEvent je) throws JessException
  {
    if (je.getType() == JessEvent.BLOAD)
      {
        // Restart engine. This won't work right if bload is called from a
        // command-line argument file
        m_rete = (Rete) je.getObject();
        m_j = new Jesp(m_fis, m_rete);

        // Reinstall listener
        DumpFunctions df = new DumpFunctions();
        m_rete.addUserpackage(df);
        df.addJessListener(this);
        throw new BloadException();
      }
  }

  class BloadException extends JessException
  {
    BloadException() { super("(bload)", "engine restarting...", ""); }
  }

}


Any help greatly appreciated. Debbie Lampon


______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list (use your own address!) List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------

Reply via email to