You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by "Bober, Kyle" <ky...@gtech.com> on 2001/12/06 17:56:31 UTC

java.io.FileNotFoundException

Hi all,
    I know this issue has been addressed before but all of the response to
the thread have been of no help to me. First of all I will give you my setup
of Cactus to make sure that it is correct:

I am running Suns J2SDKEE1.3 server. To my knowledge this is running tomcat
4.0. I have added junit.jar, cactus,jar, httpclient.jar and log4j-core.jar
to the J2EE_CLASSPATH. That being the servers side classpath. On the client
side I have added the same previous jar files and the cactus.properties
file. 
I have deployed the cactus ServletTestRedirector and can hit it which gives
me a the following: javax.servlet.ServletException: Missing service name
parameter [ServletTestRedirector_Service] in HTTP request.

This I presume acknowledges that the servlet is working. I am using the
Cactus 2.3-1.2 version since tomcat4.0 supports 2.3 servlets. The problem I
am having is running a simple test. I have a servlet called SimpleServlet
and a test class TestSimpleServlet. I can run SimpleServlet and get a
response I can also run TestSimpleServlet and the JUnit gui open up an
executes but all I get is errors. Here is the corresponding error:

java.io.FileNotFoundException:
http://localhost:8000/cactus/ServletRedirector/ 	
          at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection
.java:562)
          at
org.apache.cactus.client.AutoReadHttpURLConnection.getInputStream(AutoReadHt
tpURLConnection.java:127)
          at
org.apache.cactus.client.AbstractHttpClient.doTest(AbstractHttpClient.java:1
36)
          at
org.apache.cactus.AbstractTestCase.runGenericTest(AbstractTestCase.java:422)
          at
org.apache.cactus.ServletTestCase.runTest(ServletTestCase.java:130)
          at
org.apache.cactus.AbstractTestCase.runBare(AbstractTestCase.java:371)

The code for the classes is as follows: (SimpleServlet)

package com.simulti.cactus.servlets;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.ServletConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;

import java.io.IOException;
import java.io.PrintWriter;

import com.simulti.opensource.beans.SimpleBean;

public class SimpleServlet extends HttpServlet
{
	public static String HELLO = "Hello World from a Servlet!!!";

	public void init(ServletConfig sc)
		throws ServletException
	{

		super.init(sc);
		System.out.println(this.getClass().getName()+".init()");
	}

	public void doGet(HttpServletRequest req, HttpServletResponse res)
		throws IOException, ServletException
	{
		System.out.println(this.getClass().getName()+".doGet()");
		doPost(req,res);
	}

	public void doPost(HttpServletRequest req, HttpServletResponse res)
		throws IOException, ServletException
	{

		System.out.println(this.getClass().getName()+".doPost()");
		System.out.println("HELLO : "+HELLO);
		this.setRequestAttribute(req);

		PrintWriter print = res.getWriter();
		res.setContentType("text/html");
		print.print("<html>");
		print.print("<head><title>HTML Hello
Application</title></head>");
		print.print("<body bgcolor=\"#FFFFFF\">");
		print.print("<h1>Hello World from Response Servlet</h1>");
		print.print("</body>");
		print.print("</html>");
		print.close();
	}

	/**
	 *	Test methods for TestSimpleServlet
	 */
	public void setRequestAttribute(HttpServletRequest theRequest)
	{
	
System.out.println(this.getClass().getName()+"setRequestAttribute(HttpServle
tRequest theRequest)");
		theRequest.setAttribute("name_setRequestAttribute",
	        "value_setRequestAttribute");
    }
}



The code for the classes is as follows: (TestSimpleServlet)

package com.simulti.cactus.servlets;

import org.apache.cactus.*;
import org.apache.cactus.util.*;

import junit.framework.*;

import java.util.*;
import java.text.*;
import java.net.*;
import java.io.*;
import javax.servlet.ServletException;

public class TestSimpleServlet extends ServletTestCase
{
	/**
     * Defines the testcase name for JUnit.
     *
     * @param theName the testcase's name.
     */
    public TestSimpleServlet(String theName)
    {
        super(theName);
    }

    /**
     * Start the tests.
     *
     * @param theArgs the arguments. Not used
     */
    public static void main(String[] theArgs)
    {
        junit.ui.TestRunner.main(new String[] {
            TestSimpleServlet.class.getName()});
    }

    /**
     * @return a test suite (<code>TestSuite</code>) that includes all
methods
     *         starting with "test"
     */
    public static Test suite()
    {
        // All methods starting with "test" will be executed in the test
suite.
        return new TestSuite(TestSimpleServlet.class);
    }

	/**
     * Verify that we can set an attribute in the request.
     */
    public void testSetRequestAttribute()
    {
        SimpleServlet servlet = new SimpleServlet();
        servlet.setRequestAttribute(request);

        assertEquals("value_setRequestAttribute",
            request.getAttribute("name_setRequestAttribute"));
    }
}

Thanks all in advance Kyle




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>