<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JEE7 &#8211; Pauls Blog</title>
	<atom:link href="https://sterl.org/tag/jee7/feed/" rel="self" type="application/rss+xml" />
	<link>https://sterl.org</link>
	<description></description>
	<lastBuildDate>Sat, 21 Sep 2019 12:44:55 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>
	<item>
		<title>JEE 7 Activiti integration</title>
		<link>https://sterl.org/2017/09/jee-7-activiti-integration/</link>
					<comments>https://sterl.org/2017/09/jee-7-activiti-integration/#respond</comments>
		
		<dc:creator><![CDATA[Paul Sterl]]></dc:creator>
		<pubDate>Sat, 02 Sep 2017 14:12:46 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Activiti]]></category>
		<category><![CDATA[alfresco]]></category>
		<category><![CDATA[BPM]]></category>
		<category><![CDATA[JEE7]]></category>
		<guid isPermaLink="false">http://sterl.org/?p=239</guid>

					<description><![CDATA[Overview To enable Activiti in our JEE project the following steps are needed: Add the maven dependencies &#8212; include spring-context Add log4j configuration Add the activiti configuration for CDI integration&#160;activiti.cfg.xml Add your first activiti workflow Add an activiti compatible data source to your container Deploy and run it Git Project. Eclipse Plugin To install the&#8230;]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading"> Overview</h2>



<p> To enable Activiti in our JEE project the following steps are needed: </p>



<ol class="wp-block-list"><li>Add the maven dependencies &#8212; include spring-context</li><li>Add log4j configuration</li><li>Add the activiti configuration for CDI integration&nbsp;activiti.cfg.xml</li><li>Add your first activiti workflow</li><li>Add an activiti compatible data source to your container</li><li>Deploy and run it </li></ol>



<p><a href="https://github.com/sterlp/jee7-activiti">Git Project</a>.

</p>



<h2 class="wp-block-heading"> Eclipse Plugin</h2>



<p> To install the activiti designer just add the following update site to eclipse:&nbsp;http://docs.alfresco.com/5.2/tasks/wf-install-activiti-designer.html for more details just check the <a rel="noreferrer noopener" href="https://www.activiti.org/userguide/#eclipseDesignerInstallation" target="_blank">documentation</a>. </p>



<h2 class="wp-block-heading"> Add activity maven dependencies </h2>



<p> For JEE we want not only to add the normal dependencies for the core lib but also the CDI integration which allows us later on to access our CDI or EJB beans. In addition, we need one more dependency to have the JNDI bean. </p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror cm-s-material" data-setting="{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;xml&quot;,&quot;mime&quot;:&quot;application/xml&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;XML&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;xml&quot;}">&lt;!-- activiti --&gt; 
&lt;dependency&gt; 
  &lt;groupId&gt;org.activiti&lt;/groupId&gt; 
  &lt;artifactId&gt;activiti-engine&lt;/artifactId&gt; 
  &lt;version&gt;6.0.0&lt;/version&gt; 
&lt;/dependency&gt; 
&lt;dependency&gt; 
  &lt;groupId&gt;org.activiti&lt;/groupId&gt; 
  &lt;artifactId&gt;activiti-cdi&lt;/artifactId&gt; 
  &lt;version&gt;6.0.0&lt;/version&gt; 
&lt;/dependency&gt; 
&lt;!-- to get org.springframework.jndi.JndiObjectFactoryBean, same version as used by activiti --&gt; 
&lt;dependency&gt; 
  &lt;groupId&gt;org.springframework&lt;/groupId&gt; 
  &lt;artifactId&gt;spring-context&lt;/artifactId&gt; 
  &lt;version&gt;4.2.5.RELEASE&lt;/version&gt; 
&lt;/dependency&gt; 
&lt;!-- Needed to see the log --&gt; 
&lt;dependency&gt; 
  &lt;groupId&gt;org.slf4j&lt;/groupId&gt; 
  &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt; 
  &lt;version&gt;${slf4j.version}&lt;/version&gt; 
&lt;/dependency&gt;</pre></div>



<h2 class="wp-block-heading"> Add log4j configuration </h2>



<p>Before we start with activiti we should add the log4j.xml configuration into src/main/resources which would allow us to see any error in activiti, otherwise, we are blind. </p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror cm-s-material" data-setting="{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;xml&quot;,&quot;mime&quot;:&quot;application/xml&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;XML&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;xml&quot;}">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt; 
&lt;!DOCTYPE log4j:configuration SYSTEM &quot;log4j.dtd&quot;&gt; 
&lt;log4j:configuration debug=&quot;true&quot; xmlns:log4j='http://jakarta.apache.org/log4j/'&gt; 
  &lt;appender name=&quot;console&quot; class=&quot;org.apache.log4j.ConsoleAppender&quot;&gt; 
    &lt;layout class=&quot;org.apache.log4j.PatternLayout&quot;&gt; 
      &lt;param name=&quot;ConversionPattern&quot; value=&quot;%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n&quot; /&gt; 
    &lt;/layout&gt; 
  &lt;/appender&gt; 
  &lt;root&gt; 
    &lt;level value=&quot;INFO&quot; /&gt; &lt;appender-ref ref=&quot;console&quot; /&gt; 
  &lt;/root&gt; 
&lt;/log4j:configuration&gt;</pre></div>



<h2 class="wp-block-heading"> Add activiti configuration</h2>



<p>Add to the <code>src/main/resources</code> folder the default&nbsp;<code>activiti.cfg.xml</code> configuration which is picked up automatically by the activiti CDI integration to create the process engine.</p>



<div class="bs-callout bs-callout-info"><strong>Note:</strong>&nbsp;We set here the <code>TransactionManager</code> and the <code>ThreadFactory</code> to ensure threads and the transaction is managed by the JEE container. You may also provide the executor which is configured in the JEE container by you. As the <code>ManagedAsyncJobExecutor</code> is just creating a <code>ThreadPoolExecutor</code> under the hood.
</div>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror cm-s-material" data-setting="{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;htmlmixed&quot;,&quot;mime&quot;:&quot;text/html&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;HTML&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;html&quot;}">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; 
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd&quot;&gt; 
  &lt;!-- lookup the JTA-Transaction manager --&gt; 
  &lt;bean id=&quot;transactionManager&quot; class=&quot;org.springframework.jndi.JndiObjectFactoryBean&quot;&gt; 
    &lt;property name=&quot;jndiName&quot; value=&quot;java:appserver/TransactionManager&quot; /&gt; 
    &lt;property name=&quot;resourceRef&quot; value=&quot;true&quot; /&gt; 
  &lt;/bean&gt; 
  &lt;!-- using the JEE container thread factory for the managed executor service --&gt; 
  &lt;bean id=&quot;asyncExecutor&quot; class=&quot;org.activiti.engine.impl.asyncexecutor.ManagedAsyncJobExecutor&quot;&gt; 
    &lt;property name=&quot;threadFactory&quot;&gt; 
      &lt;bean class=&quot;org.springframework.jndi.JndiObjectFactoryBean&quot;&gt; 
        &lt;property name=&quot;jndiName&quot; value=&quot;java:comp/DefaultManagedThreadFactory&quot; /&gt; 
        &lt;property name=&quot;resourceRef&quot; value=&quot;true&quot; /&gt; 
      &lt;/bean&gt; 
    &lt;/property&gt; 
  &lt;/bean&gt; 
  &lt;!-- process engine configuration --&gt; 
  &lt;bean id=&quot;processEngineConfiguration&quot; class=&quot;org.activiti.cdi.CdiJtaProcessEngineConfiguration&quot;&gt; 
    &lt;property name=&quot;dataSourceJndiName&quot; value=&quot;jdbc/postgresql&quot; /&gt; 
    &lt;property name=&quot;transactionManager&quot; ref=&quot;transactionManager&quot; /&gt; 
    &lt;property name=&quot;asyncExecutor&quot; ref=&quot;asyncExecutor&quot; /&gt; 
    &lt;!-- using externally managed transactions --&gt; 
    &lt;property name=&quot;transactionsExternallyManaged&quot; value=&quot;true&quot; /&gt; 
    &lt;!-- will create the activiti DB schema automatically as needed --&gt; 
    &lt;property name=&quot;databaseSchemaUpdate&quot; value=&quot;true&quot; /&gt; 
  &lt;/bean&gt; 
&lt;/beans&gt;</pre></div>



<h2 class="wp-block-heading"> Deploy a workflow </h2>



<p> Overall where to ways to deploy your workflows. Either using XML or programmatically. Here I will use the last to demonstrate the injection and usage in a very simple&nbsp;(not production-ready) way: </p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror cm-s-material" data-setting="{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}">@Singleton
@Startup
public class SampleProcessDeployerBA {

    @Inject RepositoryService repositoryService;

    @PostConstruct
    void start() {
        // this will deploy the same process over and over again ...
        Deployment deploy = repositoryService.createDeployment()
                .name(&quot;SampleProcess&quot;)
                .key(&quot;SampleProcess&quot;) // note this has no effect, the ID of the bpmn file is used &quot;myProcess&quot;
                .addClasspathResource(&quot;org/sterl/jee/activiti/impl/sample/control/SampleProcess.bpmn&quot;)
                .deploy();
        System.out.println(&quot;Deployed process ID: &quot; + deploy.getId() + &quot; KEY &quot; + deploy.getKey());
    }
}</pre></div>



<h2 class="wp-block-heading"> Start a workflow</h2>



<div class="bs-callout bs-callout-info">
<strong>Note:</strong> The process ID is defined in the process <code>bpmn</code> file.
</div>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror cm-s-material" data-setting="{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}">@Named // that activiti finds this EJB
@Singleton // show that this is a singleton
public class HelloWorldBF {
    @Inject RuntimeService runtimeService;

    public void startProcess() {
        // use here the id you defined in the process designer
        ProcessInstance process = runtimeService.startProcessInstanceByKey(&quot;myProcess&quot;);
        System.out.println(&quot;Process &quot; + process.getName() + &quot; started with ID: &quot; + process.getId());
    }
}</pre></div>



<h2 class="wp-block-heading">Activiti support currently following DB </h2>



<p>Add to your JEE container one JNDI data source of one of the following supported database types. In this sample we name it <code>jdbc/activiti</code>.</p>



<div class="bs-callout bs-callout-info"><strong>Note:</strong> The default Sample DB of Payara is a Apache Derby DB and is not supported by Activiti. </div>



<p>This list is taken from <a href="https://www.activiti.org/userguide/#supporteddatabases" target="_blank" rel="noreferrer noopener">version 6.0</a>.</p>



<ul class="wp-block-list"><li>H2</li><li>HSQL</li><li>MYSQL</li><li>ORACLE</li><li>POSTGRES</li><li>MSSQL</li><li>DB2</li></ul>



<pre style="white-space: pre;">Information:   2017-08-31 20:49:49 ERROR ProcessEngines:169 - Exception while initializing process engine: couldn't deduct database type from database product name 'Apache Derby'
org.activiti.engine.ActivitiException: couldn't deduct database type from database product name 'Apache Derby'
	at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initDatabaseType(ProcessEngineConfigurationImpl.java:963)
	at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initDataSource(ProcessEngineConfigurationImpl.java:907)
	at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.init(ProcessEngineConfigurationImpl.java:689)
	at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:664)
	at org.activiti.engine.ProcessEngines.buildProcessEngine(ProcessEngines.java:189)
	at org.activiti.engine.ProcessEngines.initProcessEngineFromResource(ProcessEngines.java:162)
	at org.activiti.engine.ProcessEngines.init(ProcessEngines.java:94)
	at org.activiti.engine.ProcessEngines.getProcessEngine(ProcessEngines.java:223)
</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://sterl.org/2017/09/jee-7-activiti-integration/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
