java Java片段

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java Java片段相关的知识,希望对你有一定的参考价值。


import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
 
import javax.naming.Context;
 
import oracle.bpel.services.bpm.common.IBPMContext;
import oracle.bpel.services.workflow.client.IWorkflowServiceClientConstants;
 
import oracle.bpm.client.BPMServiceClientFactory;
import oracle.bpm.services.client.IBPMServiceClient;
import oracle.bpm.services.instancemanagement.IInstanceManagementService;
import oracle.bpm.services.instancemanagement.model.IProcessInstance;
 
import oracle.soa.management.facade.ComponentInstance;
import oracle.soa.management.facade.Locator;
import oracle.soa.management.facade.LocatorFactory;
import oracle.soa.management.util.ComponentInstanceFilter;
 
public class CancelBpmProcess {
public CancelBpmProcess() {
super();
}
 
public static void cancelProcess(String hostname, String port, String username, String password, String processID)
throws IllegalArgumentException, Exception
{
//Basic validations
if(hostname == null || hostname.isEmpty()){
throw new IllegalArgumentException("Invalid hostname");
}
if(port == null || port.isEmpty()){
throw new IllegalArgumentException("Invalid port");
}
if(username == null || username.isEmpty()){
throw new IllegalArgumentException("Invalid username");
}
if(password == null || password.isEmpty()){
throw new IllegalArgumentException("Invalid password");
}
if(processID == null || processID.isEmpty()){
throw new IllegalArgumentException("Invalid processID");
}
 
/**
* Step 1 - Retrieve the SOA Component instance representing the BPM process using the SOA Infrastructure API.
*
* SOA Infrastructure API Javadoc: http://docs.oracle.com/cd/E28389_01/apirefs.1111/e10659/index.html
*
**/
//Set up the SOA API connection properties
Hashtable jndiConfigProperties = new Hashtable();
jndiConfigProperties.put(Context.PROVIDER_URL, "t3://" + hostname + ":" + port + "/soa-infra");
jndiConfigProperties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
jndiConfigProperties.put(Context.SECURITY_PRINCIPAL, username);
jndiConfigProperties.put(Context.SECURITY_CREDENTIALS, password);
jndiConfigProperties.put("dedicated.connection", "true");
 
//Acquire the locator service
Locator locatorService = LocatorFactory.createLocator(jndiConfigProperties);
 
//Create the bpm component search filter
ComponentInstanceFilter searchFilter = new ComponentInstanceFilter();
searchFilter.setEngineType(Locator.SE_BPMN); //only BPM processes
searchFilter.setId("bpmn:" + processID);
 
//Retrieve the bpm component instance
List<ComponentInstance> bpmSoaComponents = locatorService.getComponentInstances(searchFilter);
if(bpmSoaComponents == null || bpmSoaComponents.isEmpty()){
throw new Exception("Bpm process " + processID + " was not found");
}
 
/**
* Step 2 - Find all BPM components (BPM Processes) under the same execution context as visually presented in the process audit trail.
*
* Using the SOA Infrastructure API we can find all BPM Components under the same execution context.
* This requires the execution  context id (ECID) which in this case will be retrived from the BPM component
* fetched in the previous step. There are other possibilities like a Human Task
* instance or a Composite instance (SOA Components).
*
*/
String ecid = bpmSoaComponents.get(0).getECID();
 
//BPM Component Instance Filter
searchFilter = new ComponentInstanceFilter();
searchFilter.setECID(ecid);
searchFilter.setEngineType(Locator.SE_BPMN); //only BPM processes
searchFilter.setNormalizedStates(new int[]{ComponentInstance.STATE_FAULTED,
ComponentInstance.STATE_RECOVERY_REQUIRED,
ComponentInstance.STATE_RUNNING});
searchFilter.setOrderBy(ComponentInstanceFilter.ORDER_BY_CREATION_DATE_DESC);
 
//Get the BPM components that can be cancelled (states above)
bpmSoaComponents = locatorService.getComponentInstances(searchFilter);
 
/**
* Step 3 - Cancel the BPM processes using the BPM API
*
* BPM API Javadoc: http://docs.oracle.com/cd/E23943_01/apirefs.1111/e25378/toc.htm)
*/
if(bpmSoaComponents != null && !bpmSoaComponents.isEmpty()){
//Set up the BPM API connection properties
Map<IWorkflowServiceClientConstants.CONNECTION_PROPERTY, String> properties = new HashMap<IWorkflowServiceClientConstants.CONNECTION_PROPERTY, String>();
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.CLIENT_TYPE, IWorkflowServiceClientConstants.CLIENT_TYPE_REMOTE);
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL, "t3://" + hostname + ":" + port);
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL, username);
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS, password);
 
//Aquire the service factory
BPMServiceClientFactory bpmSvcCliFactory = BPMServiceClientFactory.getInstance(properties, null, null);
if (bpmSvcCliFactory == null) {
throw new Exception("Bpm services unavailable.");
}
 
//Acquire the service client
IBPMServiceClient bpmSvcCli = bpmSvcCliFactory.getBPMServiceClient();
 
//Get the user BPM Context for the BPM API requests
IBPMContext userBpmContext = bpmSvcCliFactory.getBPMUserAuthenticationService().getBPMContextForAuthenticatedUser();
 
//Get the InstanceManagementService used to managed BPM process instances
IInstanceManagementService bpmInstanceManagementSvc = bpmSvcCli.getInstanceManagementService();
 
for(ComponentInstance bpmComponent : bpmSoaComponents){
//Get the BPM Process ID from the BPM component
int indexOfSeparator = bpmComponent.getId().indexOf(":"); //index of ':' => "bpmn:12345678"
processID = bpmComponent.getId().substring(indexOfSeparator + 1);
 
//Fetch the BPM Process Instance to cancel
IProcessInstance processInstance = bpmSvcCli.getInstanceQueryService().getProcessInstance(userBpmContext, processID);
 
//Cancel the instance
bpmInstanceManagementSvc.cancelProcessInstance(userBpmContext, processInstance);
 
System.out.println("BPM process " + processID + " was cancelled successfully");
}
}else{
System.out.println("No processes to cancel");
}
 
}
 
public static void main(String args[]){
String hostname = "";
String port = "";
 
//ser with admin privileges
String username = "";
String password = "";
 
String processID = "";
 
try{
CancelBpmProcess.cancelProcess(hostname, port, username, password, processID);
}catch(Exception e){
e.printStackTrace();
}
}
}

以上是关于java Java片段的主要内容,如果未能解决你的问题,请参考以下文章

java 代码片段【JAVA】

java Java片段

java [code-time] #java片段

如何使用java将数据从片段传递到android中的另一个片段?

java代码在片段活动中不起作用

java.lang.IllegalStateException:片段未附加到活动