Injecting a Business Service Event — Service Connector API Example (Java)

An example is provided that illustrates injecting data into a business service using method calls available in the Service Connector API.

The step numbers in the comments correspond to the steps in the illustration Injecting a Business Service Event.

private void injectBusinessServiceEventExample()
	{
		try
		{
			// Step 1: List the available business services
			ListBusinessServicesResponse businessServicesList = serviceConnectorInstance.getBusinessService()
					.listBusinessServices(Long.valueOf(0), Long.valueOf(0), true, null, true, null);
			print(businessServicesList);
			// Step 2: Start the business service
			// First we setup a BusinessServiceTemplate with details of the service to start
			// Normally these would be retrieved by parsing the businessServicesList returned from the listBusinessServices call,
			// in this example we are hard-coding the value
			BusinessServiceTemplate template = BusinessServiceTemplate.Factory.newInstance();
			template.setModuleName("/TestBS/Process Packages/ProcessPackage.xpdl");
			template.setProcessName("CatchEventBS");
			template.setVersion("1.0.0.201108111511");
			// Start the service
			StartBusinessServiceResponse startResponse = serviceConnectorInstance.getBusinessService()
					.startBusinessService(template, null, PayloadModeType.XML, Long.valueOf(0));
			// Step 3: Inject the event
			// First we setup an event containing the business service details and the name of the event
			EventDefinitionType event = EventDefinitionType.Factory.newInstance();
			// Details of business service
			event.setModuleName(template.getModuleName());
			event.setProcessName(template.getProcessName());
			// Name of the event
			event.setEventName("IntermediateEvent");
			// The ID of the service we just started
			event.setProcessInstanceId(startResponse.getPageResponse().getContext().getProcessReference().getId());
			// Now we need to setup the data to inject into the event the data is contained in a DataPayload
			DataPayload payload = DataPayload.Factory.newInstance();
			payload.setPayloadMode(PayloadModeType.XML);
			// The DataModel contains FieldType values for each parameter we are passing
			DataModel model = DataModel.Factory.newInstance();
			// Add a new In/Out field type and set its name, the parameter name is defined in the service in Business Studio
			FieldType field = model.addNewInouts();
			field.setName("Parameter");
			// For the field we must set the simple value, in this case it is a simple field type
			SimpleSpec simpleSpec = field.addNewSimpleSpec();
			XmlString value = simpleSpec.addNewValue();
			value.setStringValue("Example Value");
			// Add the DataModel to the DataPayload
			payload.setXmlPayload(model);
			// Now we inject the event passing the event details, the data payload and the respose feed type
			InjectBusinessServiceEventResponse injectResponse = serviceConnectorInstance.getBusinessService()
					.injectBusinessServiceEvent(event, payload, PayloadModeType.XML);
		}
		catch (InternalServiceFault e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (InvalidArgumentFault e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (PageFlowExecutionFault e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}