You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jonathan Yom-Tov <jo...@sysaid.com> on 2020/05/07 20:36:07 UTC

how do I switch class loaders

My application uses Redisson (a client which persists the session to
Redis). There are two Redisson jar files located in $CATALINA_HOME/lib, so
if I understand the docs correctly they're loaded by the common class
loader.

I want to access the RedissonSessionManager class during a request. The
problem is that if I do something like RedissonSessionManager manager =
(RedissonSessionManager) session.getManager() I get a ClassCastException,
presumably because they were loaded by different class loaders.

Will it help if I somehow access the common class loader for this? If so
how can I do that? If not is there some other way I can achieve this?

Jon.

Re: how do I switch class loaders

Posted by Jonathan Yom-Tov <jo...@sysaid.com>.
It was actually one of mine. I put a jar file under lib/ that I forgot had
the offending class packaged into it.



On Tue, May 12, 2020 at 5:13 PM Christopher Schultz <
chris@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> Jonathan,
>
> On 5/8/20 15:03, Jonathan Yom-Tov wrote:
> > Got it! Using http://jhades.github.io/ it was quick and easy to
> > find out that the offending class was indeed loaded from two
> > different jar files. After I removed one of them casting worked
> > with no issues. I didn't know jar hell could result in
> > ClassCastException, but you learn something new every day.
>
> So what were the two libraries that were conflicting? Logging
> libraries should be REALLY obvious since they have a very good chance
> of colliding. Did some other library "helpfully" package log4j inside
> its own JAR file?
>
> - -chris
>
> > On Fri, May 8, 2020 at 9:29 PM Olaf Kock <to...@olafkock.de>
> > wrote:
> >
> >>
> >> On 08.05.20 19:50, Christopher Schultz wrote:
> >>> Olaf,
> >>>
> >>> On 5/8/20 13:19, Olaf Kock wrote:
> >>>
> >>>> You might want to hunt down duplicate classes in the JAR
> >>>> files on your classpath. Worst case: unpack them all in
> >>>> temporary directories and check for occurrences of the
> >>>> filename. Make sure that one doesn't overwrite the other when
> >>>> unzipping.
> >>>
> >>> Or unpack them all and let the unzipper tell you if there are
> >>> any filename collisions.
> >>>
> >>> Someone has probably written a "classpath scanner" that will
> >>> just unzip everything and look for conflicts.
> >>
> >>
> >> I've gotten follow up questions on how to use those tools in the
> >> past. Key is to identify all the jars, less the options of the
> >> tool, but since then I've just reverted to mention the low-tech
> >> version, and am not even ashamed ;)
> >>
> >> That's not to say that I don't trust Jonathan to use a classpath
> >> scanner - it's just a low-tech-preference out of habit.
> >>
> >> Plus, due to this habit, I currently can't come up with a tool's
> >> name to look for :D
> >>
> >> Olaf
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >>
> >>
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >>
> >>
> >
> -----BEGIN PGP SIGNATURE-----
> Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/
>
> iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl66rREACgkQHPApP6U8
> pFhqOBAApsaappSGDrveTxgVU4X2x0VKtZxCzMX8yZ4rSPaFvRi0rMp1bLlaV/sw
> ZaRAQLZbAF5dBgahU4AqKmEkPNw2SlncuykX1JZs//lCDqzaFrJ4Dbsw4YJ7cq+3
> 3jwV6LTS7XzFXOoCHShvvbbwsK2qTWE870TQwOSN+yCN0mTbZz3ah2qnKXoLWZvn
> qUOfYmtTRJTN8vBsR0BpRq2QXZ+uL565A4WLeX9j5jTWiZ5zDNsjN4h9/GHcKChM
> lKIwR8VVfGI+le4JHiW9kz0gukbe/gcvFNPnf5UpvpVZf4VYOQyuTV0gNYAO1QZ8
> CoZ9qNuAjO6aE4BW6PGeFCnDZ55/i6lVe8ZM69Z6WFum8jYOCi2wbuPyUmZqzTbX
> aXAe7OWHXrDgdGUIUFaOvvpMjbEbG/6TBH+VMAbLN3i4uFEQwmjP+9JFn3PSeyok
> ca/5ev99ExfqEOqpQgRddxjo8TBczZdchsUazvR0pcoEWzbQUPvZKN/lRnaCTkxn
> Gvx7co1mw9sGVHkYhktJNLvZE6KP48xaRZISWhCVsVX0LgpUwOyD37N1+wUYgqJT
> Zao62Za5GVVZrbD6+9HYBD3WhKwJwxvxICQ42diEitSxgdvRSTbuUbrREVfkiYgu
> 7OmlWx6y7aXEDgDS7DSBOiMW3/N93uGzOPL0gECQnBmKHLDKfU4=
> =ANY3
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: how do I switch class loaders

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Jonathan,

On 5/8/20 15:03, Jonathan Yom-Tov wrote:
> Got it! Using http://jhades.github.io/ it was quick and easy to
> find out that the offending class was indeed loaded from two
> different jar files. After I removed one of them casting worked
> with no issues. I didn't know jar hell could result in
> ClassCastException, but you learn something new every day.

So what were the two libraries that were conflicting? Logging
libraries should be REALLY obvious since they have a very good chance
of colliding. Did some other library "helpfully" package log4j inside
its own JAR file?

- -chris

