List of usage examples for java.lang Thread getContextClassLoader
@CallerSensitive
public ClassLoader getContextClassLoader()
From source file:org.apache.geronimo.axis.AxisDiscoveryCLWorkaroundGBean.java
public AxisDiscoveryCLWorkaroundGBean(ClassLoader classLoader) { Thread currentThread = Thread.currentThread(); ClassLoader oldClassLoader = currentThread.getContextClassLoader(); currentThread.setContextClassLoader(classLoader); try {/*from ww w .ja va 2s .c o m*/ //set up log DiscoverSingleton.find(org.apache.commons.logging.LogFactory.class, "commons-logging.properties", //org.apache.commons.logging.LogFactory.FACTORY_PROPERTIES, "org.apache.commons.logging.LogFactory");//org.apache.commons.logging.LogFactory.FACTORY_DEFAULT); //this sets the classloaders used in discovery. One is the current TCCL. AxisProperties.getNameDiscoverer(); } finally { currentThread.setContextClassLoader(oldClassLoader); } }
From source file:org.intalio.tempo.workflow.ServiceObjectSupplier.java
public Object getServiceObject(AxisService service) throws AxisFault { Parameter fac = service.getParameter("SpringBeanFactory"); if (fac != null) { Thread thread = Thread.currentThread(); ClassLoader oldClassLoader = thread.getContextClassLoader(); try {//from w w w . j a v a 2 s . c o m thread.setContextClassLoader(SpringInit.CONTEXT.getClass().getClassLoader()); String factoryName = (String) fac.getValue(); LOG.info("Using factory:" + factoryName); Object o = SpringInit.CONTEXT.getBean(factoryName); //LOG.info("Class:"+o.getClass().getName()); FactoryBean factory = (FactoryBean) o; return factory.getObject(); } catch (Exception e) { LOG.info("Error while using factory", e); } finally { thread.setContextClassLoader(oldClassLoader); } } String beanName = "#unspecified#"; Parameter p = service.getParameter("SpringBeanName"); if (p != null) { beanName = (String) p.getValue(); } Object bean = SpringInit.CONTEXT.getBean(beanName); if (bean == null) { LOG.error("Bean not found: " + beanName); } return bean; }
From source file:org.wso2.carbon.custom.connector.EJBStatelessBean.java
@Override public void connect(MessageContext messageContext) { Thread currentThread = Thread.currentThread(); ClassLoader oldClassLoader = currentThread.getContextClassLoader(); try {/*from w w w . j a va 2 s . c om*/ //switching the classloader to prevent class loading glassfish classloading issues currentThread.setContextClassLoader(getClass().getClassLoader()); callEJBStateless(messageContext); } catch (Exception e) { handleException("Error calling EJB Service from EJBConnector", e, messageContext); } finally { if (oldClassLoader != null) { //resetting the classloader currentThread.setContextClassLoader(oldClassLoader); } } }
From source file:com.googlecode.psiprobe.controllers.threads.GetClassLoaderUrlsController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { String threadName = ServletRequestUtils.getStringParameter(request, "thread", null); Thread thread = Utils.getThreadByName(threadName); if (thread != null) { ClassLoader cl = thread.getContextClassLoader(); if (cl != null && cl instanceof URLClassLoader) { try { request.setAttribute("urls", Arrays.asList(((URLClassLoader) cl).getURLs())); } catch (Exception e) { logger.error("There was an exception querying classloader for thread \"" + threadName + "\"", e);/*ww w .java 2s .c o m*/ } } } return new ModelAndView(getViewName()); }
From source file:org.wso2.carbon.custom.connector.EJBStateful.java
@Override public void connect(MessageContext messageContext) throws ConnectException { Thread currentThread = Thread.currentThread(); ClassLoader oldClassLoader = currentThread.getContextClassLoader(); try {/* ww w. j a v a 2s . c o m*/ //switching the classloader to prevent class loading glassfish classloading issues currentThread.setContextClassLoader(getClass().getClassLoader()); callEJBStateful(messageContext); } catch (Exception e) { handleException("Error calling EJB Service from EJBConnector", e, messageContext); } finally { if (oldClassLoader != null) { //resetting the classloader currentThread.setContextClassLoader(oldClassLoader); } } }
From source file:org.wso2.carbon.custom.connector.EJBConnector.java
@Override public void connect(MessageContext ctx) { log.info("Initializing EJBConnector"); Thread currentThread = Thread.currentThread(); ClassLoader oldClassLoader = currentThread.getContextClassLoader(); try {/*from ww w . j a v a 2 s.c o m*/ //switching the classloader to prevent class loading glassfish classloading issues currentThread.setContextClassLoader(getClass().getClassLoader()); callEJB(); } catch (Exception e) { log.error("Error calling EJB Service from EJBConnector", e); } finally { if (oldClassLoader != null) { //resetting the classloader currentThread.setContextClassLoader(oldClassLoader); } } }
From source file:psiprobe.controllers.threads.GetClassLoaderUrlsController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { String threadName = ServletRequestUtils.getStringParameter(request, "thread", null); Thread thread = Utils.getThreadByName(threadName); if (thread != null) { ClassLoader cl = thread.getContextClassLoader(); if (cl != null && cl instanceof URLClassLoader) { try { request.setAttribute("urls", Arrays.asList(((URLClassLoader) cl).getURLs())); } catch (Exception e) { logger.error("There was an exception querying classloader for thread '{}'", threadName, e); }//from w w w .ja va 2 s. c o m } } return new ModelAndView(getViewName()); }
From source file:org.nuxeo.runtime.bridge.ApplicationManager.java
protected Application load(ApplicationDescriptor desc) throws Exception { log.info("Loading application: " + desc.getName()); ApplicationFactory factory;/*from w w w. j a v a2 s . c o m*/ if (desc.isIsolated()) { IsolatedClassLoader cl = createIsolatedClassLoader(desc); factory = (ApplicationFactory) cl.loadClass(desc.getFactory()).newInstance(); Thread th = Thread.currentThread(); ClassLoader oldcl = th.getContextClassLoader(); th.setContextClassLoader(cl); try { return factory.createApplication(desc); } finally { th.setContextClassLoader(oldcl); } } else { factory = (ApplicationFactory) desc.getBundle().loadClass(desc.getFactory()).newInstance(); return factory.createApplication(desc); } }
From source file:org.intalio.tempo.security.ws.BaseWS.java
protected void initStatics() { if (_initialized) return;/* ww w .j a v a 2 s. c o m*/ try { synchronized (BaseWS.class) { if (_initialized) return; LOG.debug("Initializing configuration."); String configDir = System.getProperty(Constants.CONFIG_DIR_PROPERTY); if (configDir == null) { throw new RuntimeException( "System property " + Constants.CONFIG_DIR_PROPERTY + " not defined."); } _configDir = new File(configDir); if (!_configDir.exists()) { throw new RuntimeException( "Configuration directory " + _configDir.getAbsolutePath() + " doesn't exist."); } Thread thread = Thread.currentThread(); ClassLoader oldClassLoader = thread.getContextClassLoader(); try { thread.setContextClassLoader(getClass().getClassLoader()); FileSystemResource config = new FileSystemResource(new File(_configDir, "securityConfig.xml")); XmlBeanFactory factory = new XmlBeanFactory(config); PropertyPlaceholderConfigurer propsCfg = new PropertyPlaceholderConfigurer(); propsCfg.setSearchSystemEnvironment(true); propsCfg.postProcessBeanFactory(factory); _securityProvider = (SecurityProvider) factory.getBean("securityProvider"); _tokenService = (org.intalio.tempo.security.token.TokenService) factory.getBean("tokenService"); _initialized = true; } finally { thread.setContextClassLoader(oldClassLoader); } } } catch (RuntimeException except) { LOG.error("Error during initialization of security service", except); throw except; } }
From source file:org.nuxeo.runtime.jboss.deployer.Bootstrap.java
public void startNuxeo() throws Exception { Thread thread = Thread.currentThread(); ClassLoader oldcl = thread.getContextClassLoader(); thread.setContextClassLoader(cl);//from www . ja v a2 s. c o m try { doStart(); } finally { thread.setContextClassLoader(oldcl); } }