Powered By Blogger

Wednesday, January 26, 2011

Reopening completed workflow human task

Usecase: Sometimes we may come across a situation where we wanted to re-open the completed workflow human task.

Implementation steps:
  • Capture the token and taskid attributes of completed human task. You can get these task attributes from 'initiateTaskResponseMessage'  outputVariable which will be created in INVOKE activity of human task service

  • Drag and drop database adapter after human task RECEIVE activity and execute delete operation from orabpel.wftask and orabpel.wfroutingslip where taskid = 'Already captured Taskid'
  • Drag and drop invoke activity and link it to TaskServcie partnerlink service and select 'reinitiate Task' operation


  • Drag an Assign activity before last INVOKE and assign previously stored Taskid, token and 'ASSIGNED'  literal value to Taskid,token and state fields of  Invoke_1_reinitiateTask_InputVariable respectively
  • Compile and deploy

Removing unwanted namespace nodes from BPEL XML data

Use case- We have a requirement where we wanted to remove certain kinds of names space nodes from BPEL XML data and write it to file location.

Implementation steps:
  • Assume that we declare string variable- tmp in BPEL which holds the xml containing name space nodes  to be deleted
    
     
      
       
      

   


  • We also  declare another string variable - encStr in BPEL which holds transformed xml data
  • Java embedding activity with below code


     
try {       
addAuditTrailEntry("Try Block");    
String outputString = null;        
outputString = (java.lang.String)getVariableData("tmp");        
outputString = outputString.replaceAll("xmlns=\"http://xmlns.modeln.com/ApplicationObjects/MCOCheckAck/V1\"", "");            
outputString = outputString.replaceAll("xmlns:ns0=\"http://xmlns.modeln.com/ApplicationObjects/MCOCheckAck/V1\"", "");          
outputString = outputString.replaceAll("ns0:", "");
outputString = outputString.replaceAll(" xmlns=\"\"", "");     
addAuditTrailEntry("outputString"+outputString);     
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();     
DocumentBuilder db = dbf.newDocumentBuilder();     
org.w3c.dom.Document originalDoc = db.parse(new ByteArrayInputStream(outputString.getBytes()));     
         DOMSource domSource = new DOMSource(originalDoc);     
         StringWriter writer = new StringWriter();    
         addAuditTrailEntry("writer"+writer);    
         StreamResult result = new StreamResult(writer);    
         addAuditTrailEntry("result"+result);    
         TransformerFactory tf = TransformerFactory.newInstance();     
         Transformer transformer = tf.newTransformer();     
         transformer.transform(domSource, result);    
         addAuditTrailEntry("domSource"+domSource);    
         addAuditTrailEntry("result"+result);    
      
String encoded = Base64Encoder.encode(writer.toString());       
setVariableData("encStr",encoded);     
} catch(Exception ex) {       
ex.printStackTrace();       
}

Create a file adapter partner link with ‘Schema is Opaque ’ option




  • Next assign encStr variable to file invoke activity input variable
  • Add an invoke activity to invoke file adapter to write transformed xml
Disadvantages of this approach


We can not see transformed payload in audit trail of BPEL console because of binary format but if we check file write location you can see XML payload without name space nodes.