diff --git a/modules/activiti-spring-boot/pom.xml b/modules/activiti-spring-boot/pom.xml
index cd471f129d68364afe0cab3ee8b5dfe31906c6a6..4493a6a590c34223e80e5aca07fadd600bdcb890 100644
--- a/modules/activiti-spring-boot/pom.xml
+++ b/modules/activiti-spring-boot/pom.xml
@@ -154,6 +154,36 @@
+
+ org.activiti
+ activiti-rest
+
+
+ true
+
com.h2database
@@ -179,6 +209,13 @@
true
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+ ${spring.boot.version}
+ true
+
+
org.springframework.boot
spring-boot-starter-web
diff --git a/modules/activiti-spring-boot/src/main/java/org/activiti/spring/boot/ActivitiProperties.java b/modules/activiti-spring-boot/src/main/java/org/activiti/spring/boot/ActivitiProperties.java
index 0a131999dd8d7a9e520cea8655904d7457ca35da..f43c6a557cdc6c8b26459731aa47fd5d6cf1fc6e 100644
--- a/modules/activiti-spring-boot/src/main/java/org/activiti/spring/boot/ActivitiProperties.java
+++ b/modules/activiti-spring-boot/src/main/java/org/activiti/spring/boot/ActivitiProperties.java
@@ -10,9 +10,25 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
public class ActivitiProperties {
private boolean checkProcessDefinitions;
-
+ private boolean restApiEnabled;
private String deploymentName;
+ public boolean isRestApiEnabled() {
+ return restApiEnabled;
+ }
+
+ public void setRestApiEnabled(boolean restApiEnabled) {
+ this.restApiEnabled = restApiEnabled;
+ }
+
+ public boolean isJpaEnabled() {
+ return jpaEnabled;
+ }
+
+ public void setJpaEnabled(boolean jpaEnabled) {
+ this.jpaEnabled = jpaEnabled;
+ }
+
private String databaseSchemaUpdate = "true" ;
private String databaseSchema;
@@ -21,7 +37,27 @@ public class ActivitiProperties {
private String processDefinitionLocationSuffix = "**.bpmn20.xml";
- private boolean jpa = true; // true by default
+ private String restApiMapping = "/api/";
+
+ public String getRestApiMapping() {
+ return restApiMapping;
+ }
+
+ public void setRestApiMapping(String restApiMapping) {
+ this.restApiMapping = restApiMapping;
+ }
+
+ public String getRestApiServletName() {
+ return restApiServletName;
+ }
+
+ public void setRestApiServletName(String restApiServletName) {
+ this.restApiServletName = restApiServletName;
+ }
+
+ private String restApiServletName = "activitiRestApi";
+
+ private boolean jpaEnabled = true; // true by default
public boolean isCheckProcessDefinitions() {
return checkProcessDefinitions;
@@ -73,11 +109,4 @@ public class ActivitiProperties {
this.processDefinitionLocationSuffix = processDefinitionLocationSuffix;
}
- public boolean isJpa() {
- return jpa;
- }
-
- public void setJpa(boolean jpa) {
- this.jpa = jpa;
- }
}
diff --git a/modules/activiti-spring-boot/src/main/java/org/activiti/spring/boot/ProcessEngineAutoConfiguration.java b/modules/activiti-spring-boot/src/main/java/org/activiti/spring/boot/ProcessEngineAutoConfiguration.java
index b760d3d61e0243e9da467438825f5bf758200b0a..69202890c46989429710672d9ee373486abbfd5e 100644
--- a/modules/activiti-spring-boot/src/main/java/org/activiti/spring/boot/ProcessEngineAutoConfiguration.java
+++ b/modules/activiti-spring-boot/src/main/java/org/activiti/spring/boot/ProcessEngineAutoConfiguration.java
@@ -16,18 +16,22 @@
package org.activiti.spring.boot;
import org.activiti.engine.*;
+import org.activiti.rest.service.application.ActivitiRestServicesApplication;
import org.activiti.spring.ProcessEngineFactoryBean;
import org.activiti.spring.SpringJobExecutor;
import org.activiti.spring.SpringProcessEngineConfiguration;
+import org.restlet.ext.servlet.ServerServlet;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.*;
+import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourcePatternResolver;
+import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.util.StringUtils;
@@ -159,13 +163,44 @@ public class ProcessEngineAutoConfiguration {
return super.identityServiceBean(processEngine);
}
+ @Bean
+ @ConditionalOnMissingBean
+ public PlatformTransactionManager transactionManager(DataSource dataSource) {
+ return new DataSourceTransactionManager(dataSource);
+ }
+
+ @Bean
+ @ConditionalOnMissingBean
+ public TaskExecutor taskExecutor() {
+ return new SimpleAsyncTaskExecutor();
+ }
+
}
+ @ConditionalOnExpression("${spring.activiti.restApiEnabled:true}")
+ @Configuration
+ @ConditionalOnClass({ActivitiRestServicesApplication.class,
+ ServletRegistrationBean.class, ServerServlet.class})
+ public static class RestServiceAutoConfiguration {
+
+ @Autowired
+ private ActivitiProperties activitiProperties;
-/*
+ @Bean
+ public ServletRegistrationBean activitiRestRegistration() {
+ ServerServlet servlet = new ServerServlet();
+ ServletRegistrationBean registration = new ServletRegistrationBean(servlet,
+ this.activitiProperties.getRestApiMapping());
+ registration.addInitParameter("org.restlet.application", "org.activiti.rest.service.application.ActivitiRestServicesApplication");
+ registration.setName(this.activitiProperties.getRestApiServletName());
+
+ return null;
+ }
+ }
+/*
@Configuration
@ConditionalOnClass({EntityManagerFactory.class})
public static class JpaAutoConfiguration {
@@ -191,209 +226,6 @@ public class ProcessEngineAutoConfiguration {
};
}
- }
-
- */
-/**
- * This installs the Activiti REST endpoints. The REST endpoints can be used to
- * query the running workflow engine.
- *//*
-
- @Configuration
- @ConditionalOnClass({ServletRegistrationBean.class, ServerServlet.class})
- public static class RestServiceAutoConfiguration {
-
- @Bean
- ServletRegistrationBean activitiRestRegistration(
- @Value("${spring.activiti.rest.mapping:activiti-rest}") String name,
- @Value("${spring.activiti.rest.mapping:'/activiti*/
-/*'}") String mapping) {
- ServerServlet servlet = new ServerServlet();
- ServletRegistrationBean registration = new ServletRegistrationBean(servlet, mapping);
- registration.addInitParameter("org.restlet.application", "org.activiti.rest.service.application.ActivitiRestServicesApplication");
- registration.setName(name);
-
- return registration;
- }
- }
-*/
-
+ }*/
}
-
-/*
-
-
-@Configuration
-class ActivitiConfiguration {
-
- @Autowired(required = false)
- private List executors;
-
- @Autowired(required = false)
- private List activitiConfigurers;
-
- @Autowired(required = false)
- private Map dataSources;
-
- @Autowired(required = false)
- private List platformTransactionManagers;
-
- @Autowired(required = false)
- private List springJobExecutors;
-
- @Bean
- public SpringProcessEngineConfiguration springProcessEngineConfiguration(
-
- ) {
- ActivitiConfigurer configurer = activitiConfigurer(activitiConfigurers);
- List processDefinitionResources = new ArrayList();
- configurer.processDefinitionResources(processDefinitionResources);
- SpringProcessEngineConfiguration engine = new SpringProcessEngineConfiguration();
- if (!processDefinitionResources.isEmpty()) {
- engine.setDeploymentResources(processDefinitionResources
- .toArray(new Resource[processDefinitionResources.size()]));
- }
- DataSource dataSource = dataSource(configurer, dataSources);
- engine.setDataSource(dataSource);
- engine.setTransactionManager(platformTransactionManager(dataSource));
- engine.setJobExecutor(springJobExecutor());
- engine.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
- configurer.postProcessSpringProcessEngineConfiguration(engine);
- return engine;
- }
-
- @Bean
- public ProcessEngineFactoryBean processEngine(SpringProcessEngineConfiguration springProcessEngineConfiguration) {
- ProcessEngineFactoryBean processEngineFactoryBean = new ProcessEngineFactoryBean();
- processEngineFactoryBean.setProcessEngineConfiguration(springProcessEngineConfiguration);
- return processEngineFactoryBean;
- }
-
- @Bean
- public RuntimeService runtimeService(ProcessEngine processEngine) {
- return processEngine.getRuntimeService();
- }
-
- @Bean
- public RepositoryService repositoryService(ProcessEngine processEngine) {
- return processEngine.getRepositoryService();
- }
-
- @Bean
- public TaskService taskService(ProcessEngine processEngine) {
- return processEngine.getTaskService();
- }
-
- @Bean
- public HistoryService historyService(ProcessEngine processEngine) {
- return processEngine.getHistoryService();
- }
-
- @Bean
- public ManagementService managementService(ProcessEngine processEngine) {
- return processEngine.getManagementService();
- }
-
- @Bean
- public FormService formService(ProcessEngine processEngine) {
- return processEngine.getFormService();
- }
-
- @Bean
- public IdentityService identityService(ProcessEngine processEngine) {
- return processEngine.getIdentityService();
- }
-
- */
-/*
- * @Bean public static ProcessScopeBeanFactoryPostProcessor processScope() {
- * return new ProcessScopeBeanFactoryPostProcessor(); }
- *
- * @Bean public SharedProcessInstanceFactoryBean
- * processInstanceFactoryBean(SharedProcessInstanceHolder
- * sharedProcessInstanceHolder) { return new
- * SharedProcessInstanceFactoryBean(sharedProcessInstanceHolder); }
- *
- * @Bean public SharedProcessInstanceHolder processScopeContextHolder() {
- * return new SharedProcessInstanceHolder(); }
- *//*
-
-
-*/
-/* protected PlatformTransactionManager platformTransactionManager(final DataSource dataSource) {
- return first(this.platformTransactionManagers,
- new ObjectFactory() {
- @Override
- public PlatformTransactionManager getObject() throws BeansException {
- return new DataSourceTransactionManager(dataSource);
- }
- });
- }*//*
-
-
- protected SpringJobExecutor springJobExecutor() {
- return first(this.springJobExecutors,
- new ObjectFactory() {
- @Override
- public SpringJobExecutor getObject() throws BeansException {
- TaskExecutor taskExecutor = first(executors,
- new ObjectFactory() {
- @Override
- public TaskExecutor getObject() throws BeansException {
- return new SyncTaskExecutor();
- }
- });
- return new SpringJobExecutor(taskExecutor);
- }
- });
- }
-
- protected ActivitiConfigurer activitiConfigurer(final List activitiConfigurers) {
-
- return new ActivitiConfigurer() {
- @Override
- public void processDefinitionResources(List resourceList) {
- List resources = new ArrayList();
-
- // lets first see if any exist in the default place:
- Resource defaultClassPathResourceMatcher = new ClassPathResource("classpath:/processes*/
-/**bpmn20.xml");
-
- if (defaultClassPathResourceMatcher.exists()) {
- resources.add(defaultClassPathResourceMatcher);
- }
-
- if (activitiConfigurers != null && !activitiConfigurers.isEmpty()) {
- for (ActivitiConfigurer ac : activitiConfigurers) {
- ac.processDefinitionResources(resources);
- }
- }
-
- resourceList.addAll(resources);
- }
-
- @Override public void postProcessSpringProcessEngineConfiguration(SpringProcessEngineConfiguration springProcessEngineConfiguration) {
- if (activitiConfigurers != null) {
- for (ActivitiConfigurer configurer : activitiConfigurers) {
- configurer.postProcessSpringProcessEngineConfiguration(springProcessEngineConfiguration);
- }
- }
- }
-
-
- };
- }
-
-
- private static T first(List tList, ObjectFactory tObjectFactory) {
- T rt;
- if (tList != null && !tList.isEmpty()) {
- rt = tList.iterator().next();
- } else {
- rt = tObjectFactory.getObject();
- }
- return rt;
- }
- }
- */
diff --git a/modules/activiti-spring-boot/src/test/java/org/activiti/spring/boot/TestAutoConfiguration.java b/modules/activiti-spring-boot/src/test/java/org/activiti/spring/boot/TestProcessEngineAutoConfiguration.java
similarity index 80%
rename from modules/activiti-spring-boot/src/test/java/org/activiti/spring/boot/TestAutoConfiguration.java
rename to modules/activiti-spring-boot/src/test/java/org/activiti/spring/boot/TestProcessEngineAutoConfiguration.java
index a658693d81fca1b9d06c4a5c4cb8684023589a34..0fcc0ec547eb6719dbf063b20c3c05e414956547 100644
--- a/modules/activiti-spring-boot/src/test/java/org/activiti/spring/boot/TestAutoConfiguration.java
+++ b/modules/activiti-spring-boot/src/test/java/org/activiti/spring/boot/TestProcessEngineAutoConfiguration.java
@@ -4,11 +4,12 @@ import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.ProcessDefinition;
import org.apache.commons.dbcp.BasicDataSource;
+import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -20,7 +21,9 @@ import org.springframework.transaction.PlatformTransactionManager;
import javax.sql.DataSource;
import java.util.List;
-public class TestAutoConfiguration {
+public class TestProcessEngineAutoConfiguration {
+
+ private ConfigurableApplicationContext applicationContext;
@Configuration
@EnableAutoConfiguration
@@ -48,20 +51,31 @@ public class TestAutoConfiguration {
}
}
-
@Test
public void testProcessEngine() throws Exception {
ProcessEngine processEngine = applicationContext.getBean(ProcessEngine.class);
Assert.assertNotNull("the processEngine should not be null!", processEngine);
}
- private ConfigurableApplicationContext applicationContext;
+ @After
+ public void close() {
+ this.applicationContext.close();
+ }
+ @Test
+ public void testRunsWithRestApis() {
+ System.setProperty("spring.activiti.restApiEnabled", "true");
+ this.applicationContext = SpringApplication.run(SimpleDataSourceConfiguration.class);
+ // do RestTemplate or something
+ }
+ @Test
+ public void testRunsWithoutRestApis() {
+ System.setProperty("spring.activiti.restApiEnabled", "false");
+ this.applicationContext = SpringApplication.run(SimpleDataSourceConfiguration.class);
+ }
@Before
public void setUp() {
- this.applicationContext = new SpringApplicationBuilder(SimpleDataSourceConfiguration.class)
- .web(false)
- .run();
+
}
@Test
@@ -77,6 +91,4 @@ public class TestAutoConfiguration {
ProcessDefinition processDefinition = processDefinitionList.iterator().next();
Assert.assertEquals(processDefinition.getKey(), "waiter");
}
-
-
}
diff --git a/modules/activiti-spring-boot/src/test/resources/application.properties b/modules/activiti-spring-boot/src/test/resources/application.properties
index ea805461f363f44b8d7023bf6e635c6102fabf17..f9e6d04af04a24a76ada2a510ab9224201bf7c8b 100644
--- a/modules/activiti-spring-boot/src/test/resources/application.properties
+++ b/modules/activiti-spring-boot/src/test/resources/application.properties
@@ -1 +1,2 @@
-debug : false
+debug true
+spring.activiti.restApiEnabled false