Thursday, October 24, 2013

jBPM process after workflow node using ActionHandler

jBPM process after workflow node using ActionHandler


Simple article to show how to do processing after each workflow node and also send values from workflow to ActionHandler 
<node name="Process Node">
<action class="org.jboss.soa.esb.services.jbpm.actionhandlers.EsbActionHandler">
<esbCategoryName>
ESB_PROCESSOR_QUOTE
</esbCategoryName>
</action>
<event type="node-leave">
<action class="event.CustomNodeComplete">
<actionName>Quote Successful</actionName>
</action>
</event>
<transition to="Complete"></transition>
</node>

Workflow ProcessDefinition


actionName is passed to the ActionHandler and  execute method will be called if workflow node completes  successfully 

ActionHandler

public class  CustomNodeComplete implements ActionHandler {


private static final long serialVersionUID = -6446921306976005512L;
String actionName;


@Override
public void execute(ExecutionContext execContext) throws Exception {

//actionName from workflow available

// send notification
}


Tuesday, October 22, 2013

jBPM Node for Decision using ActionHandler

jBPM use non-decision node to choose workflow path

You can use the decision node to choose one of the workflow path . This is to show a workaround if you have constrains using the decision node.  Shown below simple workflow and can either branch to  "Yes" path or "No" path based on the decision by Node - ValidQuote


Process Definition 
<?xml version="1.0" encoding="UTF-8"?>

<process-definition xmlns="" name="Quote Process">


<start-state name="Start">
<transition to="Process Quote"></transition>
</start-state>



<node name="Process Quote">
<action class="org.jboss.soa.esb.services.jbpm.actionhandlers.EsbActionHandler">
<esbServiceName>
ProcessQuote
</esbServiceName>
<esbCategoryName>
ESB_PROCESS_QUOTE
</esbCategoryName>
</action>
<transition to="ValidQuote"></transition>
</node>

<node name="ValidQuote">
<action name="ValidQuote" class="event.ValidQuote"></action>
<transition to="Log-NotifyCSR" name="No"></transition>
<transition to="EmailCustomer" name="Yes"></transition>
</node>

<node name="EmailCustomer">
<action class="org.jboss.soa.esb.services.jbpm.actionhandlers.EsbActionHandler">
<esbCategoryName>
ESB_EMAIL
</esbCategoryName>
</action>
<transition to="Complete"></transition>
</node>

<node name="Log-NotifyCSR">
<action class="org.jboss.soa.esb.services.jbpm.actionhandlers.EsbActionHandler">
<esbCategoryName>
ESB_CSR
</esbCategoryName>
</action>
<transition to="Complete"></transition>
</node>

<end-state name="Complete"></end-state>


</process-definition>



Action Handler ( defined in the ValidQuote)
package event;
import org.jbpm.graph.exe.ExecutionContext;

public class ValidQuote implements ActionHandler {

@Override
public void execute(ExecutionContext execContext) throws Exception {

if( somecondition...)
execContext.leaveNode("Yes");
else
execContext.leaveNode("No");
}

}



Wednesday, October 16, 2013

SOAP UI Dynamic mock service using Groovy Script


SOAP UI Dynamic mock service using Groovy Script

Create dynamic mock service using SOAP UI . You will just need the WSDL . You should be familiar using the soap ui and creating the mock service . Following is to only make it dynamic
  1. Create a SoapUI project using the WSDL . Right click and select the mock service .
  2. Select the  WebService Method and Open the Response that has to be customized
  3. Create two files for Success and Error response and place them in folder  {Project-Path}/responses
  4. WebService Response ( Right portion of the Soap UI Window )will be made dynamic based on request.  Delete everything from mock response and  replace with${content} .  This value will be dynamically rendered from  groovy script
  5. Choose Dispatch -> Script , and then choose Dynamic Reponse
  6. Use the groovy script below , to render Success and Error Responses .

It works in the following way ,

  • if quotenumber is 9999  - send Error response
  • anything else - send Success Response


Now you can create more test cases and test them by changing the input in the xml . Providing  the input , output and the script below


Input ( for ref )

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:test="http://www.testing.com/WS/quoteWS">

  <soapenv:Header/>

  <soapenv:Body>

     <test:Quote>

        <QuoteRequest>

           <quoteNumber>9999</quoteNumber>

           <quoteTitle>?</quoteTitle>

           <quotePrice>?</quotePrice>

        </QuoteRequest>

     </test:Quote>

  </soapenv:Body>

</soapenv:Envelope>'



Output

Success
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:test="http://www.testing.com/WS/quoteWS">

  <soapenv:Header/>

  <soapenv:Body>

     <test:QuoteResponse>

        <QuoteReply>

           <status>Success</status>

           <!--Optional:-->

           <errorCode>0</errorCode>

           <!--Optional:-->

           <errorMessage></errorMessage>

           <!--Optional:-->

           <errorDetail></errorDetail>

        </QuoteReply>

     </test:QuoteResponse>

  </soapenv:Body>

</soapenv:Envelope>



Error

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:test="http://www.testing.com/WS/quoteWS">

  <soapenv:Header/>

  <soapenv:Body>

     <test:QuoteResponse>

        <QuoteReply>

           <status>ERROR</status>

           <!--Optional:-->

           <errorCode>11</errorCode>

           <!--Optional:-->

           <errorMessage>Failed</errorMessage>

           <!--Optional:-->

           <errorDetail>Something failed </errorDetail>

        </QuoteReply>

     </test:QuoteResponse>

  </soapenv:Body>

</soapenv:Envelope>


Groovy Script
import com.eviware.soapui.support.GroovyUtils

import groovy.xml.XmlUtil

log.info 'start'

def groovyUtils = new GroovyUtils(context)

def xmlParser = new XmlParser()

def responseContent

def requestXmlHolder = groovyUtils.getXmlHolder(mockRequest.getRequestContent())

requestXmlHolder.declareNamespace("test","http://www.testing.com/WS/quoteWS")

def quoteNumber = requestXmlHolder.getNodeValue("//test:Quote/QuoteRequest[1]/quoteNumber[1]")

log.info  quoteNumber



if(quoteNumber == '9999')

{

responseContent = xmlParser.parse(groovyUtils.projectPath +"/responses/error-response.xml")


}

else

{

responseContent = xmlParser.parse(groovyUtils.projectPath +"/responses/success-response.xml")

}

context.content = XmlUtil.serialize(responseContent)

log.info 'complete'