jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ajay Kumar" <ajaykumar1...@hotmail.com>
Subject Re: invoking a private method of a servlet
Date Tue, 18 Nov 2003 07:01:45 GMT

hi Tom,

Thanks for ur response.
I did call the security manager to set the accessibility of the reqd method 
to true. But the problem remains.

Regards,
Ajay.

>From: Thomas Hawtin <thawtin@tackline.demon.co.uk>
>Reply-To: "Cactus Users List" <cactus-user@jakarta.apache.org>
>To: Cactus Users List <cactus-user@jakarta.apache.org>
>Subject: Re: invoking a private method of a servlet
>Date: Tue, 18 Nov 2003 00:47:00 +0000
>
>Ajay Kumar wrote:
>>
>>I have a controller servlet with many private methods and want to write a 
>>testcase for these methods. I tried using reflection for invoking these 
>>methods, but got the following report:
>
>Using JUnit, I've always found it easier to refactor so that the Servlet, 
>in this case, delegates to a class with the bulk of the functionality. 
>JUnit uses exactly the same interface (in the general sense) as the Servlet 
>and everyone is happy. In any case it's probably not a bad idea to arrange 
>for classes that extend other groups' code to be as small and simple as 
>possible.
>
>><error message="null" 
>>type="org.apache.cactus.client.ServletExceptionWrapper">
>>java.lang.reflect.InvocationTargetException
>>[...]
>>Caused by: java.lang.NullPointerException
>>     at 
>>com.appnetix.mainprospecting.control.MainServlet.getEmailTemplates(MainServlet.java:226)
>
>That looks like your servlet throwing the NPE. Perhaps it's not 
>initialised? Method.invoke will itself throw an NPE if you try to call a 
>non-static method with a null target, althugh it doesn't look like the case 
>in this instance.
>
>w.r.t security/accessibility, for private methods you should usually call 
>setAccessible(true) which is defined in Method's superclass, otherwise an 
>IllegalAccessException will be thrown. As ever you will need suitably lax 
>security, but Cactus requires that to be wide open anyway.
>
>Tom Hawtin
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: cactus-user-help@jakarta.apache.org
>

_________________________________________________________________
Express your Digital Self. Win fabulous prizes. 
http://www.msn.co.in/DigitalSelf/ Enter this cool contest.


Mime
View raw message