cancel
Showing results for 
Search instead for 
Did you mean: 

How can I get output when I use Webservice in process

morexpool
Champ in-the-making
Champ in-the-making
My Web Service :



package com.morex.test;

import javax.ejb.Stateless;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

@Stateless
@WebService
public class AddressService {

   @WebResult(name="findCustomerAddressResponseItem")
   public String findCustomerAddress(@WebParam(name="findCustomerAddressRequestItem") String customerName) {
      
      System.out.println("——————————————————- ");
      System.out.println("|                                                     | ");
      System.out.println("|                                                     | ");
      System.out.println("|                                                     | ");
      System.out.println("|                                                     | ");      
      System.out.println("|         customerName = "+ customerName);      
      System.out.println("|                                                     | ");
      System.out.println("|                                                     | ");
      System.out.println("|                                                     | ");
      System.out.println("|                                                     | ");
      System.out.println("——————————————————- ");
            
      return "Customer [ "+ customerName + " ] has address ABC…" ;
   }
}




My BPMN file :



<?xml version="1.0" encoding="UTF-8"?>
<definitions id="definitions" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
   xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"
   typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath"
   xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" targetNamespace="com.morex.test.AddressService"
   xmlns:tns="com.morex.test.AddressService" xmlns:classObject="http://test.morex.com/">

   <import importType="http://schemas.xmlsoap.org/wsdl/"
      location="http://192.168.7.166:8381/CreateWS-1/AddressService?wsdl"
      namespace="http://test.morex.com/" />

   <message id="findCustomerAddressRequestMessage" itemRef="tns:findCustomerAddressRequestItem" />
   <message id="findCustomerAddressResponseMessage" itemRef="tns:findCustomerAddressResponseItem" />

   <itemDefinition id="findCustomerAddressRequestItem"       structureRef="classObject:findCustomerAddress" />
   <itemDefinition id="findCustomerAddressResponseItem"       structureRef="classObject:findCustomerAddressResponse" />

   <interface name="Find customer address" implementationRef="classObject:AddressService">
      <operation id="findCustomerAddressOperation" name="Find Customer Address by name" implementationRef="classObject:findCustomerAddress">
         <inMessageRef>tns:findCustomerAddressRequestMessage</inMessageRef>
         <outMessageRef>tns:findCustomerAddressResponseMessage</outMessageRef>
      </operation>
   </interface>

   <process id="call_wsdl">

      <dataObject id="dataInputOfProcess" itemSubjectRef="tns:findCustomerAddressRequestItem" />
      <dataObject id="dataOutputOfProcess" itemSubjectRef="tns:findCustomerAddressResponseItem" />      

      <startEvent id="startevent" name="Start" />
      <sequenceFlow id="flow1" sourceRef="startevent"          targetRef="theScriptTask" />
      <scriptTask id="theScriptTask" scriptFormat="groovy"          name="Execute script">
         <script>
            System.out.println("dataInputOfProcess : "+dataInputOfProcess);
            System.out.println("dataOutputOfProcess : "+dataOutputOfProcess);
         </script>
      </scriptTask>
      <sequenceFlow id="flow1a" sourceRef="theScriptTask" targetRef="webService" />

      <serviceTask id="webService" name="Find customer address web service" implementation="##WebService" operationRef="tns:findCustomerAddressOperation">
         <ioSpecification>
            <dataInput itemSubjectRef="tns:findCustomerAddressRequestItem" isCollection="false"    id="requestItem" />
            <dataOutput itemSubjectRef="tns:findCustomerAddressResponseItem" isCollection="false" id="responsetItem" />
            <inputSet>
               <dataInputRefs>requestItem</dataInputRefs>
            </inputSet>
            <outputSet>
               <dataOutputRefs>responsetItem</dataOutputRefs>
            </outputSet>            
         </ioSpecification>
         <dataInputAssociation>
            <sourceRef>dataInputOfProcess</sourceRef>
            <targetRef>requestItem</targetRef>            
         </dataInputAssociation>
         <dataOutputAssociation>
              <targetRef>dataOutputOfProcess</targetRef>
              <transformation>${responsetItem}</transformation>
         </dataOutputAssociation>         
      </serviceTask>

      <sequenceFlow id="flow21" sourceRef="webService" targetRef="theScriptTask2" />
      <scriptTask id="theScriptTask2" scriptFormat="groovy" name="Execute script 2">
         <script>
            System.out.println("dataInputOfProcess : "+dataInputOfProcess);
            System.out.println("dataOutputOfProcess : "+dataOutputOfProcess);
         </script>
      </scriptTask>
      <sequenceFlow id="flow2" sourceRef="theScriptTask2" targetRef="endevent" />
      <endEvent id="endevent" name="End" />
      
   </process>

</definitions>



And my java code :



package com.bpmn.test;

import java.util.HashMap;
import java.util.Map;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;

public class ProcessRunner {
   
