1<!DOCTYPE html> 2<html lang="en"> 3<head> 4 5 <title>How to Create a Custom Work Item Handler in jBPM</title> 6 <meta charset="utf-8" /> 7 <meta http-equiv="X-UA-Compatible" content="IE=edge" /> 8 <meta name="HandheldFriendly" content="True" /> 9 <meta name="viewport" content="width=device-width, initial-scale=1.0" /> 10 11 <link rel="stylesheet" type="text/css" href="https://www.codelikethewind.org/assets/built/screen.css?v=RI3ij5X6ol84wS_v" /> 12 13 <meta name="description" content="Custom Work Item Handlers help us connect to external systems and execute business logic."> 14 <link rel="icon" href="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w256h256/2022/05/cropped-Code-Like-the-Wind-9.png" type="image/png"> 15 <link rel="canonical" href="https://www.codelikethewind.org/2017/10/30/how-to-create-a-custom-work-item-handler-in-jbpm/"> 16 <meta name="referrer" content="no-referrer-when-downgrade"> 17 18 <meta property="og:site_name" content="Code Like the Wind"> 19 <meta property="og:type" content="article"> 20 <meta property="og:title" content="How to Create a Custom Work Item Handler in jBPM"> 21 <meta property="og:description" content="Custom Work Item Handlers help us connect to external systems and execute business logic."> 22 <meta property="og:url" content="https://www.codelikethewind.org/2017/10/30/how-to-create-a-custom-work-item-handler-in-jbpm/"> 23 <meta property="og:image" content="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/wordpress/2017/10/How-to-Create-a-Custom-Work-Item-Handler.png"> 24 <meta property="article:published_time" content="2017-10-30T16:22:09.000Z"> 25 <meta property="article:modified_time" content="2022-05-19T16:31:40.000Z"> 26 <meta property="article:tag" content="BPMS"> 27 <meta property="article:tag" content="businessprocess"> 28 <meta property="article:tag" content="jboss"> 29 <meta property="article:tag" content="jbpm"> 30 31 <meta name="twitter:card" content="summary_large_image"> 32 <meta name="twitter:title" content="How to Create a Custom Work Item Handler in jBPM"> 33 <meta name="twitter:description" content="Custom Work Item Handlers help us connect to external systems and execute business logic."> 34 <meta name="twitter:url" content="https://www.codelikethewind.org/2017/10/30/how-to-create-a-custom-work-item-handler-in-jbpm/"> 35 <meta name="twitter:image" content="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/wordpress/2017/10/How-to-Create-a-Custom-Work-Item-Handler.png"> 36 <meta name="twitter:label1" content="Written by"> 37 <meta name="twitter:data1" content="TiOluwa Olarewaju"> 38 <meta name="twitter:label2" content="Filed under"> 39 <meta name="twitter:data2" content="BPMS, businessprocess, jboss, jbpm"> 40 <meta name="twitter:creator" content="@uncleteeoh"> 41 <meta property="og:image:width" content="560"> 42 <meta property="og:image:height" content="315"> 43 44
44<script type="application/ld+json"> 45{ 46 "@context": "https://schema.org", 47 "@type": "Article", 48 "publisher": { 49 "@type": "Organization", 50 "name": "Code Like the Wind", 51 "url": "https://www.codelikethewind.org/", 52 "logo": { 53 "@type": "ImageObject", 54 "url": "https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w256h256/2022/05/cropped-Code-Like-the-Wind-9.png", 55 "width": 60, 56 "height": 60 57 } 58 }, 59 "author": { 60 "@type": "Person", 61 "name": "TiOluwa Olarewaju", 62 "image": { 63 "@type": "ImageObject", 64 "url": "//www.gravatar.com/avatar/63011705e8e94b703a655521b54f0c59?s=250&d=mm&r=x", 65 "width": 250, 66 "height": 250 67 }, 68 "url": "https://www.codelikethewind.org/author/tioluwa/", 69 "sameAs": [ 70 "https://www.codelikethewind.org", 71 "https://x.com/uncleteeoh" 72 ] 73 }, 74 "headline": "How to Create a Custom Work Item Handler in jBPM", 75 "url": "https://www.codelikethewind.org/2017/10/30/how-to-create-a-custom-work-item-handler-in-jbpm/", 76 "datePublished": "2017-10-30T16:22:09.000Z", 77 "dateModified": "2022-05-19T16:31:40.000Z", 78 "image": { 79 "@type": "ImageObject", 80 "url": "https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/wordpress/2017/10/How-to-Create-a-Custom-Work-Item-Handler.png", 81 "width": 560, 82 "height": 315 83 },
84 "keywords": "BPMS, businessprocess, jboss, jbpm", 85 "description": "Custom Work Item Handlers help us connect to external systems and execute business logic.", 86 "mainEntityOfPage": "https://www.codelikethewind.org/2017/10/30/how-to-create-a-custom-work-item-handler-in-jbpm/" 87} 88 </script>
88 89 90 <meta name="generator" content="Ghost 6.68"> 91 <link rel="alternate" type="application/rss+xml" title="Code Like the Wind" href="https://www.codelikethewind.org/rss/"> 92
92<script defer src="https://cdn.jsdelivr.net/ghost/portal@~2.71/umd/portal.min.js" data-i18n="true" data-ghost="https://www.codelikethewind.org/" data-key="fc16e6907b62a92a541c2b9f9e" data-api="https://code-like-the-wind.ghost.io/ghost/api/content/" data-locale="en" crossorigin="anonymous"></script>
92<style id="gh-members-styles">.gh-post-upgrade-cta-content, 93.gh-post-upgrade-cta { 94 display: flex; 95 flex-direction: column; 96 align-items: center; 97 font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; 98 text-align: center; 99 width: 100%; 100 color: #ffffff; 101 font-size: 16px; 102} 103 104.gh-post-upgrade-cta-content { 105 border-radius: 8px; 106 padding: 40px 4vw; 107} 108 109.gh-post-upgrade-cta h2 { 110 color: #ffffff; 111 font-size: 28px; 112 letter-spacing: -0.2px; 113 margin: 0; 114 padding: 0; 115} 116 117.gh-post-upgrade-cta p { 118 margin: 20px 0 0; 119 padding: 0; 120} 121 122.gh-post-upgrade-cta small { 123 font-size: 16px; 124 letter-spacing: -0.2px; 125} 126 127.gh-post-upgrade-cta a { 128 color: #ffffff; 129 cursor: pointer; 130 font-weight: 500; 131 box-shadow: none; 132 text-decoration: underline; 133} 134 135.gh-post-upgrade-cta a:hover { 136 color: #ffffff; 137 opacity: 0.8; 138 box-shadow: none; 139 text-decoration: underline; 140} 141 142.gh-post-upgrade-cta a.gh-btn { 143 display: block; 144 background: #ffffff; 145 text-decoration: none; 146 margin: 28px 0 0; 147 padding: 8px 18px; 148 border-radius: 4px; 149 font-size: 16px; 150 font-weight: 600; 151} 152 153.gh-post-upgrade-cta a.gh-btn:hover { 154 opacity: 0.92; 155}</style> 156
156<script defer src="https://cdn.jsdelivr.net/ghost/sodo-search@~1.8/umd/sodo-search.min.js" data-key="fc16e6907b62a92a541c2b9f9e" data-styles="https://cdn.jsdelivr.net/ghost/sodo-search@~1.8/umd/main.css" data-sodo-search="https://code-like-the-wind.ghost.io/" data-locale="en" crossorigin="anonymous"></script>
156 157 158 <link href="https://www.codelikethewind.org/webmentions/receive/" rel="webmention"> 159
159<script defer src="/public/cards.min.js?v=ShRHxgy4po8zN-Wf"></script>
159 160 <link rel="stylesheet" type="text/css" href="/public/cards.min.css?v=WwnU9jw5ancNC8Gc"> 161
161<script defer src="/public/comment-counts.min.js?v=oFYkaGLdiMqB8VN9" data-ghost-comments-counts-api="https://www.codelikethewind.org/members/api/comments/counts/"></script>
161 162
162<script defer src="/public/member-attribution.min.js?v=AKG4hWena9j3yX3I"></script>
162 163
163<script defer src="/public/ghost-stats.min.js?v=vFcCUf6ZQ0Hyhc8h" data-stringify-payload="false" data-datasource="analytics_events" data-storage="localStorage" data-host="https://www.codelikethewind.org/.ghost/analytics/api/v1/page_hit" tb_site_uuid="1efc54f9-6143-47bb-be58-3116f5c55b0b" tb_post_uuid="9c8ad958-b0e7-4956-8158-49cf145ecc27" tb_post_type="post" tb_member_uuid="undefined" tb_member_status="undefined" tb_gift_link=""></script>
163<style>:root {--ghost-accent-color: #138bbe;}</style> 164 <style> 165 .cover-cta { 166 display: none; 167 } 168 169 .has-cover .site-header-content { 170 min-height: 370px; 171} 172</style> 173 174<!-- Google Tag Manager -->
175<script>
vendor: 327 bytes, lines 175-179
175(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': 176new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], 177j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 178'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); 179})(window,document,'script','dataLayer','
179GTM-KWGRFVPD
vendor: 3 bytes, line 179
179');
179</script>
179 180<!-- End Google Tag Manager --> 181 182</head> 183<body class="post-template tag-bpms tag-businessprocess tag-jboss tag-jbpm is-head-left-logo has-cover"> 184 185 <!-- Google Tag Manager (noscript) -->
vendor: 68 bytes, lines 185-186
185 186<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=
186GTM-KWGRFVPD
vendor: 83 bytes, lines 186-187
186" 187height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
188<!-- End Google Tag Manager (noscript) --> 189 190<div class="viewport"> 191 192 <header id="gh-head" class="gh-head outer"> 193 <div class="gh-head-inner inner"> 194 <div class="gh-head-brand"> 195 <a class="gh-head-logo" href="https://www.codelikethewind.org"> 196 Code Like the Wind 197 </a> 198 <button class="gh-search gh-icon-btn" data-ghost-search><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2" width="20" height="20"><path stroke-linecap="round" stroke-linejoin="round" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path></svg></button> 199 <button class="gh-burger"></button> 200 </div> 201 202 <nav class="gh-head-menu"> 203 <ul class="nav"> 204 <li class="nav-home"><a href="https://www.codelikethewind.org/">Home</a></li> 205 <li class="nav-about"><a href="https://www.codelikethewind.org/about/">About</a></li> 206 <li class="nav-contact"><a href="https://www.codelikethewind.org/contact/">Contact</a></li> 207</ul> 208 209 </nav> 210 211 <div class="gh-head-actions"> 212 <button class="gh-search gh-icon-btn" data-ghost-search><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2" width="20" height="20"><path stroke-linecap="round" stroke-linejoin="round" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path></svg></button> 213 <a class="gh-head-button" href="#/portal/signup" data-portal="signup">Subscribe</a> 214 </div> 215 </div> 216 </header> 217 218 <div class="site-content"> 219 220 221 222 223<main id="site-main" class="site-main"> 224<article class="article post tag-bpms tag-businessprocess tag-jboss tag-jbpm "> 225 226 <header class="article-header gh-canvas"> 227 228 <div class="article-tag post-card-tags"> 229 <span class="post-card-primary-tag"> 230 <a href="/tag/bpms/">BPMS</a> 231 </span> 232 </div> 233 234 <h1 class="article-title">How to Create a Custom Work Item Handler in jBPM</h1> 235 236 <p class="article-excerpt">Custom Work Item Handlers help us connect to external systems and execute business logic.</p> 237 238 <div class="article-byline"> 239 <section class="article-byline-content"> 240 241 <ul class="author-list"> 242 <li class="author-list-item"> 243 <a href="/author/tioluwa/" class="author-avatar"> 244 <img class="author-profile-image" src="//www.gravatar.com/avatar/63011705e8e94b703a655521b54f0c59?s=250&d=mm&r=x" alt="TiOluwa Olarewaju" /> 245 </a> 246 </li> 247 </ul> 248 249 <div class="article-byline-meta"> 250 <h4 class="author-name"><a href="/author/tioluwa/">TiOluwa Olarewaju</a></h4> 251 <div class="byline-meta-content"> 252 <time class="byline-meta-date" datetime="2017-10-30">Oct 30, 2017</time> 253 <span class="byline-reading-time"><span class="bull">•</span> 4 min read</span> 254 </div> 255 </div> 256 257 </section> 258 </div> 259 260 <figure class="article-image"> 261 <img 262 srcset="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w300/wordpress/2017/10/How-to-Create-a-Custom-Work-Item-Handler.png 300w, 263 https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w600/wordpress/2017/10/How-to-Create-a-Custom-Work-Item-Handler.png 600w, 264 https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w1000/wordpress/2017/10/How-to-Create-a-Custom-Work-Item-Handler.png 1000w, 265 https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w2000/wordpress/2017/10/How-to-Create-a-Custom-Work-Item-Handler.png 2000w" 266 sizes="(min-width: 1400px) 1400px, 92vw" 267 src="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w2000/wordpress/2017/10/How-to-Create-a-Cu
267stom-Work-Item-Handler.png" 268 alt="How to Create a Custom Work Item Handler in jBPM" 269 /> 270 </figure> 271 272 </header> 273 274 <section class="gh-content gh-canvas"> 275 <p>You work for a demanding, yet friendly credit card company.</p><p>And youâve <em>almost</em> finished building their business process in jBPM.</p><p>Your promotion is so close you can taste it..</p><p>But when you scroll through the list of service tasks, you can't find one to save the process information to your database.</p><p><strong>Are you doomed? </strong>No. You can create a work item handler to..</p><h2 id="connect-with-external-services">Connect with External Services</h2><p>If you want your process to <strong>connect to external systems</strong> (databases, web services) or <strong>execute special business logic</strong>, then you can..</p><h2 id="create-a-custom-work-item-handler">Create a Custom Work Item Handler</h2><p>Weâll create a custom work item handler in JBoss Dev Studio. But you can also do this in <a href="https://access.redhat.com/documentation/en-us/red_hat_jboss_bpm_suite/6.4/html/user_guide/chap_process_designer?ref=codelikethewind.org#sect_domain_specific_tasks">Business Central</a>.</p><h3 id="what-you-ll-need">What Youâll Need</h3><p>1: JBoss Developer Studio w/ JBoss EAP 6.4</p><ul><li>EAP: <a href="https://developers.redhat.com/download-manager/file/devstudio-10.2.0.GA-installer-eap.jar?ref=codelikethewind.org" rel="noopener noreferrer">
275Download here</a></li><li>JBoss Maven Repositories (<a href="https://developers.redhat.com/products/devstudio/hello-world/?ref=codelikethewind.org" rel="noopener noreferrer">Section 1: Steps 4-7</a>)</li></ul><p>2: Basic <a href="https://www.codelikethewind.org/2017/02/07/how-to-create-a-simple-maven-project/">Maven</a> & <a href="https://www.codelikethewind.org/2017/04/18/how-to-create-a-business-process-in-jboss-bpm-suite/">BPM</a> knowledge</p><p>3: JBPM Eclipse modeler. Download <a href="https://www.eclipse.org/bpmn2-modeler/downloads.php?ref=codelikethewind.org">here</a></p><h3 id="create-a-custom-service-task">Create a Custom Service Task</h3><p><strong>Step 1:</strong> Download the <a href="https://code-like-the-wind.s3.us-east-2.amazonaws.com/simple-process-workitemhandler.zip?ref=codelikethewind.org">simple-process-workitemhandler</a> project</p><ul><li>This project contains a bpm process that prints âHello Worldâ</li></ul><figure class="kg-card kg-image-card"><img src="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/2022/05/Screen-Shot-2017-08-09-at-3.38.46-PM.png" class="kg-image" alt loading="lazy" width="724" height="274" srcset="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w600/2022/05/Screen-Shot-2017-08-09-at-3.38.46-PM.png 600w, https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/2022/05/Screen-Shot-2017-08-09-at-3.38.46-PM.png 724w" sizes="(min-width: 720px) 720px"></figure><ul><li>Weâll change this script task to a custom task that executes our logic</li><li>Import this project in JBoss Developer Studio</li></ul><p><strong>Step 2:</strong> Define a Work Item</p><ul><li>Create a file src/main/resources/META-INF/MyWorkDefinitions.wid</li></ul><pre><code>import org.drools.core.process.core.datatype.impl.type.StringDataType; 276 277[ 278 [ 279 "name" : "Random Number", 280 "parameters" : [ 281 "Message" : new StringDataType(), 282 ], 283 "displayName" : "Random Number", 284 "icon" : "icon-info.gif" 285 ] 286]</code></pre><ul><li>Here we define the name of our task, a parameter and an icon</li></ul><p><strong>Step 3:</strong> Cleanup our process</p><ul><li>Right click com/sample/sample.bpm â Open with â BPMN Diagram Editor</li></ul><figure class="kg-card kg-image-card"><img src="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/2022/05/open_with.png" class="kg-image" alt loading="lazy" width="1366" height="804" srcset="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w600/2022/05/open_with.png 600w, https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w1000/2022/05/open_with.png 1000w, https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/2022/05/open_with.png 1366w" sizes="(min-width: 720px) 720px"></figure><ul><li>Delete the script task <strong>and</strong> end node.</li></ul><figure class="kg-card kg-image-card"><img src="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/2022/05/delete_node.png" class="kg-image" alt loading="lazy" width="710" height="270" srcset="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w600/2022/05/delete_node.png 600w, https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/2022/05/delete_node.png 710w"></figure><p><strong>Step 4:</strong> Create a Custom Service Task</p><ul><li>Create a <em>Random Number</em> Task</li></ul><figure class="kg-card kg-image-card"><img src="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/2022/05/Screen-Shot-2017-10-26-at-4.41.39-PM.png" class="kg-image" alt loading="lazy" width="1334" height="1150" srcset="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w600/2022/05/Screen-Shot-2017-10-26-at-4.41.39-PM.png 600w, https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w1000/2022/05/Screen-Shot-2017-10-26-at-4.41.39-PM.png 1000w, https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/2022/05/Screen-Shot-2017-10-26-at-4.41.39-PM.png 1334w" sizes="(min-width: 720px) 720px"></figure><ul><li>To add a parameter, double click the <em>Random Number</em> task</li></ul><figure class="kg-card kg-image-card"><img src="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/2022/05/Screen-Shot-2017-10-26-at-4.35.28-PM.png" class="kg-image" alt loading="lazy" width="1206" height="806" srcset="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w600/2022/05/Screen-Shot-2017-10-26-at-4.35.28-PM.png 600w, https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w1000/2022/05/Screen-Shot-2017-10-26-at-4.35.28-PM.png 1000w, https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/2022/05/Screen-Shot-2017-10-26-at-4.35.28-PM.png 1206w" sizes="(min-width: 720px) 720px"></figure><ul><li>Click the pencil next to Message</li></ul><figure class="kg-card kg-image-card"><img src="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/2022/05/Screen-Shot-2017-10-26-at-4.35.42-PM.png" class="kg-image" alt loading="lazy" width="1206" height="800" srcset="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w600/2022/05/Screen-Shot-2017-10-26-at-4.35.42-PM.png 600w, https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w1000/2022/05/Screen-Shot-2017-10-26-at-4.35.42-PM.png 1000w, https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/2022/05/Screen-Shot-2017-10-26-at-4.35.42-PM.png 1206w" sizes="(min-width: 720px) 720px"></figure><ul><li>Select âExpressionâ and type your name. Click Ok</li><li>Save the process</li></ul><p><strong>Step 5: </strong>Add a Terminate Node</p><figure class="kg-card kg-image-card"><img src="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/2022/05/Screen-Shot-2017-10-26-at-4.47.24-PM.png" class="kg-image" alt loading="lazy" width="1848" height="1230" srcset="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w600/2022/05/Screen-Shot-2017-10-26-at-4.47.24-PM.png 600w, https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w1000/2022/05/Screen-Shot-2017-10-26-at-4.47.24-PM.png 1000w, https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w1600/2022/05/Screen-Shot-2017-10-26-at-4.47.24-PM.png 1600w, https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/2022/05/Screen-Shot-2017-10-26-at-4.47.24-PM.png 1848w" sizes="(min-width: 720px) 720px"></figure><p><strong>Step 6:</strong> Connect the Service Task and Work Item Handler</p><ul><li>Create a file /src/main/resources/META-INF/kie-deployment-descriptor.xml</li></ul><pre><code><?xml version="1.0" encoding="UTF-8" standalone="yes"?> 287<deployment-descriptor xsi:schemaLocation="http://www.jboss.org/jbpm deployment-descriptor.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 288 <work-item-handlers> 289 <work-item-handler> 290 <resolver>mvel</resolver> 291 <identifier>new org.codelikethewind.workitemhandler.RandomWorkItemHandler()</identifier> 292 <parameters/> 293 <name>Random Number</name> 294 </work-item-handler> 295 </work-item-handlers> 296</deployment-descriptor></code></pre><ul><li>This registers our service task to the work item handler that weâll create next.</li></ul><p><strong>Step 7:</strong> Build the project</p><ul><li>Right click your project (simple-process) -> Run as -> Maven Build.</li></ul><pre><code>Goals: clean install</code></pre><h3 id="create-a-workitemhandler">Create a WorkItemHandler</h3><p><strong>Step 1:</strong> Download the <a href="https://code-like-the-wind.s3.us-east-2.amazonaws.com/embedded-process-workitemhandler.zip?ref=codelikethewind.org">embedded-process-workitemhandler</a> project</p><ul><li>This web app runs the bpm process we just worked on. When weâre done, that process will execute a custom work item handler</li></ul><p><strong>Step 2:</strong> Create a Custom Work Item Handler</p><ul><li>In package <em>org.codelikethewind.workitemhandler,</em> create a class called <em>RandomWorkItemHandler</em></li></ul><pre><code>public class RandomWorkItemHandler implements WorkItemHandler { 297}</code></pre><ul><li>Implement the execute and abort methods</li></ul><pre><code>@Override 298public void abortWorkItem(WorkItem workItem, WorkItemManager manager) { 299 manager.abortWorkItem(workItem.getId()); 300} 301 302@Override 303public void executeWorkItem(WorkItem workItem, WorkItemManager manager { 304 305 Random rand = new Random(); 306 int n = rand.nextInt(50) + 1; 307 308 Object name = workItem.getParameter("Message"); 309 System.out.println("Hi " + name + ", your random number is: " + n); 310 311 manager.completeWorkItem(workItem.getId(), null); 312}</code></pre><p><strong>Step 3:</strong> Build the project</p><ul><li>Right click your project (embedded-process-workitemhandler) -> Run as -> Maven Build.</li></ul><pre><code>Goals: clean install</code></pre><h3 id="run-the-process">Run the Process</h3><p><strong>Step 1:</strong> Deploy the simple-embedded-process</p><ul><li>Steps 1 &
312 2 of Method 1 <a href="https://www.codelikethewind.org/2017/08/18/3-simple-methods-to-deploy-to-jboss/">here</a></li></ul><p><strong>Step 2:</strong> Start the process</p><ul><li>Go to <a href="http://localhost:8080/embedded-process-workitemhandler/?ref=codelikethewind.org">http://localhost:8080/embedded-process-workitemhandler/</a></li></ul><p><strong>Step 3:</strong> Check your server logs</p><ul><li>If your process prints out a random number, youâve successfully built a custom work item handler!</li></ul><h3 id="recap">Recap</h3><p><strong>Create a Custom Service Task</strong></p><ul><li>We defined the structure of our <a href="http://docs.jboss.org/jbpm/v6.4/userguide/ch21.html?ref=codelikethewind.org#sec.workitemdefinition.overview">work item</a> -- a custom task in your process. It has a name, one parameter, and an icon.</li><li>We added the custom task to our process and filled in a parameter</li><li>We created a deployment descriptor to connect this service task to the work item handler.</li></ul><p><strong>Create a WorkItemHandler</strong></p><ul><li>We created a custom work item handler to print a random number</li><li>Our Work Item Handler is simple, but you can implement any complex logic.</li></ul><p><strong>Run the Process</strong></p><ul><li>Once the process hits our service task, the <em>execute()</em> method in <em>RandomWorkItemHandler </em>will<em> run</em></li></ul><h2 id="for-business-logic-not-data">For Business Logic, Not Data</h2><p>Use work item <em>handlers </em>(the java class) t<em>o</em> <strong>run</strong> business logic, not create data. Your data should be passed in as a parameter to your custom work item (the service task).</p><p>This makes your process easy to update, test, and maintain.</p><h2 id="so-"><strong>So..</strong></h2><ol><li>Custom Work Item Handlers <strong>help us connect to external services or execute business logic</strong></li><li>We <strong>define a work item</strong> (service task), a <strong>work item handler</strong> (the implementation), and run it in our process</li><li>Use work item handlers <strong>for logic, not data!</strong></li></ol><h2 id="source-code-useful-links"><strong>Source Code & Useful Links</strong></h2><ol><li>Finished projects: <a href="https://code-like-the-wind.s3.us-east-2.amazonaws.com/simple-process-workitemhandler-finished.zip?ref=codelikethewind.org">simple-process-workitemhandler</a> & <a href="https://code-like-the-wind.s3.us-east-2.amazonaws.com/embedded-process-workitemhandler-finished.zip?ref=codelikethewind.org">embedded-process-workitemhandler</a></li><li><a href="http://docs.jboss.org/jbpm/v6.4/userguide/ch21.html?ref=codelikethewind.org#d0e27682">Official jBPM Documentation of Custom Service Tasks</a></li><li><a href="https://access.redhat.com/documentation/en-us/red_hat_jboss_bpm_suite/6.4/html/user_guide/chap_process_designer?ref=codelikethewind.org#sect_domain_specific_tasks">Creating Work Item Handlers in Business Central</a></li></ol><p>Happy Coding!</p><p>-T.O.</p> 313 </section> 314 315 <section class="article-comments gh-canvas"> 316 <div id="disqus_thread"></div>
317<script> 318 var disqus_config = function () { 319 this.page.url = "https://www.codelikethewind.org/2017/10/30/how-to-create-a-custom-work-item-handler-in-jbpm/"; 320 this.page.identifier = "ghost-3017" 321 }; 322 (function() { 323 var d = document, s = d.createElement('script'); 324 s.src = 'https://codelikethewind.disqus.com/embed.js'; 325 s.setAttribute('data-timestamp', +new Date()); 326 (d.head || d.body).appendChild(s); 327 })(); 328</script>
328 329 </section> 330 331</article> 332</main> 333 334 335 336 337 <aside class="read-more-wrap outer"> 338 <div class="read-more inner"> 339 340<article class="post-card post"> 341 342 <a class="post-card-image-link" href="/2024/09/09/5-ways-developer-hub-boosts-developer-productivity/"> 343 344 <img class="post-card-image" 345 srcset="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w300/2024/09/2024_RH_Developer_Hub_Featured_imageV2.jpg 300w, 346 https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w600/2024/09/2024_RH_Developer_Hub_Featured_imageV2.jpg 600w, 347 https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w1000/2024/09/2024_RH_Developer_Hub_Featured_imageV2.jpg 1000w, 348 https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w2000/2024/09/2024_RH_Developer_Hub_Featured_imageV2.jpg 2000w" 349 sizes="(max-width: 1000px) 400px, 800px" 350 src="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w600/2024/09/2024_RH_Developer_Hub_Featured_imageV2.jpg" 351 alt="5 Ways Developer Hub Boosts Developer Productivity" 352 loading="lazy" 353 /> 354 355 356 </a> 357 358 <div class="post-card-content"> 359 360 <a class="post-card-content-link" href="/2024/09/09/5-ways-developer-hub-boosts-developer-productivity/"> 361 <header class="post-card-header"> 362 <div class="post-card-tags"> 363 </div> 364 <h2 class="post-card-title"> 365 5 Ways Developer Hub Boosts Developer Productivity 366 </h2> 367 </header> 368 <div class="post-card-excerpt">Developer Hub is a single place to build, manage, and deploy software. It saves developers time and allows them to focus on building software.</div> 369 </a> 370 371 <footer class="post-card-meta"> 372 <time class="post-card-meta-date" datetime="2024-09-09">Sep 9, 2024</time> 373 <span class="post-card-meta-length">3 min read</span> 374
374<script 375 data-ghost-comment-count="66d9eb7b9d22de00019383f1" 376 data-ghost-comment-count-empty="" 377 data-ghost-comment-count-singular="comment" 378 data-ghost-comment-count-plural="comments" 379 data-ghost-comment-count-tag="span" 380 data-ghost-comment-count-class-name="" 381 data-ghost-comment-count-autowrap="true" 382> 383</script>
383 384 </footer> 385 386 </div> 387 388</article> 389 390<article class="post-card post"> 391 392 <a class="post-card-image-link" href="/2024/08/20/instructlab-training-help-your-ai-models-grow-up-quickly/"> 393 394 <img class="post-card-image" 395 srcset="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w300/2024/08/instructlab-cropped.png 300w, 396 https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w600/2024/08/instructlab-cropped.png 600w, 397 https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w1000/2024/08/instructlab-cropped.png 1000w, 398 https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w2000/2024/08/instructlab-cropped.png 2000w" 399 sizes="(max-width: 1000px) 400px, 800px" 400 src="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w600/2024/08/instructlab-cropped.png" 401 alt="InstructLab Training: Help Your AI Models Grow Up Quickly" 402 loading="lazy" 403 /> 404 405 406 </a> 407 408 <div class="post-card-content"> 409 410 <a class="post-card-content-link" href="/2024/08/20/instructlab-training-help-your-ai-models-grow-up-quickly/"> 411 <header class="post-card-header"> 412 <div class="post-card-tags"> 413 </div> 414 <h2 class="post-card-title"> 415 InstructLab Training: Help Your AI Models Grow Up Quickly 416 </h2> 417 </header> 418 <div class="post-card-excerpt">80% of AI models never see the real world. InstructLab helps us train models fast with less data, time, and resources.</div> 419 </a> 420 421 <footer class="post-card-meta"> 422 <time class="post-card-meta-date" datetime="2024-08-20">Aug 20, 2024</time> 423 <span class="post-card-meta-length">5 min read</span> 424
424<script 425 data-ghost-comment-count="66be5b173698250001fd7354" 426 data-ghost-comment-count-empty="" 427 data-ghost-comment-count-singular="comment" 428 data-ghost-comment-count-plural="comments" 429 data-ghost-comment-count-tag="span" 430 data-ghost-comment-count-class-name="" 431 data-ghost-comment-count-autowrap="true" 432> 433</script>
433 434 </footer> 435 436 </div> 437 438</article> 439 440<article class="post-card post"> 441 442 <a class="post-card-image-link" href="/2023/06/27/camel-k-integrate-systems-without-breaking-the-bank/"> 443 444 <img class="post-card-image" 445 srcset="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w300/2023/06/camel-k-coverimage.png 300w, 446 https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w600/2023/06/camel-k-coverimage.png 600w, 447 https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w1000/2023/06/camel-k-coverimage.png 1000w, 448 https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w2000/2023/06/camel-k-coverimage.png 2000w" 449 sizes="(max-width: 1000px) 400px, 800px" 450 src="https://storage.ghost.io/c/1e/fc/1efc54f9-6143-47bb-be58-3116f5c55b0b/content/images/size/w600/2023/06/camel-k-coverimage.png" 451 alt="Camel-K: Integrate Systems Without Breaking the Bank" 452 loading="lazy" 453 /> 454 455 456 </a> 457 458 <div class="post-card-content"> 459 460 <a class="post-card-content-link" href="/2023/06/27/camel-k-integrate-systems-without-breaking-the-bank/"> 461 <header class="post-card-header"> 462 <div class="post-card-tags"> 463 </div> 464 <h2 class="post-card-title"> 465 Camel-K: Integrate Systems Without Breaking the Bank 466 </h2> 467 </header> 468 <div class="post-card-excerpt">Camel-K helps us integrate systems in an easy, simple, and cost effective way. Do more with less.</div> 469 </a> 470 471 <footer class="post-card-meta"> 472 <time class="post-card-meta-date" datetime="2023-06-27">Jun 27, 2023</time> 473 <span class="post-card-meta-length">6 min read</span> 474
474<script 475 data-ghost-comment-count="6499c378d908840001216322" 476 data-ghost-comment-count-empty="" 477 data-ghost-comment-count-singular="comment" 478 data-ghost-comment-count-plural="comments" 479 data-ghost-comment-count-tag="span" 480 data-ghost-comment-count-class-name="" 481 data-ghost-comment-count-autowrap="true" 482> 483</script>
483 484 </footer> 485 486 </div> 487 488</article> 489 </div> 490 </aside> 491 492 493 494 </div> 495 496 <footer class="site-footer outer"> 497 <div class="inner"> 498 <section class="copyright"><a href="https://www.codelikethewind.org">Code Like the Wind</a> © 2026</section> 499 <nav class="site-footer-nav"> 500 <ul class="nav"> 501 <li class="nav-sign-up"><a href="#/portal/">Sign up</a></li> 502</ul> 503 504 </nav> 505 <div><a href="https://ghost.org/" target="_blank" rel="noopener">Powered by Ghost</a></div> 506 </div> 507 </footer> 508 509</div> 510 511
512<script 513 src="https://code.jquery.com/jquery-3.5.1.min.js" 514 integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" 515 crossorigin="anonymous"> 516</script>
vendor: 1 bytes, line 516
516
517<script src="https://www.codelikethewind.org/assets/built/casper.js?v=vDI1nndnsl7J9t11"></script>
vendor: 1 bytes, line 517
517
518<script> 519$(document).ready(function () { 520 // Mobile Menu Trigger 521 $('.gh-burger').click(function () { 522 $('body').toggleClass('gh-head-open'); 523 }); 524 // FitVids - Makes video embeds responsive 525 $(".gh-content").fitVids(); 526}); 527</script>
527 528
529<script src="https://t.ghostboard.io/min.js" async defer data-gbid="62a8a21d3d7840787c1471ef"></script>
529<noscript><img src="https://api.ghostboard.io/noscript/62a8a21d3d7840787c1471ef/pixel.gif" alt="Ghostboard pixel" /></noscript> 530 531</body> 532</html>
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.