cancel
Showing results for 
Search instead for 
Did you mean: 

How to extend Activiti REST now

fisher
Champ in-the-making
Champ in-the-making
There's a great post about extending Activiti REST. http://alfrescoblog.com/2014/05/24/how-to-extend-activiti-rest.  I can follow the post and deploy my own implement. But it's only working before Activiti 5.16.4.

How to extend Activiti REST now. I'm a ROR developer. So I'm not familiar with Spring and Servlet config.  Can you give me some instructions?

thx in advance.
11 REPLIES 11

fisher
Champ in-the-making
Champ in-the-making
The version is 5.17.0.

These my steps:
1. Create a maven project named rest-demo.  <code>pom.xml</code>
<code>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.home</groupId>
  <artifactId>rest-demo</artifactId>
  <version>0.0.1</version>
  <packaging>jar</packaging>

  <name>rest-demo</name>
  <url>http://maven.apache.org</url>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.1.10.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>
</project>

</code>

2. Create <code>Application.java</code>
<java>
package com.home.rest_demo;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.boot.builder.SpringApplicationBuilder;

@ComponentScan
@Configuration
@EnableAutoConfiguration
public class Application extends SpringBootServletInitializer {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
   
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }
}
</java>

3.  Create <code>GreetingController.java</code>
<java>
package com.home.rest_demo;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GreetingController {
    @RequestMapping("/greeting")
    public String greeting(@RequestParam(value="name", defaultValue="World") String name) {
     return "Hello World!";
    }
}
</java>


4. In terminal, <code>mvn spring-boot:run</code>. And then I can visit http://localhost:8090/greeting, where you see:"Hello World!"

5. In terminal, <code>mvn package</code>, I got the rest-demo-0.0.1.jar.

6. The question is how to mount the rest-demo-0.0.1.jar in Activiti REST. I want to access my module like http://localhost:8080/activiti-rest/xxx/greeting

thx in advance.

jbarrez
Star Contributor
Star Contributor
If you are using Spring Boot, you can use the spring-boot-starter-rest-api. it will expose the Activiti rest api on the root (like runtime/process-instances). You could be inspired by the code in that module to bind it to another DispatcherServlet to map to a different context root.

fisher
Champ in-the-making
Champ in-the-making
Thank You for Your Prompt Reply.

I try to add spring-boot-starter-rest-api to the pom.xml. But it failed to running.
<code>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>fisher</groupId>
    <artifactId>extend-activiti-rest</artifactId>
    <version>1.0</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.1.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>spring-boot-starter-rest-api</artifactId>
            <version>5.17.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>
</project>
</code>

<code>
ERROR 28167 — [ost-startStop-1] o.s.b.c.embedded.tomcat.TomcatStarter    : Error starting Tomcat context: org.springframework.beans.factory.BeanCreationException
  WARN 28167 — [lication.main()] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
</code>

I have created a github repo and uploaded my code and the full error log. 
https://github.com/richfisher/extend-activiti-rest/commits/master

fisher
Champ in-the-making
Champ in-the-making
Reference https://github.com/Activiti/Activiti/tree/master/modules/activiti-spring-boot/spring-boot-samples/sp...

1. I set project parent to org.activiti.spring-boot-samples
<code>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>fisher</groupId>
    <artifactId>extend-activiti-rest</artifactId>

    <parent>
        <groupId>org.activiti</groupId>
        <artifactId>spring-boot-samples</artifactId>
        <version>5.17.0</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>spring-boot-starter-rest-api</artifactId>
            <version>5.17.0</version>
        </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.3-1103-jdbc41</version>
    </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
</code>

2. Modified Application.java
<code>
package fisher.extend_activiti_rest;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {
    public static void main(String args[]) {
        SpringApplication.run(Application.class, args);
    }
}
</code>


3. And then add db.properties to src/main/resources. But it seems not working. My postgres datebase has a user kermit. And it's password is kermit.
<code>
db=postgres
jdbc.driver=org.postgresql.Driver
jdbc.url=jdbcSmiley Tongueostgresql://localhost:5432/activiti_development
jdbc.username=postgres
jdbc.password=postgres
</code>

4. 'mvn spring-boot:run'. Visiting 'http://localhost:8090/', where asking username and password. I entered 'kermit','kermit' and got failed.

5. I have updated my code to https://github.com/richfisher/extend-activiti-rest/commits/master

jbarrez
Star Contributor
Star Contributor
> My postgres datebase has a user kermit. And it's password is kermit.

Do you mean the database credentials … or the users table?.

Anyway, you need to configure the users somehow, see for example: https://github.com/jbarrez/activiti-spring-boot-webinar/blob/master/src/main/java/demo/Application.j...

fisher
Champ in-the-making
Champ in-the-making
I mean there's a kermit user in act_id_user table.
The application seems not loading the db.properties.
What should I do?

thx.

jbarrez
Star Contributor
Star Contributor
Your reasoning is wrong. Spring Boot != activiti REST webapp. In Spring Boot you need to set the identity check yourself … and I posted a direct url to a way to do that.

fisher
Champ in-the-making
Champ in-the-making
I finially find out how to configure datasource.

http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-sql.html

<code>application.properties</code>

<code>
spring.datasource.url=jdbcSmiley Tongueostgresql://localhost:5432/activiti_development
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.datasource.driver-class-name=org.postgresql.Driver
</code>

fisher
Champ in-the-making
Champ in-the-making
What about the engine.properites in activiti-rest app. Is it possible to transform them to spring boot properties?

<code>
# demo data properties
create.demo.users=true
create.demo.definitions=false
create.demo.models=false

# engine properties
engine.schema.update=false
engine.activate.jobexecutor=false
engine.asyncexecutor.enabled=true
engine.asyncexecutor.activate=true
engine.history.level=full
</code>