> On Fri, May 8, 2020 at 9:29 PM Olaf Kock <to...@olafkock.de>
> wrote:
>
>>
>> On 08.05.20 19:50, Christopher Schultz wrote:
>>> Olaf,
>>>
>>> On 5/8/20 13:19, Olaf Kock wrote:
>>>
>>>> You might want to hunt down duplicate classes in the JAR
>>>> files on your classpath. Worst case: unpack them all in
>>>> temporary directories and check for occurrences of the
>>>> filename. Make sure that one doesn't overwrite the other when
>>>> unzipping.
>>>
>>> Or unpack them all and let the unzipper tell you if there are
>>> any filename collisions.
>>>
>>> Someone has probably written a "classpath scanner" that will
>>> just unzip everything and look for conflicts.
>>
>>
>> I've gotten follow up questions on how to use those tools in the
>> past. Key is to identify all the jars, less the options of the
>> tool, but since then I've just reverted to mention the low-tech
>> version, and am not even ashamed ;)
>>
>> That's not to say that I don't trust Jonathan to use a classpath
>> scanner - it's just a low-tech-preference out of habit.
>>
>> Plus, due to this habit, I currently can't come up with a tool's
>> name to look for :D
>>
>> Olaf
>>
>>
>>
>> ---------------------------------------------------------------------
>>
>>
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl66rREACgkQHPApP6U8
pFhqOBAApsaappSGDrveTxgVU4X2x0VKtZxCzMX8yZ4rSPaFvRi0rMp1bLlaV/sw
ZaRAQLZbAF5dBgahU4AqKmEkPNw2SlncuykX1JZs//lCDqzaFrJ4Dbsw4YJ7cq+3
3jwV6LTS7XzFXOoCHShvvbbwsK2qTWE870TQwOSN+yCN0mTbZz3ah2qnKXoLWZvn
qUOfYmtTRJTN8vBsR0BpRq2QXZ+uL565A4WLeX9j5jTWiZ5zDNsjN4h9/GHcKChM
lKIwR8VVfGI+le4JHiW9kz0gukbe/gcvFNPnf5UpvpVZf4VYOQyuTV0gNYAO1QZ8
CoZ9qNuAjO6aE4BW6PGeFCnDZ55/i6lVe8ZM69Z6WFum8jYOCi2wbuPyUmZqzTbX
aXAe7OWHXrDgdGUIUFaOvvpMjbEbG/6TBH+VMAbLN3i4uFEQwmjP+9JFn3PSeyok
ca/5ev99ExfqEOqpQgRddxjo8TBczZdchsUazvR0pcoEWzbQUPvZKN/lRnaCTkxn
Gvx7co1mw9sGVHkYhktJNLvZE6KP48xaRZISWhCVsVX0LgpUwOyD37N1+wUYgqJT
Zao62Za5GVVZrbD6+9HYBD3WhKwJwxvxICQ42diEitSxgdvRSTbuUbrREVfkiYgu
7OmlWx6y7aXEDgDS7DSBOiMW3/N93uGzOPL0gECQnBmKHLDKfU4=
=ANY3
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: how do I switch class loaders

Posted by Jonathan Yom-Tov <jo...@sysaid.com>.
Got it! Using http://jhades.github.io/ it was quick and easy to find out
that the offending class was indeed loaded from two different jar files.
After I removed one of them casting worked with no issues. I didn't know
jar hell could result in ClassCastException, but you learn something new
every day.

Thanks everyone for your help. Olaf I found your suggestion especially
helpful. Have a good weekend :-)



On Fri, May 8, 2020 at 9:29 PM Olaf Kock <to...@olafkock.de> wrote:

>
> On 08.05.20 19:50, Christopher Schultz wrote:
> > Olaf,
> >
> > On 5/8/20 13:19, Olaf Kock wrote:
> >
> > > You might want to hunt down duplicate classes in the JAR files on
> > > your classpath. Worst case: unpack them all in temporary
> > > directories and check for occurrences of the filename. Make sure
> > > that one doesn't overwrite the other when unzipping.
> >
> > Or unpack them all and let the unzipper tell you if there are any
> > filename collisions.
> >
> > Someone has probably written a "classpath scanner" that will just
> > unzip everything and look for conflicts.
>
>
> I've gotten follow up questions on how to use those tools in the past.
> Key is to identify all the jars, less the options of the tool, but since
> then I've just reverted to mention the low-tech version, and am not even
> ashamed ;)
>
> That's not to say that I don't trust Jonathan to use a classpath scanner
> - it's just a low-tech-preference out of habit.
>
> Plus, due to this habit, I currently can't come up with a tool's name to
> look for :D
>
> Olaf
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

-- 
[image: SysAid Technologies]
<http://www.sysaid.com/?utm_source=signature&utm_medium=email&utm_campaign=sysaid-logo>
Jonathan Yom-Tov
Senior Architect
jonathan.yomtov@sysaid.com
Phone (IL): +972 (3) 533-3675 Ext. 932
[image: SysAid Technologies]
<https://www.sysaid.com/?utm_source=signature&utm_medium=email&utm_campaign=sysaid-logo-icon>
  [image: SysAid on Facebook] <https://www.facebook.com/SysAidIT>   [image:
SysAid on Twitter] <https://twitter.com/sysaid>   [image: SysAid on
Linked-in] <https://www.linkedin.com/company/sysaid-technologies-ltd>   [image:
SysAid on YouTube] <https://www.youtube.com/user/SysAidIT>   [image: SysAid
on Instagram] <https://www.instagram.com/sysaid_technologies/>
[image: Banner] <https://www.sysaid.com/sig-link>

Re: how do I switch class loaders

Posted by Olaf Kock <to...@olafkock.de>.
On 08.05.20 19:50, Christopher Schultz wrote:
> Olaf,
>
> On 5/8/20 13:19, Olaf Kock wrote:
>
> > You might want to hunt down duplicate classes in the JAR files on
> > your classpath. Worst case: unpack them all in temporary
> > directories and check for occurrences of the filename. Make sure
> > that one doesn't overwrite the other when unzipping.
>
> Or unpack them all and let the unzipper tell you if there are any
> filename collisions.
>
> Someone has probably written a "classpath scanner" that will just
> unzip everything and look for conflicts.


I've gotten follow up questions on how to use those tools in the past.
Key is to identify all the jars, less the options of the tool, but since
then I've just reverted to mention the low-tech version, and am not even
ashamed ;)

That's not to say that I don't trust Jonathan to use a classpath scanner
- it's just a low-tech-preference out of habit.

Plus, due to this habit, I currently can't come up with a tool's name to
look for :D

Olaf



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: how do I switch class loaders

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Olaf,

On 5/8/20 13:19, Olaf Kock wrote:
>
> On 08.05.20 18:23, Jonathan Yom-Tov wrote:
>> Oops, my bad 😁 But that still leaves my original issue: why do I
>> get a ClassCastException casting RedissonSessionManager to
>> RedissonSessionManager?
>
> The *only* reason that I've ever seen this happens (e.g. a class
> can't be typecast to a legitimate superclass or interface): When
> the superclass or interface is available through two different
> classloaders.
>
> The error message omits the classloader, and instead of
>
> A cannot be cast to B
>
> /should/ read
>
> A (from classloader X) cannot be cast to B (from classloader Y)
>
> You might want to hunt down duplicate classes in the JAR files on
> your classpath. Worst case: unpack them all in temporary
> directories and check for occurrences of the filename. Make sure
> that one doesn't overwrite the other when unzipping.

