cancel
Showing results for 
Search instead for 
Did you mean: 

activiti-rest & -explorer sharing process engine? (v5.7)

f3lix
Champ in-the-making
Champ in-the-making
Hello,

in the previous versions of Activiti (<= 5.6) my understanding was that there was one instance of a process engine that was shared using the REST interface; activiti-probe and activiti-explorer would use the REST interface to manipulate the state of the process engine.

Now, in Activity 5.7 it seems to me that both, activiti-rest AND activiti-explorer, have an instance of the process engine running and they share there state via the DB. Is this correct? If yes, I have a feeling that this would cause problem. But my understanding of the inner workings of Activiti are unfortunately still very limited …

BTW, is there something like an architecture diagram of Activiti that would show such interdependencies/relations of modules?

Regards,
Felix
20 REPLIES 20

ndup0nt
Champ in-the-making
Champ in-the-making
Also the dispatcher servlet for both webapps is mapped on /service/*

So you have to merge the Spring config as well. Also we can't assume there won't be any URL conflict, can we ?

jbarrez
Star Contributor
Star Contributor
Yes, there wont be a conflict.

ays
Champ in-the-making
Champ in-the-making
Hello,

Did anyone managed to produce combined webapp based on 5.17?
After adding of libs and classes from rest webapp into explorer and adding WebConfigurer filter into explorer web.xml I got NullPointerException (see below).
I don't have experience with the Spring, but I guess that it is related to Spring content initialization. Any hints? *help*
<code>
Mar 18, 2015 12:42:47 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.activiti.rest.servlet.WebConfigurer
java.lang.NullPointerException
        at org.activiti.rest.servlet.WebConfigurer.initSpring(WebConfigurer.java:71)
        at org.activiti.rest.servlet.WebConfigurer.contextInitialized(WebConfigurer.java:54)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)
        at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1247)
        at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1898)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
</code>

jbarrez
Star Contributor
Star Contributor
I think the problem is that you now have multiple WebConfigurer classes in the web.xml, right? I dont believe that will work.

To make a combination, you would need to create a new webapp yourself, and combine the Webconfigurer for both endpoints. But i dont think that has been done before.

ays
Champ in-the-making
Champ in-the-making
Joram, thank you very much for this comment! It really helped to merge two apps Smiley Happy
Will be playing with the result during the next few days. Hopefully the thing will not only start but also work as expected (quick tests shown no issues with explorer part).
Thank you so much for what you are doing!

ays
Champ in-the-making
Champ in-the-making
Just to confirm that the result acheived. For those who would attempt to merge explorer and rest 5.17:
* get sources for classes from WEB-INF/classes/org
* merge them one by one. I created a different package, then copied there explorer part and then added parts from rest which was missing.
* you can skip Demo related classes
* Change web.xml, make sure that it references new classes
* Merge WEB-INF/lib
* replace WEB-INF/classes with the newly created

This should do the job. Good luck to all of you!

jbarrez
Star Contributor
Star Contributor
Thanks for posting this back. i'm sure this will be helpful to a lot of people!

andrealuciano71
Champ in-the-making
Champ in-the-making
Hi, I've just added activiti-rest API to activiti-explorer.

The merger is not so complex, but it heavily depends on the sources which have been changing throughout the different actitviti releases.
The question of merging rest and esplorer has been resumed different times in the forum, in my opinion it should be considered the opportunity of including the activiti-rest API in the next releases of activiti-explorer.

In a nutshell, what I did to add the API to  release 5.17 was:

- copying the following jars from activiti-rest's WEB-INF/lib to activiti-explorer:

      activiti-rest-5.17.0.jar
      commons-fileupload-1.2.2.jar
      jsr250-api-1.0.jar

- downloading the source of activiti-webapp-explorer2 and activiti-webapp-rest2 from:

       http://repo1.maven.org/maven2/org/activiti/activiti-webapp-explorer2/
       http://repo1.maven.org/maven2/org/activiti/activiti-webapp-rest2/

- Copying from activiti-webapp-rest2 the files below and just changing the package to org.activiti.explorer.conf:

    RestConfiguration.java
    SecurityConfiguration .java   

- Then the modification regarding Spring MVC dispatcher to apply to activiti-webapp-explorer2 to inject the rest api:
   
   One solution was to append "org.activiti.rest.exception" and "org.activiti.rest.service.api" to the ComponentScan annotation arguments in the class DispatcherServletConfiguration.java:
<code>
   @ComponentScan({"org.activiti.rest.editor", "org.activiti.rest.diagram", "org.activiti.rest.exception", "org.activiti.rest.service.api"})
</code>

   with the negative side effect that anyone could invoke the API without being authenticated, because /activiti-explorer/service is not protected.

   The second possibility was to create a subcontext of "/service", let's say "/service/api", protected by the basic authentication (actually if the  authentication is enabled on /service the diagram-viewer ceases to work), and configure the rest API with this context:

   So I copied DispatcherServletConfiguration.java from activiti-webapp-rest2 to activiti-webapp-explorer2 as DispatcherServletAPIConfiguration.java and then I modified WebConfigurer.java:

<code>
public void contextInitialized(ServletContextEvent sce) {
    …
    initSpring(servletContext, rootContext);
    initSpringAPI(servletContext, rootContext);
   
    EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC);
    initSpringSecurity(servletContext, disps);

    log.debug("Web application fully configured");
  }
….
/**
* Initializes Spring and Spring MVC for /service/api context (activiti-rest services)
*/
private ServletRegistration.Dynamic initSpringAPI(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    /** ADD /api dispatcher */
    log.debug("Configuring Spring Web application context (activiti-rest API)");
    AnnotationConfigWebApplicationContext dispatcherServletAPIConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletAPIConfiguration.setParent(rootContext);
    dispatcherServletAPIConfiguration.register(DispatcherServletAPIConfiguration.class);

    log.debug("Registering Spring MVC Servlet (activiti-rest API)");
    ServletRegistration.Dynamic dispatcherAPIServlet = servletContext.addServlet("dispatcher-rest", new DispatcherServlet(dispatcherServletAPIConfiguration));
    dispatcherAPIServlet.addMapping("/service/api/*");
    dispatcherAPIServlet.setLoadOnStartup(1);
    dispatcherAPIServlet.setAsyncSupported(true);
   
    return dispatcherAPIServlet;
  }

  /**
   * Initializes Spring Security for /service/api context (activiti-rest services)
   */
  private void initSpringSecurity(ServletContext servletContext, EnumSet<DispatcherType> disps) {
    log.debug("Registering Spring Security Filter");
    FilterRegistration.Dynamic springSecurityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());

    springSecurityFilter.addMappingForUrlPatterns(disps, false, "/service/api/*");
    springSecurityFilter.setAsyncSupported(true);
  }
  …
