/** * Gets classloader associated with {@link CamelContext} * @param context * @return */ private ClassLoader getClassLoader(CamelContext context) { return context.getApplicationContextClassLoader(); }
public ClassLoader getApplicationContextClassLoader() { return this.camelContext != null ? this.camelContext.getApplicationContextClassLoader() : null; }
public MailConfiguration(CamelContext context) { this.applicationClassLoader = context.getApplicationContextClassLoader(); }
public ClassLoadingAwareObjectInputStream(CamelContext camelContext, InputStream in) throws IOException { super(in); inLoader = camelContext.getApplicationContextClassLoader(); }
/** * Strategy to create JAXB context */ protected JAXBContext createContext() throws JAXBException { if (contextPath != null) { // prefer to use application class loader which is most likely to be able to // load the class which has been JAXB annotated ClassLoader cl = camelContext.getApplicationContextClassLoader(); if (cl != null) { LOG.debug("Creating JAXBContext with contextPath: " + contextPath + " and ApplicationContextClassLoader: " + cl); return JAXBContext.newInstance(contextPath, cl); } else { LOG.debug("Creating JAXBContext with contextPath: {}", contextPath); return JAXBContext.newInstance(contextPath); } } else { LOG.debug("Creating JAXBContext"); return JAXBContext.newInstance(); } }
/** * Run a block of code with the {@link CamelContext#getApplicationContextClassLoader()} set as the thread context classloader. * * @param callable the block of code to be run * @throws Exception exceptions being thrown while running the block of code */ public<T> T runWithCamelContextClassLoader(Callable<T> callable) throws Exception { ClassLoader original = Thread.currentThread().getContextClassLoader(); try { ClassLoader loader = context.getApplicationContextClassLoader(); if (loader != null) { logger.debug("Set the thread context classloader {}", loader); Thread.currentThread().setContextClassLoader(loader); } return callable.call(); } finally { // restore CL Thread.currentThread().setContextClassLoader(original); } }
/** * Override the Thread Context ClassLoader if need be. * @return old classloader if overridden; otherwise returns null */ protected ClassLoader overrideTccl(final Exchange exchange) { ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); ClassLoader appCtxCl = exchange.getContext().getApplicationContextClassLoader(); if (oldClassLoader == null || appCtxCl == null) { return null; } if (!oldClassLoader.equals(appCtxCl)) { Thread.currentThread().setContextClassLoader(appCtxCl); if (log.isTraceEnabled()) { log.trace("Overrode TCCL for exchangeId {} to {} on thread {}", new Object[] {exchange.getExchangeId(), appCtxCl, Thread.currentThread().getName()}); } return oldClassLoader; } return null; }
public JCacheManager(JCacheConfiguration configuration) { this.configuration = configuration; this.camelContext = configuration.getCamelContext(); this.classLoader = camelContext != null ? camelContext.getApplicationContextClassLoader() : null; this.cacheName = configuration.getCacheName(); this.provider = null; this.manager = null; this.cache = null; }
/** * Resolves the XStream instance to be used by this data format. If XStream is not explicitly set, new instance will * be created and cached. * * @param context to be used during a configuration of the XStream instance * @return XStream instance used by this data format. */ public XStream getXStream(CamelContext context) { if (xstream == null) { xstream = createXStream(context.getClassResolver(), context.getApplicationContextClassLoader()); } return xstream; }
@Override protected void doStart() throws Exception { if (configuration == null) { configuration = HBaseConfiguration.create(); ClassLoader applicationContextClassLoader = getCamelContext().getApplicationContextClassLoader(); if (applicationContextClassLoader != null) { configuration.setClassLoader(applicationContextClassLoader); HBaseConfiguration.addHbaseResources(configuration); } } connection = ConnectionFactory.createConnection( configuration, Executors.newFixedThreadPool(poolMaxSize) ); }
public OptaPlannerEndpoint(String uri, Component component, OptaPlannerConfiguration configuration) { super(uri, component); this.configuration = configuration; ClassLoader classLoader = getCamelContext().getApplicationContextClassLoader(); solverFactory = SolverFactory.createFromXmlResource(configuration.getConfigFile(), classLoader); }
@Override public Class<?> resolveClass(String name) { LOG.trace("Resolve class {}", name); name = ObjectHelper.normalizeClassName(name); if (ObjectHelper.isEmpty(name)) { return null; } // we need to avoid the NPE issue of loading the class Class<?> clazz = ObjectHelper.loadSimpleType(name); if (clazz == null) { clazz = doLoadClass(name, bundleContext.getBundle()); if (LOG.isTraceEnabled()) { LOG.trace("Loading class {} using BundleContext {} -> {}", name, bundleContext.getBundle(), clazz); } } if (clazz == null && camelContext != null) { // fallback and load class using the application context classloader clazz = super.loadClass(name, camelContext.getApplicationContextClassLoader()); if (LOG.isTraceEnabled()) { LOG.trace("Loading class {} using CamelContext {} -> {}", name, camelContext, clazz); } } return clazz; }
@Override public void setup(CamelContext camelctx) { // Verify that the application context class loader is a ModuleClassLoader ClassLoader classLoader = camelctx.getApplicationContextClassLoader(); IllegalStateAssertion.assertTrue(classLoader instanceof ModuleClassLoader, "Invalid class loader association: " + classLoader); ModuleClassLoader moduleClassLoader = (ModuleClassLoader) classLoader; camelctx.setClassResolver(new WildFlyClassResolver(moduleClassLoader)); } }
@Override public void setup(CamelContext camelctx) { // Verify that the application context class loader is a ModuleClassLoader ClassLoader classLoader = camelctx.getApplicationContextClassLoader(); IllegalStateAssertion.assertTrue(classLoader instanceof ModuleClassLoader, "Invalid class loader association: " + classLoader); ModuleClassLoader moduleClassLoader = (ModuleClassLoader) classLoader; camelctx.setClassResolver(new WildFlyClassResolver(moduleClassLoader)); } }
@Override protected void doStart() throws Exception { ObjectHelper.notNull(camelContext, "camelContext"); // initialize xstream if (xstream == null) { xstream = createXStream(camelContext.getClassResolver(), camelContext.getApplicationContextClassLoader()); } }
protected void createCamelContext(final BundleContext bundleContext, final Map<String, String> props) { if (bundleContext != null) { context = new OsgiDefaultCamelContext(bundleContext, createRegistry(bundleContext)); // Setup the application context classloader with the bundle classloader context.setApplicationContextClassLoader(new BundleDelegatingClassLoader(bundleContext.getBundle())); // and make sure the TCCL is our classloader Thread.currentThread().setContextClassLoader(context.getApplicationContextClassLoader()); } else { context = new DefaultCamelContext(createRegistry()); } setupPropertiesComponent(context, props, log); }
@Override protected void doStart() throws Exception { if (xmlContext == null) { xmlContext = createXMLContext(getCamelContext().getClassResolver(), getCamelContext().getApplicationContextClassLoader()); } }
@SuppressWarnings("unchecked") private Script instantiateScript(Exchange exchange) { // Get the script from the cache, or create a new instance GroovyLanguage language = (GroovyLanguage) exchange.getContext().resolveLanguage("groovy"); Class<Script> scriptClass = language.getScriptFromCache(text); if (scriptClass == null) { GroovyShell shell; Set<GroovyShellFactory> shellFactories = exchange.getContext().getRegistry().findByType(GroovyShellFactory.class); if (shellFactories.size() > 1) { throw new IllegalStateException("Too many GroovyShellFactory instances found: " + shellFactories.size()); } else if (shellFactories.size() == 1) { shell = shellFactories.iterator().next().createGroovyShell(exchange); } else { ClassLoader cl = exchange.getContext().getApplicationContextClassLoader(); shell = cl != null ? new GroovyShell(cl) : new GroovyShell(); } scriptClass = shell.getClassLoader().parseClass(text); language.addScriptToCache(text, scriptClass); } // New instance of the script try { return scriptClass.newInstance(); } catch (InstantiationException e) { throw new RuntimeCamelException(e); } catch (IllegalAccessException e) { throw new RuntimeCamelException(e); } }
private ELEngine createELEngine() { ELEngine answer; ClassLoader appcl = camelContext.getApplicationContextClassLoader(); ClassLoader auxcl = appcl == null ? DozerEndpoint.class.getClassLoader() : appcl; if (ELExpressionFactory.isSupported(auxcl)) { if (RuntimeUtils.isOSGi()) { answer = new TcclELEngine(ELExpressionFactory.newInstance(auxcl), auxcl); } else { answer = new DefaultELEngine(ELExpressionFactory.newInstance()); } } else { LOG.warn("Expressions are not supported by Dozer. Are you missing javax.el dependency?"); answer = new NoopELEngine(); } return answer; } }
private Theme getOrCreateTheme() throws IOException { if (theme == null) { if (themeFolder == null && themeSubfolder == null) { theme = new Theme(); } else if (themeFolder != null && themeSubfolder == null) { URL url = getCamelContext().getClassResolver().loadResourceAsURL(themeFolder); theme = new Theme(url.getPath(), ""); } else { URL url = getCamelContext().getClassResolver().loadResourceAsURL(themeFolder); theme = new Theme(url.getPath(), themeSubfolder); } if (encoding != null) { theme.setEncoding(encoding); } ClassLoader apcl = getCamelContext().getApplicationContextClassLoader(); if (apcl != null) { theme.setJarContext(apcl); } } return theme; }