   public static void main(String[] args) {
      
      ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

      RepositoryService repositoryService = processEngine.getRepositoryService();

      repositoryService.createDeployment() .addClasspathResource("call_WSDL.bpmn20.xml") .deploy();

      RuntimeService runtimeService = processEngine.getRuntimeService();      
      
      Map<String, Object> variables = new HashMap<String, Object>();
      variables.put("dataInputOfProcess", "morex");
      variables.put("dataOutputOfProcess", "x");

      runtimeService.startProcessInstanceByKey("call_wsdl",variables);   
   }   
}


Okey , Now look at result :

web service log :



01:23:55,332 INFO  [STDOUT] ——————————————————-
01:23:55,333 INFO  [STDOUT] |                                                     |
01:23:55,333 INFO  [STDOUT] |                                                     |
01:23:55,333 INFO  [STDOUT] |                                                     |
01:23:55,333 INFO  [STDOUT] |                                                     |
01:23:55,333 INFO  [STDOUT] |         customerName = morex
01:23:55,334 INFO  [STDOUT] |                                                     |
01:23:55,334 INFO  [STDOUT] |                                                     |
01:23:55,334 INFO  [STDOUT] |                                                     |
01:23:55,334 INFO  [STDOUT] |                                                     |
01:23:55,334 INFO  [STDOUT] ——————————————————-


and java code result :



Jan 30, 2013 3:17:38 PM org.activiti.engine.ProcessEngines init
INFO: Initializing process engine using configuration 'file:/F:/morteza-pooladi-share/JAVA/workspace/Test21/target/classes/activiti.cfg.xml'
Jan 30, 2013 3:17:38 PM org.activiti.engine.ProcessEngines initProcessEnginFromResource
INFO: initializing process engine for resource file:/F:/morteza-pooladi-share/JAVA/workspace/Test21/target/classes/activiti.cfg.xml
Jan 30, 2013 3:17:38 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from resource loaded through InputStream
Jan 30, 2013 3:17:39 PM org.activiti.engine.impl.ProcessEngineImpl <init>
INFO: ProcessEngine default created
Jan 30, 2013 3:17:39 PM org.activiti.engine.ProcessEngines initProcessEnginFromResource
INFO: initialised process engine default
Jan 30, 2013 3:17:39 PM org.activiti.engine.impl.bpmn.deployer.BpmnDeployer deploy
INFO: Processing resource call_WSDL.bpmn20.xml
Jan 30, 2013 3:17:39 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes
INFO: XMLSchema currently not supported as typeLanguage
Jan 30, 2013 3:17:39 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes
INFO: XPath currently not supported as expressionLanguage
Jan 30, 2013 3:17:40 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseProcessDefinitions
INFO: Process with id='call_wsdl' has no attribute isExecutable. Assuming it is executable. Better set the attribute explicitely, especially to be compatible with future engine versions which might change the default behavior.
dataInputOfProcess : morex
dataOutputOfProcess : x
Jan 30, 2013 3:17:41 PM org.apache.cxf.common.jaxb.JAXBUtils logGeneratedClassNames
INFO: Created classes: com.morex.test.FindCustomerAddress, com.morex.test.FindCustomerAddressResponse, com.morex.test.ObjectFactory

dataInputOfProcess : morex
dataOutputOfProcess : org.activiti.engine.impl.bpmn.data.ItemInstance@260829


Now my question : How can I check content of [ org.activiti.engine.impl.bpmn.data.ItemInstance@260829 ] ???

Thanks for your help .
4 REPLIES 4

frederikherema1
Star Contributor
Star Contributor
First, read the process-variable using the runtime-service. Next, you can use the getStructureInstance() on the InstanceItem to read the fields that are present in the data, this is either a "FieldBaseStructureInstance" (containing hash maps with field/values) or PrimitiveStructureInstance (which contains only ONE field, a single primitive type).

morexpool
Champ in-the-making
Champ in-the-making
First, read the process-variable using the runtime-service. Next, you can use the getStructureInstance() on the InstanceItem to read the fields that are present in the data, this is either a "FieldBaseStructureInstance" (containing hash maps with field/values) or PrimitiveStructureInstance (which contains only ONE field, a single primitive type).




I type this  :



ProcessInstance  pi = runtimeService.startProcessInstanceByKey("call_wsdl",variables);

Object varSetByListener = runtimeService.getVariable(pi.getId(), "dataOutputOfProcess");
}

but result :

