Thank you for your answer. Looking at my web.xml, there is a <filter-mapping/> entry for the filter in question. I'll remove it and see what happens.

Frederic

Kazuhito SUGURI wrote:
Hi Frederic,

In article <[EMAIL PROTECTED]>,
Fri, 25 Feb 2005 09:51:09 -0700,
Frederic Jean <[EMAIL PROTECTED]> wrote: 
Frederic> I'm trying to test an authorization type filter. Under some 
Frederic> circumstances, the filter has to return an HTTP response code of 403 
Frederic> (Forbidden).
Frederic> 

Frederic> When I try to test the filter under conditions where it should return a 
Frederic> 403, I get the following exception instead:
Frederic> 
Frederic>     [cactus] Testcase: testNoAssetId took 0.087 sec
Frederic>     [cactus]    Caused an ERROR
Frederic>     [cactus] Failed to get the test results at 
Frederic> [http://localhost:8880/delivery-cactus/test/filterRedirector.jsp]
Frederic>     [cactus] org.apache.cactus.util.ChainedRuntimeException: Failed to 
Frederic> get the test results at 

As a possible case, your web.xml may contains filter-mapping entry
which applies the filter to requests to the FilterRedirector,
http://localhost:8880/delivery-cactus/test/filterRedirector.jsp.
for this case. (I'm not sure why it has jsp suffix).
For example, if your web.xml have a filter-mapping entry like
    <filter-mapping>
        <filter-name>theFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
and theFilter can fail for the request from Cactus-client,
Cactus-client cannot get test results.


Codes are appending for an example.
You should not add filter and filter-mapping entries for the SampleFilter
to your web.xml to run this example successfully.
If you add entries like follows to web.xml, the test will be failed
as you encountered:
    <filter>
        <filter-name>sampleFilter</filter-name>
        <filter-class>SampleFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>sampleFilter</filter-name>
        <url-pattern>/FilterRedirector</url-pattern>
    </filter-mapping>


I hope this helps you.
----
Kazuhito SUGURI
mailto:[EMAIL PROTECTED]
  

import java.io.IOException; import java.io.PrintWriter; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletResponse; public class SampleFilter implements Filter { public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { HttpServletResponse httpResponse = (HttpServletResponse)response; httpResponse.setStatus(HttpServletResponse.SC_FORBIDDEN); httpResponse.setContentType("text/html"); PrintWriter out = httpResponse.getWriter(); out.print("<html><body>Forbidden</body></html>\r\n"); out.flush(); out.close(); } public void init(FilterConfig config){} public void destroy(){} }

import org.apache.cactus.FilterTestCase; import org.apache.cactus.WebRequest; import org.apache.cactus.WebResponse; public class SampleFilterTest extends FilterTestCase { public SampleFilterTest(String name){ super(name); } public void testSample(){ SampleFilter target = new SampleFilter(); target.init(config); try{ target.doFilter(request, response, null); }catch(Exception e){ fail(e.getClass().getName() + ": " + e.getMessage()); } } public void endSample(WebResponse response){ assertEquals(403, response.getStatusCode()); assertEquals("<html><body>Forbidden</body></html>\r\n", response.getText()); } }

--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

--
[Sun Logo]
Frederic Jean
Member Technical Staff, Software
Customer Networked Systems -- Offering Engineering -- SWUP Delivery
Email: [EMAIL PROTECTED]
Phone: 303-223-6187 / x69565
SMS: [EMAIL PROTECTED]
Jabber ID: [EMAIL PROTECTED]

<<inline: logo_sun_sdn.gif>>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to