Time for action – implementing the REST service

To access Activiti as a REST service, we need to perform some configurations in our Tomcat server. Now, we will take a look at these configurations. Perform the following steps to implement the REST services:

  1. As we want to access the REST services of Activiti, we will deploy the activiti-rest.war file in the apache-tomcat web server. Copy the activiti-rest.war file and paste it to the webapps folder that can be found at apache-tomcat ../apache-tomcat-7.0.37/webapps, as shown in the following screenshot:
    Time for action – implementing the REST service
  2. If your Tomcat server is already running, the activiti-rest.war file will be deployed automatically. If Tomcat is not running, start your Tomcat server; then, your activiti-rest.war file will be deployed and you will be able to find the deployed folder (activiti-rest) in apache-tomcat's webapps folder (apache-tomcat ../apache-tomcat-7.0.3/webapps), as shown in the following screenshot:
    Time for action – implementing the REST service
  3. After the successful deployment of the activiti-rest file, we need to connect the activiti-rest file to the database that we had configured in Chapter 4, Management and Monitoring Using the Activiti Explorer. Browse to the classes folder of activiti-rest (../apache-tomcat-7.0.37/webapps/activiti-rest/WEB-INF/classes) and edit the db.properties file shown in the following screenshot:
    Time for action – implementing the REST service
  4. By default, the db.properties file will be connected to the H2 database; we need to change it to mysql (which we have configured in Chapter 4, Management and Monitoring, using the Activiti Explorer), as shown in the following code:
    db=mysql
    jdbc.driver=com.mysql.jdbc.Driver
    jdbc.url=jdbc:mysql://localhost:3306/activiti
    jdbc.username=root
    jdbc.password=root
  5. After executing all the preceding configurations, you need to restart your web server so that the changes are applied.
  6. To check whether or not the REST service can be accessed, you need to add the RESTClient plugin to your browser.
  7. To install RESTClient in the Firefox browser, we need to download it from the URL https://addons.mozilla.org/en-US/firefox/addon/restclient/. This URL will take you to the page shown in the following screenshot:
    Time for action – implementing the REST service
  8. Once you have successfully installed the plugin, the REST icon will be displayed on the toolbar as shown in the following screenshot; you can open the RESTClient by clicking on this icon:
    Time for action – implementing the REST service
  9. On opening the RESTClient, the following screenshot will appear; we then need to perform the authentication to be able to access the REST services of the Activiti Engine. Navigate to Authentication | Basic Authentication, as shown in the following screenshot:
    Time for action – implementing the REST service
  10. A Basic Authorization window will pop up, where we need to specify the username and password. Enter kermit in the Username and Password fields for authentication, as shown in the following screenshot:
    Time for action – implementing the REST service
  11. On successful authentication, you can access the REST API of the Activiti Engine. For testing, you can provide the URL http://localhost:8080/activiti-rest/service/deployments in the URL field in the RESTClient window and the Method field should be set to GET. On executing this, you should get the output in the Response Headers section, as shown in the following screenshot:
    Time for action – implementing the REST service

Note

Before execution, the Tomcat server in which you have deployed the activiti-rest.war file should be running; otherwise, you won't be able to see the output.

What just happened?

We just went through how to configure activiti-rest and access the Activiti Process Engine by performing REST calls using RESTClient.

Working with REST API services

As we have configured the RESTClient in the browser, we will now start accessing the REST API using RESTClient.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset