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 <[EMAIL PROTECTED]>
Reply-To: "Cactus Users List" <[EMAIL PROTECTED]>
To: Cactus Users List <[EMAIL PROTECTED]>
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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]


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



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



Reply via email to