Or unpack them all and let the unzipper tell you if there are any
filename collisions.

Someone has probably written a "classpath scanner" that will just
unzip everything and look for conflicts.

- -chris

>> On Fri, 8 May 2020, 16:56 Luis Rodríguez Fernández,
>> <uo...@gmail.com> wrote:
>>
>>> Hello Jonathan,
>>>
>>> It is not exactly the same :), look at the "$2" appended at the
>>> end.This is an "anonymous inner class" [1]
>>>
>>> Cheers,
>>>
>>> Luis
>>>
>>> [1]
>>>
>>> https://stackoverflow.com/questions/11388840/java-compiled-classes-c
ontain-dollar-signs
>>>
>>>
>>>
>>>
El vie., 8 may. 2020 a las 11:52, Jonathan Yom-Tov (<
>>> jonathan.yomtov@sysaid.com>) escribió:
>>>
>>>> This is very odd. I ran Tomcat with -verbose:class (see
>>>> relevant output below). The class is being loaded twice from
>>>> the same location, I'm guessing by two different class
>>>> loaders. How can that be?
>>>>
>>>> [Loaded org.redisson.tomcat.RedissonSessionManager from
>>>> file:/C:/dev/tomcat.9.0.19/lib/redisson-tomcat-9-3.12.2.jar]
>>>> [Loaded org.redisson.tomcat.RedissonSessionManager$2 from
>>>> file:/C:/dev/tomcat.9.0.19/lib/redisson-tomcat-9-3.12.2.jar]
>>>>
>>>> On Fri, May 8, 2020 at 11:04 AM Olaf Kock
>>>> <to...@olafkock.de> wrote:
>>>>
>>>>> On 08.05.20 09:37, Jonathan Yom-Tov wrote:
>>>>>> Thanks Mark. Just tried that. I put the redisson-tomcat
>>>>>> jar outside
>>> of
>>>>>> WEB-INF/lib and added it with scope provided. I get the
>>>>>> exact same
>>>> issue.
>>>>>> What am I doing wrong?
>>>>> Make sure, it's actually gone from your webapp. Depending
>>>>> on the deployment technique I've seen removed files to
>>>>> persist from previous deployments.
>>>>>
>>>>> You might need to fully undeploy, then deploy the new
>>>>> version without the jar in question. But inspect the
>>>>> runtime environment to make sure you only have a single
>>>>> library accessible. Having the same class available two
>>>>> different ways is a recipe for disaster, don't fix it my
>>>>> messing with the classloader: Fix it by eliminating one of
>>>>> them.
>>>>>
>>>>> You might also check if you're not accessing any wrapped
>>>>> object, e.g.
>>> by
>>>>> inspecting getManager(session).getClass().getName().
>>>>>
>>>>> Olaf
>>>>>
>>>>>
>>>>>
>>>>>> Here's my code:
>>>>>>
>>>>>> HttpSession session =
>>>>>> httpServletRequest.getSession(false); try {
>>>>>> RedissonSessionManager rsm = (RedissonSessionManager)
>>>>> getManager(session);
>>>>>> } catch (Exception e) { e.printStackTrace(); }
>>>>>>
>>>>>> private Manager getManager(HttpSession session) throws
>>>>>> Exception {
>>>>>>
>>>>>> Field facadeSessionField =
>>>>>> StandardSessionFacade.class.getDeclaredField("session");
>>>>>> facadeSessionField.setAccessible(true); StandardSession
>>>>>> stdSession = (StandardSession)
>>>>>> facadeSessionField.get(session);
>>>>>>
>>>>>> return stdSession.getManager(); }
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Thu, May 7, 2020 at 11:52 PM Mark Thomas
>>>>>> <ma...@apache.org>
>>> wrote:
>>>>>>> On 07/05/2020 21:36, Jonathan Yom-Tov wrote:
>>>>>>>> My application uses Redisson (a client which persists
>>>>>>>> the session
>>> to
>>>>>>>> Redis). There are two Redisson jar files located in
>>>> $CATALINA_HOME/lib,
>>>>>>> so
>>>>>>>> if I understand the docs correctly they're loaded by
>>>>>>>> the common
>>> class
>>>>>>>> loader.
>>>>>>>>
>>>>>>>> I want to access the RedissonSessionManager class
>>>>>>>> during a request.
>>>> The
>>>>>>>> problem is that if I do something like
>>>>>>>> RedissonSessionManager
>>>> manager =
>>>>>>>> (RedissonSessionManager) session.getManager() I get
>>>>>>>> a
>>>>> ClassCastException,
>>>>>>>> presumably because they were loaded by different
>>>>>>>> class loaders.
>>>>>>>>
>>>>>>>> Will it help if I somehow access the common class
>>>>>>>> loader for this?
>>> If
>>>>> so
>>>>>>>> how can I do that? If not is there some other way I
>>>>>>>> can achieve
>>> this?
>>>>>>> Make sure you don't have those JARs in your
>>>>>>> application's
>>> WEB-INF/lib
>>>> as
>>>>>>> well as $CATALINA_BASE/lib.
>>>>>>>
>>>>>>> In any recent version of Tomcat any JAR in
>>>>>>> $CATALINA_BASE/lib will
>>> be
>>>>>>> visible to your application.
>>>>>>>
>>>>>>> Mark
>>>>>>>
>>>>>>>
>>> --------------------------------------------------------------------
- -
>>>>>>>
>>>
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>>>>> For additional commands, e-mail:
>>>>>>> users-help@tomcat.apache.org
>>>>>>>
>>>>>>>
>>>>> ------------------------------------------------------------------
- ---
>>>>>
>>>>>
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>>> For additional commands, e-mail:
>>>>> users-help@tomcat.apache.org
>>>>>
>>>>>
>>>> -- [image: SysAid Technologies] <
>>>>
>>> http://www.sysaid.com/?utm_source=signature&utm_medium=email&utm_cam
paign=sysaid-logo
>>>>
>>>
Jonathan Yom-Tov
>>>> Senior Architect jonathan.yomtov@sysaid.com Phone (IL): +972
>>>> (3) 533-3675 Ext. 932 [image: SysAid Technologies] <
>>>>
>>> https://www.sysaid.com/?utm_source=signature&utm_medium=email&utm_ca
mpaign=sysaid-logo-icon
>>>>
>>>
[image: SysAid on Facebook] <https://www.facebook.com/SysAidIT>
>>>> [image: SysAid on Twitter] <https://twitter.com/sysaid>
>>>> [image: SysAid on Linked-in]
>>>> <https://www.linkedin.com/company/sysaid-technologies-ltd>
>>>> [image: SysAid on YouTube]
>>>> <https://www.youtube.com/user/SysAidIT>   [image: SysAid on
>>>> Instagram] <https://www.instagram.com/sysaid_technologies/>
>>>> [image: Banner] <https://www.sysaid.com/sig-link>
>>>>
>>>
>>> --
>>>
>>> "Ever tried. Ever failed. No matter. Try Again. Fail again.
>>> Fail better."
>>>
>>> - Samuel Beckett
>>>
>
> ---------------------------------------------------------------------
>
>
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl61m+MACgkQHPApP6U8
pFhjxA/+IOLPex2KWzimlFRYCfkrd9bT45Ksrrb0SyKEeUsh4+/SDeZ8e0on9/K2
oCA13GZJj4t6R8gb6OH5/4jCNb15iMSS/N+mz3HR8e8u83IM5tCLzpmCw0wtEEyJ
w+lbcyfdiecnBIV3nWvFvS9bgMnBsaHLad2lkojhrdoCl/QdQiJw72vWsuuLsJcm
nZr3wYArxbrFFR515KQGaMvhe2LEUw5cti333u2FGi1VTl7f2YXRZ92ZY08QwvAv
auToZY56MQ4aVkgf3ck+ju7IlDtnsgHPJ46KgqD8VA7FMq5HuTuwWiaf3NQt75ra
7HK/qFYOwv5Uqo7abxMeQ1WIlD0fzqaJkdzUyuO3ZPnoXshBj3mTRvNd3zH+EWE3
0IFSQ2MOkzDaKd3DqQKdbRGOSroXhHuhJVnlxCUczCsLLGzCr0qzjMnOU9IYj0QR
GQUOqLZazn/XlDjWtAPBgXf4CcToG0Pd/IWLyrIh06YeCjOuBurmFPg2a258IdAQ
NMjXekn72AWdbBtMdnLMNIIker4aivYPPI36dCz6422cSJI6ct/spqfaTm/jrVS5
DsFNRg7qgcMLavsTl281l+Ano7lgRqpWqywvGvWYzQTJi776+4UYE0lUkcsA6Frm
MMknIe9+01aYf2XpDHvEOsM/Wzf+ZcHtnBmhyVaX6uz9mf8uKvU=
=2Jus
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: how do I switch class loaders

