org.camunda.bpm.engine.impl.util.ClassLoaderUtil Java Examples

The following examples show how to use org.camunda.bpm.engine.impl.util.ClassLoaderUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EjbProcessApplication.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public <T> T execute(Callable<T> callable) throws ProcessApplicationExecutionException {
  ClassLoader originalClassloader = ClassLoaderUtil.getContextClassloader();
  ClassLoader processApplicationClassloader = getProcessApplicationClassloader();

  try {
    if (originalClassloader != processApplicationClassloader) {
      ClassLoaderUtil.setContextClassloader(processApplicationClassloader);
    }

    return callable.call();

  }
  catch(Exception e) {
    throw LOG.processApplicationExecutionException(e);
  }
  finally {
    ClassLoaderUtil.setContextClassloader(originalClassloader);
  }
}
 
Example #2
Source File: ProcessApplicationContextUtil.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public static boolean requiresContextSwitch(ProcessApplicationReference processApplicationReference) {

    final ProcessApplicationReference currentProcessApplication = Context.getCurrentProcessApplication();

    if(processApplicationReference == null) {
      return false;
    }

    if(currentProcessApplication == null) {
      return true;
    }
    else {
      if(!processApplicationReference.getName().equals(currentProcessApplication.getName())) {
        return true;
      }
      else {
        // check whether the thread context has been manipulated since last context switch. This can happen as a result of
        // an operation causing the container to switch to a different application.
        // Example: JavaDelegate implementation (inside PA) invokes an EJB from different application which in turn interacts with the Process engine.
        ClassLoader processApplicationClassLoader = ProcessApplicationClassloaderInterceptor.getProcessApplicationClassLoader();
        ClassLoader currentClassloader = ClassLoaderUtil.getContextClassloader();
        return currentClassloader != processApplicationClassLoader;
      }
    }
  }
 
Example #3
Source File: MscRuntimeContainerDelegate.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected void deployServletProcessApplication(ServletProcessApplication processApplication) {

  ClassLoader contextClassloader = ClassLoaderUtil.getContextClassloader();
  String moduleName = ((ModuleClassLoader)contextClassloader).getModule().getIdentifier().toString();

  ServiceName serviceName = ServiceNames.forNoViewProcessApplicationStartService(moduleName);
  ServiceName paModuleService = ServiceNames.forProcessApplicationModuleService(moduleName);

  if(serviceContainer.getService(serviceName) == null) {

    ServiceController<ServiceTarget> requiredService = (ServiceController<ServiceTarget>) serviceContainer.getRequiredService(paModuleService);

    NoViewProcessApplicationStartService service = new NoViewProcessApplicationStartService(processApplication.getReference());
    requiredService.getValue()
      .addService(serviceName, service)
      .setInitialMode(Mode.ACTIVE)
      .install();

  }
}
 
Example #4
Source File: MscRuntimeContainerDelegate.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected void deployServletProcessApplication(ServletProcessApplication processApplication) {

  ClassLoader contextClassloader = ClassLoaderUtil.getContextClassloader();
  String moduleName = ((ModuleClassLoader)contextClassloader).getModule().getIdentifier().toString();

  ServiceName serviceName = ServiceNames.forNoViewProcessApplicationStartService(moduleName);
  ServiceName paModuleService = ServiceNames.forProcessApplicationModuleService(moduleName);

  if(serviceContainer.getService(serviceName) == null) {

    ServiceController<ServiceTarget> requiredService = (ServiceController<ServiceTarget>) serviceContainer.getRequiredService(paModuleService);

    NoViewProcessApplicationStartService service = new NoViewProcessApplicationStartService(processApplication.getReference());
    requiredService.getValue()
      .addService(serviceName, service)
      .setInitialMode(Mode.ACTIVE)
      .install();

  }
}
 
Example #5
Source File: ConnectProcessEnginePlugin.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
  // use classloader which loaded the plugin
  ClassLoader classloader = ClassLoaderUtil.getClassloader(ConnectProcessEnginePlugin.class);
  Connectors.loadConnectors(classloader);

  addConnectorParseListener(processEngineConfiguration);
}
 
Example #6
Source File: AbstractProcessApplication.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public <T> T execute(Callable<T> callable) throws ProcessApplicationExecutionException {
  ClassLoader originalClassloader = ClassLoaderUtil.getContextClassloader();
  ClassLoader processApplicationClassloader = getProcessApplicationClassloader();

  try {
    ClassLoaderUtil.setContextClassloader(processApplicationClassloader);

    return callable.call();

  } catch (Exception e) {
    throw LOG.processApplicationExecutionException(e);
  } finally {
    ClassLoaderUtil.setContextClassloader(originalClassloader);
  }
}
 
Example #7
Source File: ProcessApplicationClassloaderInterceptor.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public T call() throws Exception {
  try {
    // record thread context right after context switch
    PA_CLASSLOADER.set(ClassLoaderUtil.getContextClassloader());

    // proceed with delegate callable invocation
    return delegate.call();

  }
  finally {
    PA_CLASSLOADER.remove();
  }
}
 
Example #8
Source File: AbstractParseBpmPlatformXmlStep.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public URL lookupBpmPlatformXmlFromClassPath(String resourceLocation) {
  URL fileLocation = ClassLoaderUtil.getClassloader(getClass()).getResource(resourceLocation);

  if (fileLocation != null) {
    LOG.foundConfigAtLocation(resourceLocation, fileLocation.toString());
  }

  return fileLocation;
}
 
Example #9
Source File: DiscoverBpmPlatformPluginsStep.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected ClassLoader getPluginsClassloader() {

    ClassLoader pluginsClassLoader = ClassLoaderUtil.getContextClassloader();
    if(pluginsClassLoader == null) {
      // if context classloader is null, use classloader which loaded the camunda-engine jar.
      pluginsClassLoader = BpmPlatform.class.getClassLoader();
    }

    return pluginsClassLoader;
  }
 
Example #10
Source File: SpringBootSpinProcessEnginePlugin.java    From camunda-bpm-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
@Override
public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
  ClassLoader classloader = ClassLoaderUtil.getClassloader(SpringBootSpinProcessEnginePlugin.class);
  loadSpringBootDataFormats(classloader);
}
 
Example #11
Source File: SpringBootSpinProcessEnginePlugin.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Override
public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
  ClassLoader classloader = ClassLoaderUtil.getClassloader(SpringBootSpinProcessEnginePlugin.class);
  loadSpringBootDataFormats(classloader);
}
 
Example #12
Source File: SpinProcessEnginePlugin.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Override
public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
  // use classloader which loaded the plugin
  ClassLoader classloader = ClassLoaderUtil.getClassloader(SpinProcessEnginePlugin.class);
  DataFormats.loadDataFormats(classloader);
}
 
Example #13
Source File: AbstractProcessApplication.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public ClassLoader getProcessApplicationClassloader() {
  // the default implementation uses the classloader that loaded
  // the application-provided subclass of this class.
  return ClassLoaderUtil.getClassloader(getClass());
}
 
Example #14
Source File: ServletProcessApplication.java    From camunda-bpm-platform with Apache License 2.0 3 votes vote down vote up
protected ClassLoader initProcessApplicationClassloader(ServletContextEvent sce) {

    if (isServlet30ApiPresent(sce) && getClass().equals(ServletProcessApplication.class)) {
      return ClassLoaderUtil.getServletContextClassloader(sce);

    } else {
      return ClassLoaderUtil.getClassloader(getClass());

    }

  }