</code>

  To finish, compile the modified activiti-webapp-explorer2 and copy the classes to activiti-explorer/WEB-INF/classes.

  The API are accessible asking for authentication at "/activiti-explorer/service/api", such as in this example :

   http://localhost:8080/activiti-explorer/service/api/repository/process-definitions

  It would be also possible to configure a prefix different from "/activti-explorer/service" but this means impacts on the activiti-explorer's org.activiti.explorer.filter.ExplorerFilter class which contains the context exceptions to the default activiti explorer authentication based on form (ignoreList variable).
  
   Bye.

   Andrea

vasile_dirla
Star Contributor
Star Contributor
Hi,
Thank you Andrea for your contribution to this forum.

srini_n
Champ in-the-making
Champ in-the-making
Hi,

I am new to Activiti and would like to understand this topic better to make an informed decision.

1. What are the benefits of merging Activiti-REST and Activiti-Explorer? Why do we need a single Activiti-Engine instance? If the 2 engine instances share state via DB what are the benefits of combining them? The flip side of merging them is that upgrades will get complicated and will require manual work that is error prone.
2. My understanding is that Activiti-Engine embedded within the application is preferable because of transaction management. Using REST will create a Transactions boundary where one may not be able to guarantee data integrity.

Appreciate any inputs on the above 2 points.

Thanks,
srini