Posted by Olaf Kock <to...@olafkock.de>.
On 08.05.20 18:23, Jonathan Yom-Tov wrote:
> Oops, my bad 😁 But that still leaves my original issue: why do I get a
> ClassCastException casting RedissonSessionManager to
> RedissonSessionManager?

The *only* reason that I've ever seen this happens (e.g. a class can't
be typecast to a legitimate superclass or interface): When the
superclass or interface is available through two different classloaders.

The error message omits the classloader, and instead of

  A cannot be cast to B

/should/ read

   A (from classloader X) cannot be cast to B (from classloader Y)

You might want to hunt down duplicate classes in the JAR files on your
classpath. Worst case: unpack them all in temporary directories and
check for occurrences of the filename. Make sure that one doesn't
overwrite the other when unzipping.

Olaf



> On Fri, 8 May 2020, 16:56 Luis Rodríguez Fernández, <uo...@gmail.com>
> wrote:
>
>> Hello Jonathan,
>>
>> It is not exactly the same :), look at the "$2" appended at the end.This is
>> an "anonymous inner class" [1]
>>
>> Cheers,
>>
>> Luis
>>
>> [1]
>>
>> https://stackoverflow.com/questions/11388840/java-compiled-classes-contain-dollar-signs
>>
>>
>> El vie., 8 may. 2020 a las 11:52, Jonathan Yom-Tov (<
>> jonathan.yomtov@sysaid.com>) escribió:
>>
>>> This is very odd. I ran Tomcat with -verbose:class (see relevant output
>>> below). The class is being loaded twice from the same location, I'm
>>> guessing by two different class loaders. How can that be?
>>>
>>> [Loaded org.redisson.tomcat.RedissonSessionManager from
>>> file:/C:/dev/tomcat.9.0.19/lib/redisson-tomcat-9-3.12.2.jar]
>>> [Loaded org.redisson.tomcat.RedissonSessionManager$2 from
>>> file:/C:/dev/tomcat.9.0.19/lib/redisson-tomcat-9-3.12.2.jar]
>>>
>>> On Fri, May 8, 2020 at 11:04 AM Olaf Kock <to...@olafkock.de> wrote:
>>>
>>>> On 08.05.20 09:37, Jonathan Yom-Tov wrote:
>>>>> Thanks Mark. Just tried that. I put the redisson-tomcat jar outside
>> of
>>>>> WEB-INF/lib and added it with scope provided. I get the exact same
>>> issue.
>>>>> What am I doing wrong?
>>>> Make sure, it's actually gone from your webapp. Depending on the
>>>> deployment technique I've seen removed files to persist from previous
>>>> deployments.
>>>>
>>>> You might need to fully undeploy, then deploy the new version without
>>>> the jar in question. But inspect the runtime environment to make sure
>>>> you only have a single library accessible. Having the same class
>>>> available two different ways is a recipe for disaster, don't fix it my
>>>> messing with the classloader: Fix it by eliminating one of them.
>>>>
>>>> You might also check if you're not accessing any wrapped object, e.g.
>> by
>>>> inspecting getManager(session).getClass().getName().
>>>>
>>>> Olaf
>>>>
>>>>
>>>>
>>>>> Here's my code:
>>>>>
>>>>> HttpSession session = httpServletRequest.getSession(false);
>>>>> try {
>>>>>     RedissonSessionManager rsm = (RedissonSessionManager)
>>>> getManager(session);
>>>>> } catch (Exception e) {
>>>>>     e.printStackTrace();
>>>>> }
>>>>>
>>>>> private Manager getManager(HttpSession session) throws Exception {
>>>>>
>>>>>     Field facadeSessionField =
>>>>> StandardSessionFacade.class.getDeclaredField("session");
>>>>>     facadeSessionField.setAccessible(true);
>>>>>     StandardSession stdSession = (StandardSession)
>>>>> facadeSessionField.get(session);
>>>>>
>>>>>     return stdSession.getManager();
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> On Thu, May 7, 2020 at 11:52 PM Mark Thomas <ma...@apache.org>
>> wrote:
>>>>>> On 07/05/2020 21:36, Jonathan Yom-Tov wrote:
>>>>>>> My application uses Redisson (a client which persists the session
>> to
>>>>>>> Redis). There are two Redisson jar files located in
>>> $CATALINA_HOME/lib,
>>>>>> so
>>>>>>> if I understand the docs correctly they're loaded by the common
>> class
>>>>>>> loader.
>>>>>>>
>>>>>>> I want to access the RedissonSessionManager class during a request.
>>> The
>>>>>>> problem is that if I do something like RedissonSessionManager
>>> manager =
>>>>>>> (RedissonSessionManager) session.getManager() I get a
>>>> ClassCastException,
>>>>>>> presumably because they were loaded by different class loaders.
>>>>>>>
>>>>>>> Will it help if I somehow access the common class loader for this?
>> If
>>>> so
>>>>>>> how can I do that? If not is there some other way I can achieve
>> this?
>>>>>> Make sure you don't have those JARs in your application's
>> WEB-INF/lib
>>> as
>>>>>> well as $CATALINA_BASE/lib.
>>>>>>
>>>>>> In any recent version of Tomcat any JAR in $CATALINA_BASE/lib will
>> be
>>>>>> visible to your application.
>>>>>>
>>>>>> Mark
>>>>>>
>>>>>>
>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>>>>
>>>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>>
>>>>
>>> --
>>> [image: SysAid Technologies]
>>> <
>>>
>> http://www.sysaid.com/?utm_source=signature&utm_medium=email&utm_campaign=sysaid-logo
>>> Jonathan Yom-Tov
>>> Senior Architect
>>> jonathan.yomtov@sysaid.com
>>> Phone (IL): +972 (3) 533-3675 Ext. 932
>>> [image: SysAid Technologies]
>>> <
>>>
>> https://www.sysaid.com/?utm_source=signature&utm_medium=email&utm_campaign=sysaid-logo-icon
>>>   [image: SysAid on Facebook] <https://www.facebook.com/SysAidIT>
>>>  [image:
>>> SysAid on Twitter] <https://twitter.com/sysaid>   [image: SysAid on
>>> Linked-in] <https://www.linkedin.com/company/sysaid-technologies-ltd>
>>>  [image:
>>> SysAid on YouTube] <https://www.youtube.com/user/SysAidIT>   [image:
>>> SysAid
>>> on Instagram] <https://www.instagram.com/sysaid_technologies/>
>>> [image: Banner] <https://www.sysaid.com/sig-link>
>>>
>>
>> --
>>
>> "Ever tried. Ever failed. No matter. Try Again. Fail again. Fail better."
>>
>> - Samuel Beckett
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: how do I switch class loaders

