From b700129254aa70fc857d63392edd405bcd355822 Mon Sep 17 00:00:00 2001 From: edwardsmj Date: Tue, 4 Aug 2009 21:19:56 +0000 Subject: Fix classloading problem with ODE dependencies used by implementation-bpel-runtime: force TCCL for those dependencies to be the OSGi Bundle ClassLoader when running under OSGi git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@800980 13f79535-47bb-0310-9956-ffa450edef68 --- .../implementation/bpel/ode/EmbeddedODEServer.java | 76 ++++++++++++---------- 1 file changed, 43 insertions(+), 33 deletions(-) (limited to 'java/sca/modules/implementation-bpel-runtime/src') diff --git a/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServer.java b/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServer.java index 5c0129fd41..b2522326f8 100644 --- a/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServer.java +++ b/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServer.java @@ -87,39 +87,49 @@ public class EmbeddedODEServer { } public void init() throws ODEInitializationException { - Properties p = System.getProperties(); - p.put("derby.system.home", "target"); - - Properties confProps = new Properties(); - confProps.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=false)"); - - _config = new OdeConfigProperties(confProps, "ode-sca"); - - // Setting work root as the directory containing our database - try { - _workRoot = getDatabaseLocationAsFile(); - } catch (URISyntaxException e) { - throw new ODEInitializationException(e); - } - - initTxMgr(); - initPersistence(); - initBpelServer(); - - try { - _bpelServer.start(); - } catch (Exception ex) { - String errmsg = "An error occured during the ODE BPEL server startup."; - __log.error(errmsg, ex); - throw new ODEInitializationException(errmsg, ex); - } - - // Added MJE, 24/06/2009 - for 1.3.2 version of ODE - _scheduler.start(); - // end of addition - - __log.info("ODE BPEL server started."); - _initialized = true; + ClassLoader tccl = Thread.currentThread().getContextClassLoader(); + ClassLoader bpelcl = this.getClass().getClassLoader(); + try{ + // Switch TCCL - under OSGi this causes the TCCL to be set to the Bundle + // classloader - this is then used by 3rd party code from ODE and its dependencies + if( bpelcl != tccl ) Thread.currentThread().setContextClassLoader(bpelcl); + Properties p = System.getProperties(); + p.put("derby.system.home", "target"); + + Properties confProps = new Properties(); + confProps.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=false)"); + + _config = new OdeConfigProperties(confProps, "ode-sca"); + + // Setting work root as the directory containing our database + try { + _workRoot = getDatabaseLocationAsFile(); + } catch (URISyntaxException e) { + throw new ODEInitializationException(e); + } + + initTxMgr(); + initPersistence(); + initBpelServer(); + + try { + _bpelServer.start(); + } catch (Exception ex) { + String errmsg = "An error occured during the ODE BPEL server startup."; + __log.error(errmsg, ex); + throw new ODEInitializationException(errmsg, ex); + } + + // Added MJE, 24/06/2009 - for 1.3.2 version of ODE + _scheduler.start(); + // end of addition + + __log.info("ODE BPEL server started."); + _initialized = true; + } finally { + // Restore the TCCL if we changed it + if( bpelcl != tccl ) Thread.currentThread().setContextClassLoader(tccl); + } } /** -- cgit v1.2.3