<?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>JEE &#8211; Pauls Blog</title>
	<atom:link href="https://sterl.org/category/java/java-enterprise-edition/feed/" rel="self" type="application/rss+xml" />
	<link>https://sterl.org</link>
	<description></description>
	<lastBuildDate>Sat, 04 Apr 2020 14:30:33 +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>Reconnecting JMS listener</title>
		<link>https://sterl.org/2020/04/reconnecting-jms-listener/</link>
					<comments>https://sterl.org/2020/04/reconnecting-jms-listener/#respond</comments>
		
		<dc:creator><![CDATA[Paul Sterl]]></dc:creator>
		<pubDate>Sat, 04 Apr 2020 13:34:15 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[Spring Boot]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[JMS]]></category>
		<category><![CDATA[Reconnect]]></category>
		<guid isPermaLink="false">http://sterl.org/?p=558</guid>

					<description><![CDATA[Problem In some projects we still may need to manually to reconnect to our JMS provider. For what ever reason the framework or the container cannot do the job for us. As so we have to ensure that an once registered JMS listener re-register itself if something bad happens. Note: Check first if your container&#8230;]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Problem</h2>



<p>In some projects we still may need to manually to reconnect to our JMS provider. For what ever reason the framework or the container cannot do the job for us. As so we have to ensure that an once registered JMS listener re-register itself if something bad happens.</p>



<div class="bs-callout bs-callout-info"><strong>Note:</strong>
Check first if your container can handle this for you.
</div>



<h2 class="wp-block-heading">Solution</h2>



<p>Well some <code>JmsConnectionFactory</code> already support a re-connection but they are not always very reliable. For instance, the <a rel="noreferrer noopener" href="https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_7.5.0/com.ibm.mq.ref.dev.doc/q111980_.htm" target="_blank">IBM driver supports</a> in theory a reconnect, but it is just a bit buggy.</p>



<p>Well, what is the straight forward solution? The most easiest way is just to register an exception listener with the connection and rebuild the connection from here:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" 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;}"> connection.setExceptionListener((e) -&gt; {
   connection = cf.createConnection();
   session = connection.createSession();
   consumer = session.createConsumer(session.createQueue(&quot;FANCY.QUEUE.NAME&quot;));
   consumer.setMessageListener((m) -&gt; {
     System.out.println(&quot;onMessage: &quot; + m);
   }
   connection.start();
 });
</pre></div>



<p>Not clean but in theory, this is all that we have to do. Of course, we have to handle the state, the old connection and even worse think about a retry if the connection cannot be created immediately again. The last part considering that we have of course also the requirement to stop the connection and avoid race conditions is the hard part.</p>



<h3 class="wp-block-heading">ReconnectinListener</h3>



<p>Let us build a <code>ReconnectingListener</code> step by step. What we have seen above is that we need a way to determine the desired connection state and we have to provide separate methods for <code>connect </code>and <code>disconnect </code>as we will do this more often, in case we have to retry to re-connect again.</p>



<h4 class="wp-block-heading">Connecting and Disconnecting</h4>



<p>Lets us first solve the connect and disconnect problem. The user should be able to:</p>



<ol class="wp-block-list"><li>Have a separate connect method</li><li>Store the user desire if we should be connected or not</li><li>Have a separate disconnect method</li><li>Have a way to clear the resources without to reset the user desire</li><li>Have a way to check if the connection is up and running</li></ol>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" 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;}">@RequiredArgsConstructor
static class ReconnectingListener implements MessageListener,  ExceptionListener {
    final JmsConnectionFactory cf;
    final String destinationQueue;
    
    private Connection connection;
    private Session session;
    private MessageConsumer consumer;
    // 1. Have a separate connect method
    public synchronized void connect() throws JMSException {
        // 2. Store the user desire if we should be connected or not
        shouldRun.set(true);
        if (!isConnected()) {
            connection = cf.createConnection();
            session = connection.createSession();
            consumer = session.createConsumer(session.createQueue(destinationQueue));
            consumer.setMessageListener(this); // register us
            connection.setExceptionListener(this); // react on errors
            connection.start();
        }
    }
    // 3. Have a separate disconnect method 
    public synchronized void disconnect() {
        // 2. Store the user desire if we should be connected or not
        shouldRun.set(false);
        clearConnection();
    }
    // 4. Have a way to clear the resources without to reset the user desire
    private synchronized void clearConnection() {
        JmsUtil.close(consumer);
        JmsUtil.close(session);
        JmsUtil.close(connection);
        consumer = null;
        session = null;
        connection = null;
        LOG.debug(&quot;Connection cleared and stoped&quot;);
   }
   // 5. Have a way to check if the connection is up and running
   public boolean isConnected() {
       return connection != null &amp;&amp; consumer != null &amp;&amp; session != null;
   }</pre></div>



<h4 class="wp-block-heading">Reconnect &#8222;onException&#8220;</h4>



<p>Having solved this we have to re-connect back to the JMS Broker if we lose the connection. For this have to implement the <code>ExceptionListener </code>interface as shown above and now to implement <code>onException</code>.  The goal here is now:</p>



<ol class="wp-block-list"><li>Clear the old connection to avoid a double registration</li><li>Schedule a delayed retry to connect again</li><li>Check if we still should be connected</li><li>Retry again, if we fail in our retry to connect to the broker</li></ol>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" 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;}">// we need a executer to delay a retry attempt
private final ScheduledExecutorService reconnectScheduler = Executors.newScheduledThreadPool(1);
@Override
public void onException(JMSException exception) {
    // 1. Clear the old connection to avoid a double registration
    clearConnection();
    // 2. Schedule a delayed retry to connect again
    reconnect(5);
}
private void reconnect(final int delay) {            
    reconnectScheduler.schedule(() -&gt; {
        // 3. Check if we still should be connected
        if (shouldRun.get()) {
            try {
                // here we use our connect method from above
                connect();
            } catch (Exception e) {
                // 4. Retry again, if we fail in our retry to connect to the broker
                LOG.info(&quot;Reconnect failed, will retry in {}s. {}&quot;, delay, e.getMessage());
                clearConnection(); // just for savety
                reconnect(delay);
            }
        }
    }, delay, TimeUnit.SECONDS);
}</pre></div>



<p>That&#8217;s it. Basically we solved all basic requirements </p>



<h3 class="wp-block-heading">Going further</h3>



<p>We should of course provide the ability to set a subscription filter and maybe we should just implement the <code>Closeable </code>interface to provide a more modern API. Not to forget that we have now hardcoded that we subscribe always to a queue, means a way to tell the code if it is a topic or not would be too bad.  Maybe we should also consider using the JMS 2.x API like:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" 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;}">public synchronized void connectJms2() throws JMSException {
    shouldRun.set(true);
    if (!isConnected()) {
        context = cf.createContext();
        context.setExceptionListener(this);
        context.setAutoStart(true);
        consumer = context.createConsumer(context.createQueue(destinationQueue));
        consumer.setMessageListener(this); // register us
    }
}</pre></div>



<p>Last but not least we could also destroy the executor. Looking forward to a pull request :-).</p>



<h2 class="wp-block-heading">Links</h2>



<ul class="wp-block-list"><li><a rel="noreferrer noopener" href="https://github.com/sterlp/training/blob/master/jms-trainging/src/test/java/org/sterl/training/jms/ibm/IbmReconnectExampleTest.java" target="_blank">Source Code on GitHub</a></li><li><a rel="noreferrer noopener" href="https://docs.oracle.com/cd/E19798-01/821-1751/abljw/index.html" target="_blank">Oracle Docs for connection pool and reconnect for JEE</a></li><li><a href="https://eclipse-ee4j.github.io/glassfish/docs/5.1.0/administration-guide/jms.html" target="_blank" rel="noreferrer noopener">Glassfish Doc</a></li></ul>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://sterl.org/2020/04/reconnecting-jms-listener/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<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>
