Return-Path: X-Original-To: apmail-camel-issues-archive@minotaur.apache.org Delivered-To: apmail-camel-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EF02B1857A for ; Thu, 9 Jul 2015 11:12:04 +0000 (UTC) Received: (qmail 47628 invoked by uid 500); 9 Jul 2015 11:12:04 -0000 Delivered-To: apmail-camel-issues-archive@camel.apache.org Received: (qmail 47591 invoked by uid 500); 9 Jul 2015 11:12:04 -0000 Mailing-List: contact issues-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list issues@camel.apache.org Received: (qmail 47580 invoked by uid 99); 9 Jul 2015 11:12:04 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Jul 2015 11:12:04 +0000 Date: Thu, 9 Jul 2015 11:12:04 +0000 (UTC) From: "Claus Ibsen (JIRA)" To: issues@camel.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Resolved] (CAMEL-7708) osgi - Dozer class loading works only in last bundle MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CAMEL-7708?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Claus Ibsen resolved CAMEL-7708. -------------------------------- Resolution: Implemented > osgi - Dozer class loading works only in last bundle > ---------------------------------------------------- > > Key: CAMEL-7708 > URL: https://issues.apache.org/jira/browse/CAMEL-7708 > Project: Camel > Issue Type: Bug > Components: camel-dozer, osgi > Affects Versions: 2.13.2 > Reporter: Jozef Tomek > Fix For: 2.16.0 > > > DozerTypeConverterLoader in it's init() method sets CamelToDozerClassResolverAdapter, properly resolving resources only within bundle being currently loaded, to Dozer's BeanContainer.getInstance(). > Because of Dozer using singletons, this DozerClassLoader implementation is then used for mappings done in context of all bundles. This effectively means that class loading will work only for the bundle (using dozer) that was started the last. > Code of interest: > {code:title=org.apache.camel.converter.dozer.DozerTypeConverterLoader|borderStyle=solid} > 167 CamelToDozerClassResolverAdapter adapter = new CamelToDozerClassResolverAdapter(camelContext); > 168 BeanContainer.getInstance().setClassLoader(adapter); > {code} > *Symptoms* > For me the symptoms were NPE when Dozer's JAXBBeanFactory tried to create mapping-target class instance by loading ObjectFactory class and calling the appropriate create method. Installed CamelToDozerClassResolverAdapter was unable to load ObjectFactory residing in different bundle (started not as the last one), which immediatelly caused NPE. > However I would say it has to fail even when default bean creation method instead of JAXBBeanFactory is used. > *Workaround* > Since I had to deliver working module that day, my quick and not very nice workaround was to extend DozerTypeConverterLoader, override its' init() method and after calling super.init() replace the loader set on BeanContainer.getInstance() with my custom DozerClassLoader. > This custom loader knows what bundle it was created for, what loader was set on BeanContainer.getInstance() before super.init() changed it \[one hopefully working for all bundles that are already started\], and (new) one that super.init() changed it to \[one working for this new bundle\]. > This custom loader then checks what bundle context is it called from using ugly > {code} > ((BundleDelegatingClassLoader) Thread.currentThread().getContextClassLoader()).getBundle() > {code} > approach. Then it delegates call to proper dozer class loader - either one for that bundle or fallback. -- This message was sent by Atlassian JIRA (v6.3.4#6332)