Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > IllegalAccessException using reflection on HttpSession

Reply
Thread Tools

IllegalAccessException using reflection on HttpSession

 
 
Ranger
Guest
Posts: n/a
 
      07-30-2003
I have a scenario where I need to invoke methods on the object
implementing HttpSession retrieved by getSession(). When I use
ServletExec and run my code, it works fine. When I deploy this same
code on WebLogic, I get an IllegalAccessException with no detailed
information (the message is null).

See the following code:

HttpSession session = request.getSession();
Method method = session.getClass().getMethod("getId", new Class[] {
});
String id = (String)method.invoke(session, new Object[] { });
out.println("Session id is: "+id);

The error when executing this on a WebLogic server:

java.lang.IllegalAccessException
at java.lang.reflect.Method.invoke(Native Method)
at TestServlet.doGet(TestServlet.java:41)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:853)
at weblogic.servlet.internal.ServletStubImpl.invokeSe rvlet(ServletStubImpl.java:265)
at weblogic.servlet.internal.ServletStubImpl.invokeSe rvlet(ServletStubImpl.java:200)
at weblogic.servlet.internal.WebAppServletContext.inv okeServlet(WebAppServletContext.java:2495)
at weblogic.servlet.internal.ServletRequestImpl.execu te(ServletRequestImpl.java:2204)
at weblogic.kernel.ExecuteThread.execute(ExecuteThrea d.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.ja va:120)
 
Reply With Quote
 
 
 
 
John C. Bollinger
Guest
Posts: n/a
 
      08-04-2003
Ranger wrote:
> I have a scenario where I need to invoke methods on the object
> implementing HttpSession retrieved by getSession(). When I use
> ServletExec and run my code, it works fine. When I deploy this same
> code on WebLogic, I get an IllegalAccessException with no detailed
> information (the message is null).
>
> See the following code:
>
> HttpSession session = request.getSession();
> Method method = session.getClass().getMethod("getId", new Class[] {
> });
> String id = (String)method.invoke(session, new Object[] { });
> out.println("Session id is: "+id);


Why in the world are you trying to do it that way? How about

out.println("Session id is: " + request.getSession().getId());

instead? (Or cache intermediate references as desired.) You do not
need to use reflection to invoke the methods defined by an interface
through a compatibly-typed reference. That would make interfaces pretty
useless.


John Bollinger
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Invoke method with HTTPSession or request as parametera using JSON RPC JAVA cool2005 Javascript 0 10-28-2006 06:11 AM
Webwork/ONGL IllegalAccessException Using Resin 2.1.12 Josh Java 0 02-21-2005 05:11 AM
Classloader IllegalAccessException Andreas Solsbach Java 0 10-07-2004 10:33 AM
IllegalAccessException on public method mike Java 2 07-10-2004 10:13 PM
IllegalAccessException on public method mike Java 4 06-24-2004 12:53 AM



Advertisments