|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
Edgar Silva's Blog
Creating a Process Server based on OpenSource Technologies using RESTPosted by edgars on August 04, 2008 at 06:01 PM | Permalink | Comments (0)This is a post where I will try share some thoughts about where REST could be useful inside a SOA architecture using Business Process Management, in that case we will be using jBPM and RESTEasy, which is the JBoss's implementation for JSR311 - Java Restful WebServices. RESTEasyRestEasy is a project that is getting a good relevance in terms of integration with some projects inside JBoss.ORG and even other projects. If you are trying use a simple REST implementation you should take a look on this projects, basically there are few steps you must to do to put RestEasy working for your Application, so see the following Steps:
Custom configurationRESTeasy is implemented as a ServletContextListener? and a Servlet and deployed within a WAR file. If you open up the WEB-INF/web.xml in your RESTeasy download you will see this: <web-app>
<display-name>Archetype Created Web Application</display-name>
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<listener>
<listener-class>org.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<servlet>
<servlet-name>Resteasy</servlet-name>
<servlet-class>org.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>The ResteasyBootstrap listener is responsible for initializing some basic components of RESTeasy as well as scanning for annotation classes you have in your WAR file. It receives configuration options from <context-param> elements. Here's a list of what options are available
Proof of Concept of a “Process Server”We have several open source BPM Engines , I am using JBoss jBPM because I wanna show you a Web-Console where the process are running on, in addition a graphical tool to design my processes. First of all I have a really simple “Controller” based on REST principles, nothing too complex or beautiful so far, but is useful, so I created a simple class called RestService.java where you can find many useful methods to operate business process using jBPM. Based on my own experience could be considered a “best practice” you design your URLs first, who knows some day we could create a tool (ant or maven), that could based on a text file containing one URL per line, where after reading it could create an abstract class with the methods. (Maybe a good way to forget any XML). Based on this practice I wanna give the ability for PHP, .net or even HTML interact with my “Process Server”, to do that I can have the following URLs:
Based on these 4 actions I defined above, I can show you now how implement them: 1- Start a new Process Instance
@GET @Path("/start/process/{processdefinition}/{user}") @ProduceMime("text/plain") public String startProcesInstance( @PathParam("processdefinition")String processDefintion, @PathParam("user")String user) { JbpmContext ctx = JbpmConfiguration.getInstance().createJbpmContext(); try { ProcessInstance instance = ctx.newProcessInstance(processDefintion); instance.getContextInstance().setVariable("user", user); Token t = instance.getRootToken(); t.signal(); ctx.save(instance);
return new Long(instance.getId()).toString(); } catch (Exception e) { e.printStackTrace(); } finally { ctx.close(); } return "ERROR";
} 2 - Signaling your ProcessOnce you have your Process Id, you can operate it and do whatever you want, this is one of the “Key-benefits” in jBPM, the ability to keep everything related to the process stored in the database, and not in the memory, it allow you have several application interacting with your Process Engine, for my testing, I have jBPM Server (jBPM+JBoss [could be any other AppServer]) in one IP address, and a TomCat with my simple REST application based in RESTEasy. Keep in mind, that having your process stored in regular tables in many Databases supported by Java, you shall create many kinds of applications, you may use Hibernate for persistence, query and cache as well as JDBC or even Spring helpers. See the following source code to allow this action: @GET @Path("/signal/process/{id}/{user}") @ProduceMime("text/plain") public String signalProcess( @PathParam("id")String id, @PathParam("user")String user) { JbpmContext ctx = JbpmConfiguration.getInstance().createJbpmContext();
try{ GraphSession graphSession = ctx.getGraphSession(); ProcessInstance processInstance = graphSession.loadProcessInstance((new Long(id)).longValue());
processInstance.signal();
ctx.save(processInstance);
return processInstance.getRootToken().getNode().getName();
} catch (Exception e ) { e.printStackTrace(); return "ERROR"; } finally { ctx.close(); } }
3 – Adding variables to your processes via a simple URL
@GET @Path("/process/{id}/add/var") @ProduceMime("text/plain") public String addVariables( @PathParam("id")String id, @Context HttpServletRequest request) { JbpmContext ctx = JbpmConfiguration.getInstance().createJbpmContext();
try{ GraphSession graphSession = ctx.getGraphSession(); ProcessInstance processInstance = graphSession.loadProcessInstance((new Long(id)).longValue());
Enumeration params = request.getParameterNames(); String param; StringBuilder b = new StringBuilder(); while (params.hasMoreElements()) {
param = (String) params.nextElement(); processInstance.getContextInstance().setVariable(param, request.getParameter(param)); b.append(String.format("Param:%s=%s is Stored in BPM Context\n",param,request.getParameter(param))); }
ctx.save(processInstance);
return b.toString();
} catch (Exception e ) { e.printStackTrace(); return "ERROR"; } finally { ctx.close(); } } Time for TestingAs far you can see, everything on our example just returns basic “plain texts” as results, so we can use those everywhere, in The Developers Conference (A Brazilian Java Conference) I did an examples really “old school”, I used a Borland Delphi 5 client, in terms of integration, I can get an existing Delphi or Visual Basic Application and integrate them with my “Process Server”, than for our Proof of Concept. My process for testing is really easy, as far you can see in the following image:
This is a simple “Buying Process”, where could be used for many different scenarios, on our case, we try simulate a simple Delphi client interacting with this process. On Delphi's side, I need just a component to interact with HTTP requests and nothing else, so in my case I used TidHTTP object for it. My Process Server in ActionWhen we execute the following URL: http://192.168.161.1:8080/flowlet/start/process/buyticket/edgar , we are informing the process name: buyticket and the user ir edgar , and the result we can expect is a text with process id as the text returned via Http, see the following image:
After execute our method, the process instance id is 124, this id might be used for this process interaction, at this moment, my application is used a process which was deployed in my Process Server, and then we can create a new instance from the process called buyticket , so everything is stored in the database, and we can create any kind of information based on database tables about our process instances, such as: “Execution time”, “Troubleshooting” and so on. Now, it's time to see our JBoss jBPM Console in action, take a look on my process listing and you can see the process instance id: 124
And you can see where in the process, you process instance actually is stopped:
Now, it's time to navigate through the process instance, so I will execute the following rest URL: http://192.168.161.1:8080/flowlet/signal/process/124/edgar , the result are the following screen shots:
This method, basically execute the signal into the process instance, and move the process to the next node, as far you can in the result and in the following image in the jBPM Console:
Adding the variables based on HttpServletRequest shall be executed using the following URL: http://192.168.161.1:8080/flowlet/process/124/add/var?payment=Yes&blog=Edgar , so based on the Java Web technologies, you can assume that you have 2 variables: payment and blog, so what we wanna do now is to transfer these variables from http context, which are durable just while the server is running or some clustering replication in really durable information stored in the database as process variables. In addition to this capacity, imagine that we need some variable to define some execution path in the process instance handling, like a decision handler based on some expression(EL) based on some variable, for instance: expression='#{payment=="No"}'; this expression can decide in the decision-node “Is Payment Approved?” which path(direction) the process will go as the next execution node and transitions. See the results in the following images:
Now, we can signal the process again, and the results in our jBPM Server could be as the following :
ConclusionBasically, as far you can see Process Server is something beyond a product, can be a concept that you can apply in many different ways, and one of that, for sure could be using Open-Source technologies, such as we had shown here on this entry.
Some thoughts about opensource BPMsPosted by edgars on June 23, 2008 at 01:44 PM | Permalink | Comments (0)Business Processing Modeling – BPM, I was starting my career when I heard the word “Workflow” by the first time, of course I had many other things to learn, instead to pay attention on some thing that seems to be too complicated, however in during any computer science or related course we learn some about “State Machines”, well, I wanna tell you a history that I heard when I worked for one of the biggest federal bank in Brazil: Workflow products had arrived down here in end of 90's, this bank tried implement a Workflow, although instead to map the the activities into a “State Machine Diagram” where would be possible figure out where the process's drawbacks or too long waits came from, they mixed business logic to process logic, obtaining serious performance problems and not too accurate information, the word “workflow” was abolished for a long time on this bank after this first frustrated try. Maybe, such things like that happened in all over the world, that's why during too much time, the concept to try get the company's process and map all of them represented using cool colored diagrams, which internally are not much more than a “State Machine”. The workflow products getting started so to hibernate, and then as a “pheonix” are relaunched but now with a new name: BPM (Business Process Modeling)! Maybe now, many people will stop to read this entry, but sorry, I can't figure out BPM in any other way, but now it is dressed much better, with new terminologies and concepts that make it “hot” or “fashion”. All the text above is just to call your attention for BPM Opensource implementations as an alternative for commercial licensing vendors,as such alternatives I can recommend you the following: OSWorkflow, IntalioBPM and jBPM, actually I respect all of them, but I've been using jBPM most frequently, that's why I will point some about it here. But, I recommend you take a look about the other ones. From this point of this entry, I don't wanna promote any project marketing, in despite of the fact I wanna tell you my particular vision about jBPM as a solution, and based on my professional experience show you where and how you may apply it into your projects. The best way I found to look at jBPM, is that it is a great BPM Engine, and it is not a weakness, I mean: When you think about BPM you can take many scenarios, since from modeling, management, governance and so on. JBPM is a really cool BPM framework and Engine. When you have an Application that has an internal workflow with a complete User Interface or a set of Services to do everything you want without. In other words, imagine you have a HelpDesk System built 10 years ago with OracleForms , and you have mapped a kind of workflow on that, however you never figured out how measure your business activity monitoring(BAM). Now, keep in mind that you can during your regular activities in your system call a procedure to generate a simples text file with some information, which can be used to fill information into a process execution of a jBPM process instance, and from another system you can handle such information to get some report or any other issue. If we are speaking about text file generating, it could be a serious candidate for an ESB listener to process it, well but ESB is out of this scope, but keep ESBs usage in mind. In general, jBPM can be your best option when you want embed a BPM engine into your application, good scenarios contributes for that, such as: JBPM has a native extensible and open language called jPDL, that can process both HumanTasks in addition to invoke WebServices via Java components, it counts with BPEL support as well. In a near future, jBPM will have a PVM(Process Virtual Machine), which basically is “State Machine Framework”, which will render a process independent from the language source, support for BPEL, XPDL using PVM are in the plans of jBPM new versions. A really nice Eclipe plugin where is possible design all process visually, in addition to this, you can use Java components to interact with Node events(node-enter, node-leave for example) or during a transition from a node to another, and everything associating Java objetcs to some specific event during the process execution. The last good reason to use jBPM is the Seam intergration, which make the process management really easy for any developer. For sure, that you may use jBPM as a “BPM Suite” as well, but keep in mind that you will keep Business Analyst designing the process in UML or in some BPMN tool, and you will need a tech-guy to transform this design in to a jpdl diagram, where a Eclipse plugin is available. By the way, when you made an option by use an Opensource engine such as jBPM, you can do that because your plan can be get culture about BPM first, and it is really important for a SOA strategy. No matter if you have many boxes with SOA solutions with you have no idea how use them, and even worst when you already paid for them. Well, if you need more information, you can go to jBPM web site, and download the lastest jbpm-jpdl-suite, which contains the framework and the eclipse plugin all together. Watch the demos, and take a look into documentation. |
August 2008
Search this blog:CategoriesBusinessCommunity Community: Java Enterprise Community: Java Patterns Community: Java Tools Community: Java Web Services and XML Community: JDK Community: NetBeans Community: Portlet Deployment J2EE JSR Open Source Programming Tools Web Services and XML Archives
August 2008 Recent EntriesCreating a Process Server based on OpenSource Technologies using REST Some thoughts about opensource BPMs Using DWR inside a Portlet deployed into JBoss Portal Articlesj1-2k7-mtH01: Open Source Business Opportunities | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
|