cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

IllegalAccessError while accessing sessionContext object.

KanifG
1-Newbie

IllegalAccessError while accessing sessionContext object.

I am getting nested exception java.lang.IllegalAccessError: tried to access field wt.method.MethodContext.sessionContext. my code snippet looks like

try {

MethodContext methodcontext = MethodContext.getContext();

if (methodcontext != null && methodcontext.sessionContext != null

&& methodcontext.sessionContext.toString().contains("authenticationName")){

return SessionHelper.manager.getPrincipal().getName();

} else {

return EMPTY_STRING;

}

} catch (Exception e) {

return EMPTY_STRING;

}

methodcontext.sessionContextgetting an error so couldn't even catch it, it is terminating flow of execution, I check the Apache Conf settings and all looks good. The logged in user is in session just getting an error on sessionContext. Any help around it would be appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
jessh
5-Regular Member
(To:KanifG)

I'm betting you took old customization code that was

  1. Compiled in an older release,
  2. Not re-compiled with the latest release,
  3. Using an unsupported API (the sessionContext field is not supported), and
  4. Tried to run it in 10.2 M010

If so, then that explains everything there is no such publicly accessible field in 10.2 M010. There is, however, a getSessionContext() method -- though it also is not a supported API currently.

[Unsupported APIs are subject to change at any time without notice.]

View solution in original post

5 REPLIES 5
jessh
5-Regular Member
(To:KanifG)

I'm betting you took old customization code that was

  1. Compiled in an older release,
  2. Not re-compiled with the latest release,
  3. Using an unsupported API (the sessionContext field is not supported), and
  4. Tried to run it in 10.2 M010

If so, then that explains everything there is no such publicly accessible field in 10.2 M010. There is, however, a getSessionContext() method -- though it also is not a supported API currently.

[Unsupported APIs are subject to change at any time without notice.]

jessh
5-Regular Member
(To:jessh)

It looks like you could get nearly the same result with

MethodContext.getContext().mbean.getUserName()

though this returns null rather than EMPTY_STRING when the user is not known.

KanifG
1-Newbie
(To:jessh)

Yes Jess, You are absolutely right, this is specific to 10.2 M010 release only. I did explored some API around this and could the SessionContext.getContext() for 10.2 M010 API list, and same is not deprecated too. I used this and It did work as expected.

jessh
5-Regular Member
(To:KanifG)

If what you want is the user name associated with the current method context, then the code snippet I gave should work as well.

SessionContext.getContext() is supported, but do note what the Javadoc says:

"Get current session context. Session context is determined by authentication information in the current Method context. If none exists, an unauthenticated session context will be established."

If you don't want the italicized piece to occur, then I'd go with "MethodContext.getContext().mbean.getUserName()" instead. If the method context will have an associated user by this point, then either approach should work just fine.

KanifG
1-Newbie
(To:jessh)

Jess, my intention is to check if any valid user is present in session(sessionContext) before accessing Principal to avoid null pointers, PTC told us that the sessionContext field in MethodContext has been made private in 10.2 M010 version, but we can access same by using public getter method. so instead methodContext.sessionContext we have to access session by calling this methodContext.getSessionContext(). Thanks for your help!

Top Tags