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 "Flagg, Kenneth BGI SF" <Ke...@barclaysglobal.com> on 2003/10/11 01:47:58 UTC

Newbie question: implicit objects not initialized in FilterTestCa se

Hello.

I'm running Cactus 1.5-beta1 with Jboss 3.2.2RC2 and JDK 1.4.1.

When I attempt to run my FilterTestCase, I get a NullPointerException when
trying to access the implicit Request object in my textXXX method.   I
created a beginXXX method, and output the values of request, response, and
config, all of which were null.  I also printed the output of theRequest,
which was:

simulation URL = [null], automatic session = [true], cookies = [], headers =
[], GET parameters = [], POST parameters = []

I'm using System.out.println for debugging.  The output from the beginXXX
method is sent to the console where I am running the AWT TestRunner.  The
output from the testXXX method is sent to my JBoss log.

All cactus JARs are in WEB-INF/lib.

I'm somewhat confused as to why the objects aren't being initialized, but
I'm sure it's a configuration problem on my part.  Here are all of the
relevant files:

web.xml:

...
  <!-- CACTUS FILTER -->
  
  <filter>
    <filter-name>FilterRedirector</filter-name>
 
<filter-class>org.apache.cactus.server.FilterTestRedirector</filter-class>
  </filter>
  
  <!-- END CACTUS FILTER -->
...
  <!-- CACTUS FILTER MAPPING -->
  
  <filter-mapping>
    <filter-name>FilterRedirector</filter-name>
    <url-pattern>/FilterRedirector</url-pattern>
  </filter-mapping>

  <!-- END CACTUS FILTER MAPPING -->
...
  <!-- CATCTUS SERVLETS -->
  
  <servlet>
    <servlet-name>ServletRedirector</servlet-name>
 
<servlet-class>org.apache.cactus.server.ServletTestRedirector</servlet-class
>
  </servlet>

  <servlet>
    <servlet-name>JspRedirector</servlet-name>
    <jsp-file>/jspRedirector.jsp</jsp-file>
  </servlet>

  <!-- END CATCTUS SERVLETS -->

cactus.properties (in /WEB-INF/classes of my web-app):

# configuration properties for Cactus
cactus.contextURL = http://localhost:8080/

LoginFilterTest.java:

package test.com.x.y.filter;

import org.apache.cactus.*;
import org.apache.cactus.server.HttpServletRequestWrapper;
import junit.framework.*;
import com.x.y.filter.LoginFilter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

public class LoginFilterTest extends FilterTestCase {

  public LoginFilterTest(String name) {
    super(name);
  }

  public void beginDoFilter(WebRequest theRequest) {
    System.out.println("theRequest is " + theRequest);
    System.out.println("request is " + request);
    System.out.println("response is " + response);
    System.out.println("config is " + config);
  }

  public void testDoFilter() throws ServletException, IOException {
    LoginFilter loginFilter = new LoginFilter();

    System.out.println("request is " + request);
   if (request != null) {
      System.out.println("session is " + request.getSession(true));
    }

    request.getSession(true).removeAttribute("user"); // ensure there is no
user
    
    try {
      loginFilter.doFilter(request, response, filterChain);
      assertNotNull(request.getSession().getAttribute("user"));
    } catch (Exception e) {
      assertNotNull(null);
    }
  }
  public static Test suite() {
    return new ServletTestSuite(LoginFilterTest.class);
  }

  public static void main(String[] theArgs) {
    junit.textui.TestRunner.run(suite());
  }
}

Local console log output:

theRequest is simulation URL = [null], automatic session = [true], cookies =
[],
 headers = [], GET parameters = [], POST parameters = []
request is null
response is null
config is null

JBoss log output:

15:49:08,101 INFO  [UserWrapper] Re-building profile...
15:49:08,101 INFO  [UserWrapper] authStatus is anonymous
15:49:08,288 INFO  [STDOUT] request is null <-- from
LoginFilterTest.testDoFilter()
15:49:08,367 INFO  [UserWrapper] Re-building profile...
15:49:08,367 INFO  [UserWrapper] authStatus is anonymous

Any help would be greatly appreciated.  I only found one other person that
had a similar problem, but there was no relevant response.

Thanks,
Ken