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 "Peng, Haitao" <Ha...@commerceone.com> on 2002/08/06 21:17:18 UTC

LogConfigurationException

Hi, Vincent:

I am a beginner to use Cactus with JBuilder and Jrun.  I tried a simple
servlet and test class.

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

public class SampleServlet extends HttpServlet
{
    public void saveToSession(HttpServletRequest request)
    {
            String testparam = request.getParameter("testparam");
            request.getSession().setAttribute("testAttribute", testparam);
    }
}


import junit.framework.*;
import org.apache.cactus.*;
import SampleServlet;

public class SampleServletTest extends ServletTestCase
{
    public SampleServletTest(String theName)
    {
        super(theName);
    }

    public static void main (String[] args)
    {
        //junit.textui.TestRunner.run (TestSampleServlet.class);
        junit.swingui.TestRunner.run (SampleServletTest.class);
    }
    public static Test suite()
    {
        return new TestSuite(SampleServletTest.class);
    }

    public void beginSaveToSessionOK(WebRequest webRequest)
    {
        webRequest.addParameter("testparam", "it works!");
    }

    public void testSaveToSessionOK()
    {
        SampleServlet servlet = new SampleServlet();
        servlet.saveToSession(request);
        assertEquals("it works!", session.getAttribute("testAttribute"));
        System.out.print("Test Works!");
    }
}

The following are exceptions I got:

junit.framework.AssertionFailedError: Exception in constructor:
testSaveToSessionOK (org.apache.commons.logging.LogConfigurationException:
java.lang.ClassCastException: org.apache.commons.logging.impl.LogFactoryImpl
at org.apache.commons.logging.LogFactory.newFactory(LogFactory.java:506)
at org.apache.commons.logging.LogFactory.getFactory(LogFactory.java:350)

at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:381) 	
at
org.apache.cactus.util.JUnitVersionHelper.around146_getTestCaseName(LogAspec
t.java(1k):1170) 	
at
org.apache.cactus.util.JUnitVersionHelper.getTestCaseName(LogAspect.java(1k)
:103) 	
at org.apache.cactus.AbstractTestCase.<init>(AbstractTestCase.java:124)

at org.apache.cactus.AbstractWebTestCase.<init>(AbstractWebTestCase.java:86)
\
at org.apache.cactus.ServletTestCase.<init>(ServletTestCase.java:119) 	
at SampleServletTest.<init>(SampleServletTest.java:10) 	
at java.lang.reflect.Constructor.newInstance(Native Method) 	
at SampleServletTest.suite(SampleServletTest.java:20) 	
at junit.runner.BaseTestRunner.getTest(BaseTestRunner.java:53) 	at
SampleServletTest.main(SampleServletTest.java:16) ) 


I don't have any clue what is wrong?  Any pointers?

Thanks

Haitao Peng
Commerce One at Austin
(512) 597-6230


RE: LogConfigurationException

Posted by Vincent Massol <vm...@octo.com>.
Hi Haito,

You servlet and test case look very fine. As your subject says, it seems
to be a problem with internal Cactus logging (which uses
commons-logging). At first sight, it looks like you've tried to use a
special logging factory class that does not inherit from LogFactory ...

Have you tried to play with configuring commons-logging ? :-)

Apart from that, I am stuck at the moment ...

-Vincent
 
> -----Original Message-----
> From: Peng, Haitao [mailto:Haitao.Peng@commerceone.com]
> Sent: 06 August 2002 20:17
> To: 'cactus-user@jakarta.apache.org'
> Subject: LogConfigurationException
> 
> Hi, Vincent:
> 
> I am a beginner to use Cactus with JBuilder and Jrun.  I tried a
simple
> servlet and test class.
> 
> import javax.servlet.http.HttpServlet;
> import javax.servlet.http.HttpServletRequest;
> 
> public class SampleServlet extends HttpServlet
> {
>     public void saveToSession(HttpServletRequest request)
>     {
>             String testparam = request.getParameter("testparam");
>             request.getSession().setAttribute("testAttribute",
testparam);
>     }
> }
> 
> 
> import junit.framework.*;
> import org.apache.cactus.*;
> import SampleServlet;
> 
> public class SampleServletTest extends ServletTestCase
> {
>     public SampleServletTest(String theName)
>     {
>         super(theName);
>     }
> 
>     public static void main (String[] args)
>     {
>         //junit.textui.TestRunner.run (TestSampleServlet.class);
>         junit.swingui.TestRunner.run (SampleServletTest.class);
>     }
>     public static Test suite()
>     {
>         return new TestSuite(SampleServletTest.class);
>     }
> 
>     public void beginSaveToSessionOK(WebRequest webRequest)
>     {
>         webRequest.addParameter("testparam", "it works!");
>     }
> 
>     public void testSaveToSessionOK()
>     {
>         SampleServlet servlet = new SampleServlet();
>         servlet.saveToSession(request);
>         assertEquals("it works!",
session.getAttribute("testAttribute"));
>         System.out.print("Test Works!");
>     }
> }
> 
> The following are exceptions I got:
> 
> junit.framework.AssertionFailedError: Exception in constructor:
> testSaveToSessionOK
(org.apache.commons.logging.LogConfigurationException:
> java.lang.ClassCastException:
> org.apache.commons.logging.impl.LogFactoryImpl
> at
org.apache.commons.logging.LogFactory.newFactory(LogFactory.java:506)
> at
org.apache.commons.logging.LogFactory.getFactory(LogFactory.java:350)
> 
> at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:381)
> at
>
org.apache.cactus.util.JUnitVersionHelper.around146_getTestCaseName(LogA
sp
> ec
> t.java(1k):1170)
> at
>
org.apache.cactus.util.JUnitVersionHelper.getTestCaseName(LogAspect.java
(1
> k)
> :103)
> at
org.apache.cactus.AbstractTestCase.<init>(AbstractTestCase.java:124)
> 
> at
>
org.apache.cactus.AbstractWebTestCase.<init>(AbstractWebTestCase.java:86
)
> \
> at org.apache.cactus.ServletTestCase.<init>(ServletTestCase.java:119)
> at SampleServletTest.<init>(SampleServletTest.java:10)
> at java.lang.reflect.Constructor.newInstance(Native Method)
> at SampleServletTest.suite(SampleServletTest.java:20)
> at junit.runner.BaseTestRunner.getTest(BaseTestRunner.java:53)
at
> SampleServletTest.main(SampleServletTest.java:16) )
> 
> 
> I don't have any clue what is wrong?  Any pointers?
> 
> Thanks
> 
> Haitao Peng
> Commerce One at Austin
> (512) 597-6230



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