Jan 30, 2013 3:44:44 PM org.activiti.engine.ProcessEngines init
INFO: Initializing process engine using configuration 'file:/F:/morteza-pooladi-share/JAVA/workspace/Test21/target/classes/activiti.cfg.xml'
Jan 30, 2013 3:44:44 PM org.activiti.engine.ProcessEngines initProcessEnginFromResource
INFO: initializing process engine for resource file:/F:/morteza-pooladi-share/JAVA/workspace/Test21/target/classes/activiti.cfg.xml
Jan 30, 2013 3:44:44 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from resource loaded through InputStream
Jan 30, 2013 3:44:45 PM org.activiti.engine.impl.ProcessEngineImpl <init>
INFO: ProcessEngine default created
Jan 30, 2013 3:44:45 PM org.activiti.engine.ProcessEngines initProcessEnginFromResource
INFO: initialised process engine default
Jan 30, 2013 3:44:45 PM org.activiti.engine.impl.bpmn.deployer.BpmnDeployer deploy
INFO: Processing resource call_WSDL.bpmn20.xml
Jan 30, 2013 3:44:45 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes
INFO: XMLSchema currently not supported as typeLanguage
Jan 30, 2013 3:44:45 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes
INFO: XPath currently not supported as expressionLanguage
Jan 30, 2013 3:44:46 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseProcessDefinitions
INFO: Process with id='call_wsdl' has no attribute isExecutable. Assuming it is executable. Better set the attribute explicitely, especially to be compatible with future engine versions which might change the default behavior.
dataInputOfProcess : morex
dataOutputOfProcess : x
Jan 30, 2013 3:44:46 PM org.apache.cxf.common.jaxb.JAXBUtils logGeneratedClassNames
INFO: Created classes: com.morex.test.FindCustomerAddress, com.morex.test.FindCustomerAddressResponse, com.morex.test.ObjectFactory
dataInputOfProcess : morex
dataOutputOfProcess : org.activiti.engine.impl.bpmn.data.ItemInstance@d622e5
Jan 30, 2013 3:44:48 PM org.activiti.engine.impl.interceptor.CommandContext close
SEVERE: Error while closing command context
org.activiti.engine.ActivitiException: execution 24604 doesn't exist
at org.activiti.engine.impl.cmd.GetExecutionVariableCmd.execute(GetExecutionVariableCmd.java:52)
at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:60)
at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:32)
at org.activiti.engine.impl.RuntimeServiceImpl.getVariable(RuntimeServiceImpl.java:115)
at com.bpmn.test.ProcessRunner.main(ProcessRunner.java:30)
Exception in thread "main" org.activiti.engine.ActivitiException: execution 24604 doesn't exist
at org.activiti.engine.impl.cmd.GetExecutionVariableCmd.execute(GetExecutionVariableCmd.java:52)
at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:60)
at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:32)
at org.activiti.engine.impl.RuntimeServiceImpl.getVariable(RuntimeServiceImpl.java:115)
at com.bpmn.test.ProcessRunner.main(ProcessRunner.java:30)

:!:

Do your have any idea ?  :geek:

frederikherema1
Star Contributor
Star Contributor
The exception states that the execution does not exist. Probabily, you're process immediately ends after the webservice-call. One the process is ended, the process is deleted from the database, along with any variables associated to it. Possible solutions are:

  • Add an additional receiveTask or userTask after the webservice-call. This step represent an action needs to be performed outside of the engine (either a system-action or a manual action by a user). Since the process is not ended, but rather waiting for a signal or a task to complete, the variables will still be accessible using runtimeService.

  • Make sure history is configured high enough to get HistoricVariableUpdates recorded. When the process is finished, you can still query those, using the HistoryService.

  • A process with a web-service call that immediately ends, doesn't really make sense. Most of the time, you'll want to use the outcome in THE NEXT STEPS of your process. For example, you can add a service-task (JavaDelegate) after the webservice-call, which used the passed-in DelegateExecution to extract the "dataOutputOfProcess" variable. It can inspect the variable and perform actions or set other variables accordingly…

morexpool
Champ in-the-making
Champ in-the-making
You are right.

I have 2 way :

1- In process catch it like this :


<scriptTask id="theScriptTask2" scriptFormat="groovy" name="Execute script 2">
   <script>
    String responceItemName = dataOutputOfProcess.structureInstance.getFieldNameAt(0);
    System.out.println("responce Item Name : " + responceItemName);
    System.out.println("dataOutputOfProcess : "+dataOutputOfProcess.structureInstance.getFieldValue(responceItemName));   
   </script>
</scriptTask>


and result :




Jan 30, 2013 5:42:08 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes
INFO: XPath currently not supported as expressionLanguage
Jan 30, 2013 5:42:09 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseProcessDefinitions
INFO: Process with id='call_wsdl' has no attribute isExecutable. Assuming it is executable. Better set the attribute explicitely, especially to be compatible with future engine versions which might change the default behavior.
dataInputOfProcess : morex
dataOutputOfProcess : x
Jan 30, 2013 5:42:10 PM org.apache.cxf.common.jaxb.JAXBUtils logGeneratedClassNames
INFO: Created classes: com.morex.test.FindCustomerAddress, com.morex.test.FindCustomerAddressResponse, com.morex.test.ObjectFactory
responce Item Name : responseItem
dataOutputOfProcess : Customer [ morex ] has address ABC…



2- Use History LOG .

Chapter 11. History

Thanks a lot men .