could not find work item handler for Database
kojot Sep 11, 2014 4:16 AMHello, sorry for my english.
I want create service task, which will sent data to database, and download data.
I use kie workbench and jbpm 6.
I created service task in WorkDefinition:
[
"name" : "Database",
"parameters" : [
"select" : new StringDataType(),
"host" : new StringDataType(),
"port" : new StringDataType(),
"dbname" : new StringDataType(),
"user" : new StringDataType(),
"pass" : new StringDataType(),
],
"displayName" : "Database",
"icon" : "defaultemailicon.gif"
],
Then, I created java file in src/main/java/com/sample/DatabaseWorkItemHandler.java
1. | | | package com.sample; |
2. | | | |
3. | | | import org.jboss.solder.logging.Logger; |
4. | | | import org.kie.api.runtime.process.WorkItem; |
5. | | | import org.kie.api.runtime.process.WorkItemHandler; |
6. | | | import org.kie.api.runtime.process.WorkItemManager; |
7. | | | |
8. | | | import java.sql.*; |
9. | | | import java.util.Map; |
10. | | | |
11. | | | public class DatabaseWorkItemHandler implements WorkItemHandler { |
12. | | | |
13. | | | public void executeWorkItem(WorkItem workItem, WorkItemManager manager) { |
14. | | | |
15. | | | try { |
16. | | | // extract parameters |
17. | | | String select = (String) workItem.getParameter("select"); |
18. | | | String host = (String) workItem.getParameter("host"); |
19. | | | String port = (String) workItem.getParameter("port"); |
20. | | | String dbname = (String) workItem.getParameter("dbname"); |
21. | | | String user = (String) workItem.getParameter("user"); |
22. | | | String pass = (String) workItem.getParameter("pass"); |
23. | | | |
24. | | | String url = "jdbc:postgresql://" + host + ":" + port + "/" |
25. | | | + dbname; |
26. | | | Class.forName("org.postgresql.Driver"); |
27. | | | Connection db = DriverManager.getConnection(url, user, pass); |
28. | | | Statement stmt = db.createStatement(); |
29. | | | |
30. | | | ResultSet rs = stmt.executeQuery(select); |
31. | | | int count = rs.getMetaData().getColumnCount(); |
32. | | | Map res = workItem.getResults(); |
33. | | | res.put("columnCount", count); |
34. | | | while (rs.next()) { |
35. | | | for (int i = 0; i < count; i++) { |
36. | | | Object ob = rs.getObject(i); |
37. | | | res.put("column_" + i, ob.toString()); |
38. | | | } |
39. | | | } |
40. | | | |
41. | | | // notify manager that work item has been completed |
42. | | | manager.completeWorkItem(workItem.getId(), null); |
43. | | | } catch (Exception ex) { |
44. | | | Logger.getLogger(this.getClass().getName()).error( |
45. | | | "Cos jest nie tak", ex); |
46. | | | } |
47. | | | } |
48. | | | |
49. | | | public void abortWorkItem(WorkItem workItem, WorkItemManager manager) { |
50. | | | |
51. | | | // Do nothing, notifications cannot be aborted |
52. | | | |
53. | | | } |
54. | | | |
55. | | | } |
When I click play in "Process Definitions", i have got statement "could not find work item handler for Database"