Posted by Jonathan Yom-Tov <jo...@sysaid.com>.
Oops, my bad 😁 But that still leaves my original issue: why do I get a
ClassCastException casting RedissonSessionManager to
RedissonSessionManager?

On Fri, 8 May 2020, 16:56 Luis Rodríguez Fernández, <uo...@gmail.com>
wrote:

> Hello Jonathan,
>
> It is not exactly the same :), look at the "$2" appended at the end.This is
> an "anonymous inner class" [1]
>
> Cheers,
>
> Luis
>
> [1]
>
> https://stackoverflow.com/questions/11388840/java-compiled-classes-contain-dollar-signs
>
>
> El vie., 8 may. 2020 a las 11:52, Jonathan Yom-Tov (<
> jonathan.yomtov@sysaid.com>) escribió:
>
> > This is very odd. I ran Tomcat with -verbose:class (see relevant output
> > below). The class is being loaded twice from the same location, I'm
> > guessing by two different class loaders. How can that be?
> >
> > [Loaded org.redisson.tomcat.RedissonSessionManager from
> > file:/C:/dev/tomcat.9.0.19/lib/redisson-tomcat-9-3.12.2.jar]
> > [Loaded org.redisson.tomcat.RedissonSessionManager$2 from
> > file:/C:/dev/tomcat.9.0.19/lib/redisson-tomcat-9-3.12.2.jar]
> >
> > On Fri, May 8, 2020 at 11:04 AM Olaf Kock <to...@olafkock.de> wrote:
> >
> > >
> > > On 08.05.20 09:37, Jonathan Yom-Tov wrote:
> > > > Thanks Mark. Just tried that. I put the redisson-tomcat jar outside
> of
> > > > WEB-INF/lib and added it with scope provided. I get the exact same
> > issue.
> > > > What am I doing wrong?
> > >
> > > Make sure, it's actually gone from your webapp. Depending on the
> > > deployment technique I've seen removed files to persist from previous
> > > deployments.
> > >
> > > You might need to fully undeploy, then deploy the new version without
> > > the jar in question. But inspect the runtime environment to make sure
> > > you only have a single library accessible. Having the same class
> > > available two different ways is a recipe for disaster, don't fix it my
> > > messing with the classloader: Fix it by eliminating one of them.
> > >
> > > You might also check if you're not accessing any wrapped object, e.g.
> by
> > > inspecting getManager(session).getClass().getName().
> > >
> > > Olaf
> > >
> > >
> > >
> > > > Here's my code:
> > > >
> > > > HttpSession session = httpServletRequest.getSession(false);
> > > > try {
> > > >     RedissonSessionManager rsm = (RedissonSessionManager)
> > > getManager(session);
> > > > } catch (Exception e) {
> > > >     e.printStackTrace();
> > > > }
> > > >
> > > > private Manager getManager(HttpSession session) throws Exception {
> > > >
> > > >     Field facadeSessionField =
> > > > StandardSessionFacade.class.getDeclaredField("session");
> > > >     facadeSessionField.setAccessible(true);
> > > >     StandardSession stdSession = (StandardSession)
> > > > facadeSessionField.get(session);
> > > >
> > > >     return stdSession.getManager();
> > > > }
> > > >
> > > >
> > > >
> > > > On Thu, May 7, 2020 at 11:52 PM Mark Thomas <ma...@apache.org>
> wrote:
> > > >
> > > >> On 07/05/2020 21:36, Jonathan Yom-Tov wrote:
> > > >>> My application uses Redisson (a client which persists the session
> to
> > > >>> Redis). There are two Redisson jar files located in
> > $CATALINA_HOME/lib,
> > > >> so
> > > >>> if I understand the docs correctly they're loaded by the common
> class
> > > >>> loader.
> > > >>>
> > > >>> I want to access the RedissonSessionManager class during a request.
> > The
> > > >>> problem is that if I do something like RedissonSessionManager
> > manager =
> > > >>> (RedissonSessionManager) session.getManager() I get a
> > > ClassCastException,
> > > >>> presumably because they were loaded by different class loaders.
> > > >>>
> > > >>> Will it help if I somehow access the common class loader for this?
> If
> > > so
> > > >>> how can I do that? If not is there some other way I can achieve
> this?
> > > >> Make sure you don't have those JARs in your application's
> WEB-INF/lib
> > as
> > > >> well as $CATALINA_BASE/lib.
> > > >>
> > > >> In any recent version of Tomcat any JAR in $CATALINA_BASE/lib will
> be
> > > >> visible to your application.
> > > >>
> > > >> Mark
> > > >>
> > > >>
> ---------------------------------------------------------------------
> > > >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > > >> For additional commands, e-mail: users-help@tomcat.apache.org
> > > >>
> > > >>
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > > For additional commands, e-mail: users-help@tomcat.apache.org
> > >
> > >
> >
> > --
> > [image: SysAid Technologies]
> > <
> >
> http://www.sysaid.com/?utm_source=signature&utm_medium=email&utm_campaign=sysaid-logo
> > >
> > Jonathan Yom-Tov
> > Senior Architect
> > jonathan.yomtov@sysaid.com
> > Phone (IL): +972 (3) 533-3675 Ext. 932
> > [image: SysAid Technologies]
> > <
> >
> https://www.sysaid.com/?utm_source=signature&utm_medium=email&utm_campaign=sysaid-logo-icon
> > >
> >   [image: SysAid on Facebook] <https://www.facebook.com/SysAidIT>
> >  [image:
> > SysAid on Twitter] <https://twitter.com/sysaid>   [image: SysAid on
> > Linked-in] <https://www.linkedin.com/company/sysaid-technologies-ltd>
> >  [image:
> > SysAid on YouTube] <https://www.youtube.com/user/SysAidIT>   [image:
> > SysAid
> > on Instagram] <https://www.instagram.com/sysaid_technologies/>
> > [image: Banner] <https://www.sysaid.com/sig-link>
> >
>
>
> --
>
> "Ever tried. Ever failed. No matter. Try Again. Fail again. Fail better."
>
> - Samuel Beckett
>

Re: how do I switch class loaders

Posted by Luis Rodríguez Fernández <uo...@gmail.com>.
Hello Jonathan,

It is not exactly the same :), look at the "$2" appended at the end.This is
an "anonymous inner class" [1]

Cheers,

Luis

[1]
https://stackoverflow.com/questions/11388840/java-compiled-classes-contain-dollar-signs


El vie., 8 may. 2020 a las 11:52, Jonathan Yom-Tov (<
jonathan.yomtov@sysaid.com>) escribió:

> This is very odd. I ran Tomcat with -verbose:class (see relevant output
> below). The class is being loaded twice from the same location, I'm
> guessing by two different class loaders. How can that be?
>
> [Loaded org.redisson.tomcat.RedissonSessionManager from
> file:/C:/dev/tomcat.9.0.19/lib/redisson-tomcat-9-3.12.2.jar]
> [Loaded org.redisson.tomcat.RedissonSessionManager$2 from
> file:/C:/dev/tomcat.9.0.19/lib/redisson-tomcat-9-3.12.2.jar]
>
> On Fri, May 8, 2020 at 11:04 AM Olaf Kock <to...@olafkock.de> wrote:
>
> >
> > On 08.05.20 09:37, Jonathan Yom-Tov wrote:
> > > Thanks Mark. Just tried that. I put the redisson-tomcat jar outside of
> > > WEB-INF/lib and added it with scope provided. I get the exact same
> issue.
> > > What am I doing wrong?
> >
> > Make sure, it's actually gone from your webapp. Depending on the
> > deployment technique I've seen removed files to persist from previous
> > deployments.
> >
> > You might need to fully undeploy, then deploy the new version without
> > the jar in question. But inspect the runtime environment to make sure
> > you only have a single library accessible. Having the same class
> > available two different ways is a recipe for disaster, don't fix it my
> > messing with the classloader: Fix it by eliminating one of them.
> >
> > You might also check if you're not accessing any wrapped object, e.g. by
> > inspecting getManager(session).getClass().getName().
> >
> > Olaf
> >
> >
> >
> > > Here's my code:
> > >
> > > HttpSession session = httpServletRequest.getSession(false);
> > > try {
> > >     RedissonSessionManager rsm = (RedissonSessionManager)
> > getManager(session);
> > > } catch (Exception e) {
> > >     e.printStackTrace();
> > > }
> > >
> > > private Manager getManager(HttpSession session) throws Exception {
> > >
> > >     Field facadeSessionField =
> > > StandardSessionFacade.class.getDeclaredField("session");
> > >     facadeSessionField.setAccessible(true);
> > >     StandardSession stdSession = (StandardSession)
> > > facadeSessionField.get(session);
> > >
> > >     return stdSession.getManager();
> > > }
> > >
> > >
> > >
> > > On Thu, May 7, 2020 at 11:52 PM Mark Thomas <ma...@apache.org> wrote:
> > >
> > >> On 07/05/2020 21:36, Jonathan Yom-Tov wrote:
> > >>> My application uses Redisson (a client which persists the session to
> > >>> Redis). There are two Redisson jar files located in
> $CATALINA_HOME/lib,
> > >> so
> > >>> if I understand the docs correctly they're loaded by the common class
> > >>> loader.
> > >>>
> > >>> I want to access the RedissonSessionManager class during a request.
> The
> > >>> problem is that if I do something like RedissonSessionManager
> manager =
> > >>> (RedissonSessionManager) session.getManager() I get a
> > ClassCastException,
> > >>> presumably because they were loaded by different class loaders.
> > >>>
> > >>> Will it help if I somehow access the common class loader for this? If
> > so
> > >>> how can I do that? If not is there some other way I can achieve this?
> > >> Make sure you don't have those JARs in your application's WEB-INF/lib
> as
> > >> well as $CATALINA_BASE/lib.
> > >>
> > >> In any recent version of Tomcat any JAR in $CATALINA_BASE/lib will be
> > >> visible to your application.
> > >>
> > >> Mark
> > >>
> > >> ---------------------------------------------------------------------
> > >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > >> For additional commands, e-mail: users-help@tomcat.apache.org
> > >>
> > >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
> >
>
> --
> [image: SysAid Technologies]
> <
> http://www.sysaid.com/?utm_source=signature&utm_medium=email&utm_campaign=sysaid-logo
> >
> Jonathan Yom-Tov
> Senior Architect
> jonathan.yomtov@sysaid.com
> Phone (IL): +972 (3) 533-3675 Ext. 932
> [image: SysAid Technologies]
> <
> https://www.sysaid.com/?utm_source=signature&utm_medium=email&utm_campaign=sysaid-logo-icon
> >
>   [image: SysAid on Facebook] <https://www.facebook.com/SysAidIT>
>  [image:
> SysAid on Twitter] <https://twitter.com/sysaid>   [image: SysAid on
> Linked-in] <https://www.linkedin.com/company/sysaid-technologies-ltd>
>  [image:
> SysAid on YouTube] <https://www.youtube.com/user/SysAidIT>   [image:
> SysAid
> on Instagram] <https://www.instagram.com/sysaid_technologies/>
> [image: Banner] <https://www.sysaid.com/sig-link>
>


