activemq-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "clebert suconic (JIRA)" <j...@apache.org>
Subject [jira] [Closed] (ARTEMIS-721) ObjectInputStreamWithClassLoader#resolveClass0 uses Thread.currentThread().getContextClassLoader()
Date Mon, 08 May 2017 19:20:04 GMT

     [ https://issues.apache.org/jira/browse/ARTEMIS-721?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

clebert suconic closed ARTEMIS-721.
-----------------------------------
    Resolution: Won't Fix

this is JMS API. nothing I can do about this.

> ObjectInputStreamWithClassLoader#resolveClass0 uses Thread.currentThread().getContextClassLoader()
> --------------------------------------------------------------------------------------------------
>
>                 Key: ARTEMIS-721
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-721
>             Project: ActiveMQ Artemis
>          Issue Type: Bug
>          Components: osgi
>    Affects Versions: 1.3.0
>         Environment: JDK 1.8.0_91, OS X 10.11.6, Apache Felix 5.0.1
>            Reporter: Peter Robbins
>
> ObjectInputStreamWithClassLoader#resolveClass0 uses Thread.currentThread().getContextClassLoader()
to resolve the the class of a message body when using the JMS 2.0 API to get a message body.
> message.getBody(MyCoolObject.class) will throw javax.jms.MessageFormatException "Body
not assignable to class..." in an OSGi environment. There should be a way to configure which
classloader is used to resolve message objects.
> Workaround:
> Swap out the currentThread context classloader
> {code}
> public class MyCoolMessageListener implements MessageListener {
> 	private static final Logger log = LogManager.getLogger();
> 	@Override
> 	public void onMessage(Message message) {
> 		final ClassLoader loader = Thread.currentThread().getContextClassLoader();
> 		try {
> 			Thread.currentThread().setContextClassLoader(MyCoolObject.class.getClassLoader());
> 			MyCoolObject messageBody = message.getBody(MyCoolObject.class);
> 			message.acknowledge();
> 		} catch (JMSException e) {
> 			log.error(e.getMessage(), e);
> 		} finally {
> 			Thread.currentThread().setContextClassLoader(loader);
> 		}
> 	}
> }
> {code}
> This sort of defeats the purpose of the simpler, more readable, JMS 2 API though.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message