Saturday, December 17, 2016

Activiti 5.22 Introduction and Installation

Tuesday, April 26, 2016

Activiti BPMN Configure Oracle Database

I use version 5.19 of Activiti BPMN Engine.

Activiti comes with an in-memory H2 database. Which is not useful for any serious development or for Production Purposes. So i installed an Oracle 12c on my local computer for educational purposes and Configured Activiti to start pointing to that Database.

here's what you need to do to configure Oracle database for Activiti 5.19

I Assume you copied activiti war's into your Tomcat webapps folder. Once you have copied the wars will explode into a folder. I have copied both the activiti-explorer.war and activiti-rest.war to my tomcat8\webapps folder and started up tomcat.

After this you can go to tomcat8\webapps\activiti-explorer\WEB-INF\classes and you find a file called db.properties there. You can delete the contents of this file and replace it with

db = oracle
jdbc.driver = oracle.jdbc.OracleDriver
jdbc.url = jdbc:oracle:thin:@localhost:1521:SUNIL
jdbc.username = user
jdbc.password = password

and update your DB details in this.

You also need to add your ojdbc.jar to this lib folder here - tomcat8\webapps\activiti-explorer\WEB-INF\lib

You need to follow same steps for activiti-rest also.

If you are configuring Activiti into this Oracle DB, then you need to run some scripts to create your tables and other DDL in Oracle.

For this you can log into your Oracle user and run the script from your actual Activiti download folder. \activiti-5.19.0.2\database\create
For Oracle you need to execute the below .sql files in your oracle user.

activiti.oracle.create.engine.sql
activiti.oracle.create.history.sql
activiti.oracle.create.identity.sql

Now you can login to http://localhost:8090/activiti-explorer/ to log in and you database will be connecting to Oracle.

Thanks
SunilTK



Friday, January 9, 2015

Custom CORS filter in java

Implement CORS Filter in Java.
When you want to make a Cross Domain Call from angular.js to a Jboss (or Any server). You can write a simple servlet filter to achieve this.
Add a new Servlet like below
package com.rest.cors;
public class CorsFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Credentials", "true");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, HEAD, OPTIONS");
        response.setHeader("Access-Control-Allow-Headers", "Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers");
        filterChain.doFilter(servletRequest, servletResponse);
    }
    @Override
    public void destroy() {
    }
}

Add a Filter entry in the web.xml of your war file
    <filter>
        <filter-name>cors</filter-name>
        <filter-class>com.rest.cors.CorsFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>cors</filter-name>
        <url-pattern>* /*</url-pattern>
    </filter-mapping>

This will ensure that CORS Filter applied to all, REST APIs and Servlets’.

Available headers are,
Access-Control-Allow-Origin – you can set the originating domain info here
Access-Control-Allow-Credentials – set to true by default
Access-Control-Expose-Headers
Access-Control-Max-Age
Access-Control-Allow-Methods
Access-Control-Allow-Headers


If you intend to use xml/json in content-type, please make sure you allow OPTION as in the above sample.