-- 

"Ever tried. Ever failed. No matter. Try Again. Fail again. Fail better."

- Samuel Beckett

Re: how do I switch class loaders

Posted by Jonathan Yom-Tov <jo...@sysaid.com>.
This is very odd. I ran Tomcat with -verbose:class (see relevant output
below). The class is being loaded twice from the same location, I'm
guessing by two different class loaders. How can that be?

[Loaded org.redisson.tomcat.RedissonSessionManager from
file:/C:/dev/tomcat.9.0.19/lib/redisson-tomcat-9-3.12.2.jar]
[Loaded org.redisson.tomcat.RedissonSessionManager$2 from
file:/C:/dev/tomcat.9.0.19/lib/redisson-tomcat-9-3.12.2.jar]

On Fri, May 8, 2020 at 11:04 AM Olaf Kock <to...@olafkock.de> wrote:

>
> On 08.05.20 09:37, Jonathan Yom-Tov wrote:
> > Thanks Mark. Just tried that. I put the redisson-tomcat jar outside of
> > WEB-INF/lib and added it with scope provided. I get the exact same issue.
> > What am I doing wrong?
>
> Make sure, it's actually gone from your webapp. Depending on the
> deployment technique I've seen removed files to persist from previous
> deployments.
>
> You might need to fully undeploy, then deploy the new version without
> the jar in question. But inspect the runtime environment to make sure
> you only have a single library accessible. Having the same class
> available two different ways is a recipe for disaster, don't fix it my
> messing with the classloader: Fix it by eliminating one of them.
>
> You might also check if you're not accessing any wrapped object, e.g. by
> inspecting getManager(session).getClass().getName().
>
> Olaf
>
>
>
> > Here's my code:
> >
> > HttpSession session = httpServletRequest.getSession(false);
> > try {
> >     RedissonSessionManager rsm = (RedissonSessionManager)
> getManager(session);
> > } catch (Exception e) {
> >     e.printStackTrace();
> > }
> >
> > private Manager getManager(HttpSession session) throws Exception {
> >
> >     Field facadeSessionField =
> > StandardSessionFacade.class.getDeclaredField("session");
> >     facadeSessionField.setAccessible(true);
> >     StandardSession stdSession = (StandardSession)
> > facadeSessionField.get(session);
> >
> >     return stdSession.getManager();
> > }
> >
> >
> >
> > On Thu, May 7, 2020 at 11:52 PM Mark Thomas <ma...@apache.org> wrote:
> >
> >> On 07/05/2020 21:36, Jonathan Yom-Tov wrote:
> >>> My application uses Redisson (a client which persists the session to
> >>> Redis). There are two Redisson jar files located in $CATALINA_HOME/lib,
> >> so
> >>> if I understand the docs correctly they're loaded by the common class
> >>> loader.
> >>>
> >>> I want to access the RedissonSessionManager class during a request. The
> >>> problem is that if I do something like RedissonSessionManager manager =
> >>> (RedissonSessionManager) session.getManager() I get a
> ClassCastException,
> >>> presumably because they were loaded by different class loaders.
> >>>
> >>> Will it help if I somehow access the common class loader for this? If
> so
> >>> how can I do that? If not is there some other way I can achieve this?
> >> Make sure you don't have those JARs in your application's WEB-INF/lib as
> >> well as $CATALINA_BASE/lib.
> >>
> >> In any recent version of Tomcat any JAR in $CATALINA_BASE/lib will be
> >> visible to your application.
> >>
> >> Mark
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >>
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

-- 
[image: SysAid Technologies]
<http://www.sysaid.com/?utm_source=signature&utm_medium=email&utm_campaign=sysaid-logo>
Jonathan Yom-Tov
Senior Architect
jonathan.yomtov@sysaid.com
Phone (IL): +972 (3) 533-3675 Ext. 932
[image: SysAid Technologies]
<https://www.sysaid.com/?utm_source=signature&utm_medium=email&utm_campaign=sysaid-logo-icon>
  [image: SysAid on Facebook] <https://www.facebook.com/SysAidIT>   [image:
SysAid on Twitter] <https://twitter.com/sysaid>   [image: SysAid on
Linked-in] <https://www.linkedin.com/company/sysaid-technologies-ltd>   [image:
SysAid on YouTube] <https://www.youtube.com/user/SysAidIT>   [image: SysAid
on Instagram] <https://www.instagram.com/sysaid_technologies/>
[image: Banner] <https://www.sysaid.com/sig-link>

Re: how do I switch class loaders

Posted by Olaf Kock <to...@olafkock.de>.
On 08.05.20 09:37, Jonathan Yom-Tov wrote:
> Thanks Mark. Just tried that. I put the redisson-tomcat jar outside of
> WEB-INF/lib and added it with scope provided. I get the exact same issue.
> What am I doing wrong?

Make sure, it's actually gone from your webapp. Depending on the
deployment technique I've seen removed files to persist from previous
deployments.

You might need to fully undeploy, then deploy the new version without
the jar in question. But inspect the runtime environment to make sure
you only have a single library accessible. Having the same class
available two different ways is a recipe for disaster, don't fix it my
messing with the classloader: Fix it by eliminating one of them.

You might also check if you're not accessing any wrapped object, e.g. by
inspecting getManager(session).getClass().getName().

Olaf



> Here's my code:
>
> HttpSession session = httpServletRequest.getSession(false);
> try {
>     RedissonSessionManager rsm = (RedissonSessionManager) getManager(session);
> } catch (Exception e) {
>     e.printStackTrace();
> }
>
> private Manager getManager(HttpSession session) throws Exception {
>
>     Field facadeSessionField =
> StandardSessionFacade.class.getDeclaredField("session");
>     facadeSessionField.setAccessible(true);
>     StandardSession stdSession = (StandardSession)
> facadeSessionField.get(session);
>
>     return stdSession.getManager();
> }
>
>
>
> On Thu, May 7, 2020 at 11:52 PM Mark Thomas <ma...@apache.org> wrote:
>
>> On 07/05/2020 21:36, Jonathan Yom-Tov wrote:
>>> My application uses Redisson (a client which persists the session to
>>> Redis). There are two Redisson jar files located in $CATALINA_HOME/lib,
>> so
>>> if I understand the docs correctly they're loaded by the common class
>>> loader.
>>>
>>> I want to access the RedissonSessionManager class during a request. The
>>> problem is that if I do something like RedissonSessionManager manager =
>>> (RedissonSessionManager) session.getManager() I get a ClassCastException,
>>> presumably because they were loaded by different class loaders.
>>>
>>> Will it help if I somehow access the common class loader for this? If so
>>> how can I do that? If not is there some other way I can achieve this?
>> Make sure you don't have those JARs in your application's WEB-INF/lib as
>> well as $CATALINA_BASE/lib.
>>
>> In any recent version of Tomcat any JAR in $CATALINA_BASE/lib will be
>> visible to your application.
>>
>> Mark
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: how do I switch class loaders

Posted by Jonathan Yom-Tov <jo...@sysaid.com>.
Thanks Mark. Just tried that. I put the redisson-tomcat jar outside of
WEB-INF/lib and added it with scope provided. I get the exact same issue.
What am I doing wrong?

Here's my code:

HttpSession session = httpServletRequest.getSession(false);
try {
    RedissonSessionManager rsm = (RedissonSessionManager) getManager(session);
} catch (Exception e) {
    e.printStackTrace();
}

private Manager getManager(HttpSession session) throws Exception {

    Field facadeSessionField =
StandardSessionFacade.class.getDeclaredField("session");
    facadeSessionField.setAccessible(true);
    StandardSession stdSession = (StandardSession)
facadeSessionField.get(session);

    return stdSession.getManager();
}



On Thu, May 7, 2020 at 11:52 PM Mark Thomas <ma...@apache.org> wrote:

> On 07/05/2020 21:36, Jonathan Yom-Tov wrote:
> > My application uses Redisson (a client which persists the session to
> > Redis). There are two Redisson jar files located in $CATALINA_HOME/lib,
> so
> > if I understand the docs correctly they're loaded by the common class
> > loader.
> >
> > I want to access the RedissonSessionManager class during a request. The
> > problem is that if I do something like RedissonSessionManager manager =
> > (RedissonSessionManager) session.getManager() I get a ClassCastException,
> > presumably because they were loaded by different class loaders.
> >
> > Will it help if I somehow access the common class loader for this? If so
> > how can I do that? If not is there some other way I can achieve this?
>
> Make sure you don't have those JARs in your application's WEB-INF/lib as
> well as $CATALINA_BASE/lib.
>
> In any recent version of Tomcat any JAR in $CATALINA_BASE/lib will be
> visible to your application.
>
> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

-- 
[image: SysAid Technologies]
<http://www.sysaid.com/?utm_source=signature&utm_medium=email&utm_campaign=sysaid-logo>
Jonathan Yom-Tov
Senior Architect
jonathan.yomtov@sysaid.com
Phone (IL): +972 (3) 533-3675 Ext. 932
[image: SysAid Technologies]
<https://www.sysaid.com/?utm_source=signature&utm_medium=email&utm_campaign=sysaid-logo-icon>
  [image: SysAid on Facebook] <https://www.facebook.com/SysAidIT>   [image:
SysAid on Twitter] <https://twitter.com/sysaid>   [image: SysAid on
Linked-in] <https://www.linkedin.com/company/sysaid-technologies-ltd>   [image:
SysAid on YouTube] <https://www.youtube.com/user/SysAidIT>   [image: SysAid
on Instagram] <https://www.instagram.com/sysaid_technologies/>
[image: Banner] <https://www.sysaid.com/sig-link>

Re: how do I switch class loaders

Posted by Mark Thomas <ma...@apache.org>.
On 07/05/2020 21:36, Jonathan Yom-Tov wrote:
> My application uses Redisson (a client which persists the session to
> Redis). There are two Redisson jar files located in $CATALINA_HOME/lib, so
> if I understand the docs correctly they're loaded by the common class
> loader.
> 
> I want to access the RedissonSessionManager class during a request. The
> problem is that if I do something like RedissonSessionManager manager =
> (RedissonSessionManager) session.getManager() I get a ClassCastException,
> presumably because they were loaded by different class loaders.
> 
> Will it help if I somehow access the common class loader for this? If so
> how can I do that? If not is there some other way I can achieve this?

Make sure you don't have those JARs in your application's WEB-INF/lib as
well as $CATALINA_BASE/lib.

In any recent version of Tomcat any JAR in $CATALINA_BASE/lib will be
visible to your application.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org