Thursday, February 12, 2015

Oracle SOA : Get number of instances using SOA Facade api's


package com.raylabs.soa.management;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import javax.naming.Context;
import oracle.soa.management.facade.Composite;
import oracle.soa.management.facade.CompositeInstance;
import oracle.soa.management.facade.Locator;
import oracle.soa.management.facade.LocatorFactory;
import oracle.soa.management.util.CompositeFilter;
import oracle.soa.management.util.CompositeInstanceFilter;
public class GetNumberOfInstances {
public GetNumberOfInstances() {
super();
}
public static void main(String[] args) {
Locator loc = null;
try {
loc = LocatorFactory.createLocator(getConnectionDetails());
CompositeFilter compositeFilter = new CompositeFilter();
compositeFilter.setPartition("default");
//compositeFilter.setRevision("1.0");
List<Composite> composites = new ArrayList<Composite>();
composites = loc.getComposites(compositeFilter);
System.out.println("Number of Composites deployed :" +
composites.size());
Iterator compositesIterator = composites.iterator();
System.out.println("-----------------------------------------------------");
while (compositesIterator.hasNext()) {
Composite composite = (Composite)compositesIterator.next();
System.out.println("Composite Name :" +
composite.getCompositeDN().getCompositeName());
System.out.println("Composite Revsion :" +
composite.getCompositeDN().getRevision());
System.out.println("Total number of Instances :" +
composite.getInstanceCount());
CompositeInstanceFilter filter = new CompositeInstanceFilter();
//Running
filter.setState(CompositeInstance.STATE_RUNNING);
List<CompositeInstance> instancesRunning =
composite.getInstances(filter);
System.out.println("Total number of Running Instance :" +
instancesRunning.size());
filter.setState(CompositeInstance.STATE_COMPLETED_SUCCESSFULLY);
List<CompositeInstance> instancesCompleted =
composite.getInstances(filter);
System.out.println("Total number of Completed Instance :" +
instancesCompleted.size());
filter.setState(CompositeInstance.STATE_FAULTED);
List<CompositeInstance> instancesFaulted =
composite.getInstances(filter);
System.out.println("Total number of Faulted Instance :" +
instancesFaulted.size());
filter.setState(CompositeInstance.STATE_STALE);
List<CompositeInstance> instancesStale =
composite.getInstances(filter);
System.out.println("Total number of Stale Instance :" +
instancesStale.size());
filter.setState(CompositeInstance.STATE_SUSPENDED);
List<CompositeInstance> instancesSuspended =
composite.getInstances(filter);
System.out.println("Total number of Suspended Instance :" +
instancesSuspended.size());
filter.setState(CompositeInstance.STATE_UNKNOWN);
List<CompositeInstance> instancesUnknown =
composite.getInstances(filter);
System.out.println("Total number of Unknown state Instance :" +
instancesUnknown.size());
System.out.println("------------------------------------------");
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static Hashtable getConnectionDetails() {
Hashtable jndiProps = new Hashtable();
jndiProps.put(Context.PROVIDER_URL,
"t3://xxx:11234/soa-infra");
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
jndiProps.put(Context.SECURITY_PRINCIPAL, "xxx");
jndiProps.put(Context.SECURITY_CREDENTIALS, "xxxxxx");
jndiProps.put("dedicated.connection", "true");
return jndiProps;
}
}





Libraries


Oracle SOA : Get list of all faults in the SOA domain

Below is the code to get all faults given the filter criteria in the entire soa infra.

package com.raylabs.bpel;
import java.util.Calendar;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import javax.naming.Context;
import oracle.soa.management.facade.Fault;
import oracle.soa.management.facade.Locator;
import oracle.soa.management.facade.LocatorFactory;
import oracle.soa.management.util.FaultFilter;
public class Class1 {
public Class1() {
super();
}
public static void main(String[] args) {
Locator locator = null;
try{
locator = LocatorFactory.createLocator(getConnectionForLocator());
FaultFilter faultFilter = new FaultFilter();
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -30);
faultFilter.setMinCreationDate(cal.getTime());
//faultFilter.setRecoverable(true);
faultFilter.setPageSize(10);
List<Fault> list = locator.getFaults(faultFilter);
Iterator<Fault> faults = list.iterator();
while (faults.hasNext()) {
Fault fault = faults.next();
//if(fault.isRecoverable()){
System.out.println("Composite :" +
fault.getCompositeDN().getCompositeName());
System.out.println("Fault Description :" + fault.getName());
System.out.println("Fault ECID:" + fault.getECID());
System.out.println("Fault Composite instance id :" +
fault.getCompositeInstanceId());
if (fault.getType() == Fault.TYPE_BUSINESS_FAULT) {
System.out.println("BUSINESS_FAULT");
} else if (fault.getType() == Fault.TYPE_SYSTEM_FAULT) {
System.out.println("SYSTEM_FAULT");
} else if (fault.getType() == Fault.TYPE_POLICY_FAULT) {
System.out.println("POLICY_FAULT");
} else {
System.out.println("Unknown fault :" + fault.getType());
}
System.out.println("Message :" + fault.getMessage());
System.out.println("Created on :" + fault.getCreationDate());
if (fault.isRecoverable()) {
System.out.println("Recoverable");
} else {
System.out.println("Non Recoverable");
}
if (fault.isRejectedMessage()) {
System.out.println("Rejected Message");
}
System.out.println("--------------------------------------------");
// }
}
} catch (Exception e) {
System.out.println("Unknown Exception ");
e.printStackTrace();
} finally {
try {
locator.close();
System.out.println("Locator closed successfully");
} catch (Exception e) {
System.out.println("Exception while closing Locator handle");
e.printStackTrace();
}
}
}
public static Hashtable getConnectionForLocator() {
Hashtable jndiProps = new Hashtable();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
jndiProps.put(Context.PROVIDER_URL,
"t3://xxx:123123/soa-infra");
jndiProps.put(Context.SECURITY_PRINCIPAL, "xxx");
jndiProps.put(Context.SECURITY_CREDENTIALS, "xxxx");
jndiProps.put("dedicated.connection", "true");
return jndiProps;
}
}
view raw GetListOfFaults hosted with ❤ by GitHub


Libraries



Wednesday, February 11, 2015

Oracle BPM :Get list of Holiday Calendars and Working Calendar using BPM api's


package com.raylabs.bpm;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import oracle.bpel.services.bpm.common.IBPMContext;
import oracle.bpel.services.workflow.client.IWorkflowServiceClientConstants;
import oracle.bpel.services.workflow.client.WorkflowServiceClientFactory;
import oracle.bpm.client.BPMServiceClientFactory;
import oracle.bpm.services.client.IBPMServiceClient;
import oracle.bpm.services.organization.IBPMOrganizationService;
import oracle.bpm.services.organization.model.CalendarRule;
import oracle.bpm.services.organization.model.CalendarRules;
import oracle.bpm.services.organization.model.HolidayRule;
import oracle.bpm.services.organization.model.HolidayRules;
import oracle.bpm.services.organization.model.HolidayType;
import oracle.bpm.services.organization.model.Organization;
import oracle.bpm.services.organization.model.WeekDaysEnum;
import oracle.bpm.services.organization.model.WorkPeriodType;
import oracle.bpm.services.organization.model.WorkdayListType;
import oracle.bpm.services.organization.model.WorkdayType;
public class Class1 {
private static String username;
private static String password;
private static String environment;
private static String serverPort;
private Class1() {
super();
}
public static void main(String[] args) {
username = "xxx";
password = "xxx";
environment = "dev";
serverPort = "123";
BPMServiceClientFactory wfSvcClient = null;
IBPMContext bpmCtx = null;
IBPMServiceClient bPMServiceClient = null;
try {
final Map connectionProperty = getConnProp();
wfSvcClient =
BPMServiceClientFactory.getInstance(connectionProperty,
null, null);
bPMServiceClient = wfSvcClient.getBPMServiceClient();
IBPMOrganizationService bpmOrgSvc =
bPMServiceClient.getBPMOrganizationService();
bpmCtx =
(IBPMContext)wfSvcClient.getWorkflowServiceClient().getTaskQueryService().authenticate(null,
null,
null);
Organization org = bpmOrgSvc.exportOrganization(bpmCtx);
//Holiday Calendar
HolidayRules holidayRules = org.getHolidayRules();
List<HolidayRule> holidayRule = holidayRules.getHolidayRule();
Iterator<HolidayRule> iterator0 = holidayRule.iterator();
while (iterator0.hasNext()) {
HolidayRule next = iterator0.next();
System.out.println("Holiday calendar :" + next.getName());
List<HolidayType> holidays = next.getHolidays();
Iterator<HolidayType> iterator = holidays.iterator();
while (iterator.hasNext()) {
HolidayType holidayType = iterator.next();
System.out.println("Holiday name :" +
holidayType.getName() +
" Holiday date :" +
holidayType.getHolidayDate() +
" Holiday type :" +
holidayType.getHolidayPattern());
}
}
//Calendar rules
CalendarRules calendarRules = org.getCalendarRules();
List<CalendarRule> calendarRule = calendarRules.getCalendarRule();
Iterator<CalendarRule> iterator = calendarRule.iterator();
while (iterator.hasNext()) {
CalendarRule next = iterator.next();
System.out.println("Working Calendar :" + next.getName());
System.out.println("Holdiay Calendar associated with the Working Calendar :" +
next.getHolidayRuleName());
WorkdayListType list = next.getWorkdayList();
List<WorkdayType> workday = list.getWorkday();
Iterator<WorkdayType> iterator1 = workday.iterator();
while (iterator1.hasNext()) {
WorkdayType type = iterator1.next();
WeekDaysEnum day = type.getWeekDay();
System.out.println("Working days " + day);
List<WorkPeriodType> period = type.getWorkPeriod();
Iterator<WorkPeriodType> iterator2 = period.iterator();
while (iterator2.hasNext()) {
WorkPeriodType periodType = iterator2.next();
System.out.println("Start time :" +
periodType.getStartTime() +
" End time " +
periodType.getEndTime());
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
}
}
public static Map getConnProp() throws Exception {
final Map connProp = new HashMap();
try {
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL,
"t3://" + environment +
"-abc.com:" + serverPort);
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL,
username);
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS,
password);
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.CLIENT_TYPE,
WorkflowServiceClientFactory.REMOTE_CLIENT);
} catch (Exception e) {
e.printStackTrace();
}
return connProp;
}
}



Oracle BPM : Get Extended User Properties using BPM API's

The below code retrieves the list of parametric values and its properties.

package com.raylabs.bpm;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import oracle.bpel.services.bpm.common.IBPMContext;
import oracle.bpel.services.workflow.client.IWorkflowServiceClientConstants;
import oracle.bpel.services.workflow.client.WorkflowServiceClientFactory;
import oracle.bpm.client.BPMServiceClientFactory;
import oracle.bpm.services.client.IBPMServiceClient;
import oracle.bpm.services.organization.IBPMOrganizationService;
import oracle.bpm.services.organization.model.Organization;
import oracle.bpm.services.organization.model.ParticipantProperties;
import oracle.bpm.services.organization.model.ParticipantPropertiesList;
import oracle.bpm.services.organization.model.ParticipantProperty;
import oracle.bpm.services.organization.model.PrincipleRefType;
public class Class1 {
private static String username;
private static String password;
private static String environment;
private static String serverPort;
private Class1() {
super();
}
public static void main(String[] args) {
username = "xxx";
password = "xx";
environment = "dev";
serverPort = "12121";
BPMServiceClientFactory wfSvcClient = null;
IBPMContext bpmCtx = null;
IBPMServiceClient bPMServiceClient = null;
try {
final Map connectionProperty = getConnProp();
wfSvcClient =
BPMServiceClientFactory.getInstance(connectionProperty,
null, null);
bPMServiceClient = wfSvcClient.getBPMServiceClient();
IBPMOrganizationService bpmOrgSvc =
bPMServiceClient.getBPMOrganizationService();
bpmCtx =
(IBPMContext)wfSvcClient.getWorkflowServiceClient().getTaskQueryService().authenticate(null,
null,
null);
Organization org = bpmOrgSvc.exportOrganization(bpmCtx);
ParticipantPropertiesList list = org.getParticipantPropertiesList();
List<ParticipantProperties> participantProperties = list.getParticipantProperties();
Iterator<ParticipantProperties> iterator = participantProperties.iterator();
while(iterator.hasNext()){
ParticipantProperties next = iterator.next();
PrincipleRefType participant = next.getParticipant();
System.out.println("Particpant name :"+participant.getName());
System.out.println("Participant type :"+participant.getType());
List<ParticipantProperty> participantProperty = next.getParticipantProperty();
Iterator<ParticipantProperty> iterator1 = participantProperty.iterator();
while(iterator1.hasNext()){
ParticipantProperty property = iterator1.next();
// System.out.println("Property name: "+property.getName());
List<Object> value = property.getValue();
for(int i=0;i<value.size();i++){
String name= (String)value.get(i);
System.out.println("Property name :"+property.getName()+" Property value :"+name);
}
}
System.out.println("---------------------------------------------");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
}
}
public static Map getConnProp() throws Exception {
final Map connProp = new HashMap();
try {
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL,
"t3://" + environment +
"-abc.com:" + serverPort);
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL,
username);
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS,
password);
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.CLIENT_TYPE,
WorkflowServiceClientFactory.REMOTE_CLIENT);
} catch (Exception e) {
e.printStackTrace();
}
return connProp;
}
}


Libraries :


Oracle BPM : Get List of Parametric roles using BPM api's

package com.raylabs.bpm;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import oracle.bpel.services.bpm.common.IBPMContext;
import oracle.bpel.services.workflow.client.IWorkflowServiceClientConstants;
import oracle.bpel.services.workflow.client.WorkflowServiceClientFactory;
import oracle.bpm.client.BPMServiceClientFactory;
import oracle.bpm.services.client.IBPMServiceClient;
import oracle.bpm.services.organization.IBPMOrganizationService;
import oracle.bpm.services.organization.model.LogicalPeopleGroup;
import oracle.bpm.services.organization.model.LogicalPeopleGroupList;
import oracle.bpm.services.organization.model.Organization;
import oracle.bpm.services.organization.model.ParameterListType;
import oracle.bpm.services.organization.model.ParameterType;
import oracle.bpm.services.organization.model.PeopleQueryType;
public class Class1 {
private static String username;
private static String password;
private static String environment;
private static String serverPort;
private static String user;
private static String role;
private Class1() {
super();
}
public static void main(String[] args) {
username = "xxx";
password = "xxxx";
environment = "dev";
serverPort = "232232";
BPMServiceClientFactory wfSvcClient = null;
IBPMContext bpmCtx = null;
IBPMServiceClient bPMServiceClient = null;
try {
final Map connectionProperty = getConnProp();
wfSvcClient =
BPMServiceClientFactory.getInstance(connectionProperty,
null, null);
bPMServiceClient = wfSvcClient.getBPMServiceClient();
IBPMOrganizationService bpmOrgSvc =
bPMServiceClient.getBPMOrganizationService();
bpmCtx =
(IBPMContext)wfSvcClient.getWorkflowServiceClient().getTaskQueryService().authenticate(null,
null,
null);
Organization org = bpmOrgSvc.exportOrganization(bpmCtx);
LogicalPeopleGroupList groupList = org.getLogicalPeopleGroupList();
List<LogicalPeopleGroup> group = groupList.getLogicalPeopleGroup();
Iterator<LogicalPeopleGroup> iterator = group.iterator();
while (iterator.hasNext()) {
LogicalPeopleGroup logicalPeopleGroup = iterator.next();
System.out.println("Parametric roles :" +
logicalPeopleGroup.getName());
PeopleQueryType peopleQuery =
logicalPeopleGroup.getPeopleQuery();
//Parameters
ParameterListType listType = peopleQuery.getParameters();
List<ParameterType> list = listType.getParameter();
Iterator<ParameterType> iterator1 = list.iterator();
while (iterator1.hasNext()) {
ParameterType parmeter = iterator1.next();
System.out.println("Parmeter name :" + parmeter.getName() +
" Parameter type :" +
parmeter.getType());
}
//Predicate
//PredicateType predicate = peopleQuery.getPredicate();
System.out.println("------------------------------------");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
}
}
public static Map getConnProp() throws Exception {
final Map connProp = new HashMap();
try {
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL,
"t3://" + environment +
"-abc.com:" + serverPort);
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL,
username);
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS,
password);
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.CLIENT_TYPE,
WorkflowServiceClientFactory.REMOTE_CLIENT);
} catch (Exception e) {
e.printStackTrace();
}
return connProp;
}
}

Libraries :


Oracle BPM : Assign or Remove user from Application role using BPM api's

Below is the java code to assign or remove user from a role , same functionality is present in bpm workspace admin.


package com.raylabs.bpm;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import oracle.bpel.services.bpm.common.IBPMContext;
import oracle.bpel.services.workflow.client.IWorkflowServiceClientConstants;
import oracle.bpel.services.workflow.client.WorkflowServiceClientFactory;
import oracle.bpm.client.BPMServiceClientFactory;
import oracle.bpm.services.client.IBPMServiceClient;
import oracle.bpm.services.organization.IBPMOrganizationService;
import oracle.bpm.services.organization.model.AppRoleRefType;
import oracle.bpm.services.organization.model.ApplicationContext;
import oracle.bpm.services.organization.model.ApplicationContextTypeEnum;
import oracle.bpm.services.organization.model.ApplicationRoleType;
import oracle.bpm.services.organization.model.ApplicationRoles;
import oracle.bpm.services.organization.model.Organization;
import oracle.bpm.services.organization.model.Participant;
import oracle.bpm.services.organization.model.ParticipantTypeEnum;
public class Class1 {
private static String username;
private static String password;
private static String environment;
private static String serverPort;
private static String user;
private static String role;
private Class1() {
super();
}
public static void main(String[] args) {
username = "xx";
password = "xxxx";
environment = "dev";
serverPort = "34444";
user = "xxxx";
role = "APPROVER";
BPMServiceClientFactory wfSvcClient = null;
IBPMContext bpmCtx = null;
IBPMServiceClient bPMServiceClient = null;
try {
final Map connectionProperty = getConnProp();
wfSvcClient =
BPMServiceClientFactory.getInstance(connectionProperty,
null, null);
bPMServiceClient = wfSvcClient.getBPMServiceClient();
IBPMOrganizationService bpmOrgSvc =
bPMServiceClient.getBPMOrganizationService();
bpmCtx =
(IBPMContext)wfSvcClient.getWorkflowServiceClient().getTaskQueryService().authenticate(null,
null,
null);
Organization org = bpmOrgSvc.exportOrganization(bpmCtx);
ApplicationRoles applicationRoles = org.getApplicationRoles();
List<ApplicationRoleType> roleList =
applicationRoles.getApplicationRole();
Iterator<ApplicationRoleType> iterator = roleList.iterator();
while (iterator.hasNext()) {
ApplicationRoleType applicationRoleType = iterator.next();
if (applicationRoleType.getName().equals(role)) {
ApplicationContext appContext = new ApplicationContext();
appContext.setApplicationType(ApplicationContextTypeEnum.ORACLE_BPM_PROCESS_ROLES_APP);
AppRoleRefType appRole = new AppRoleRefType();
appRole.setType(ParticipantTypeEnum.USER);
appRole.setName(user);
bpmOrgSvc.grantAppRoleToPrincipal(bpmCtx, appContext, role,
new Participant(appRole));
System.out.println("Added user " + user + " to Role " +
role);
// bpmOrgSvc.revokeAppRoleFromPrincipal(bpmCtx, appContext, role, new Participant(appRole));
// System.out.println("Removed user "+user+" from Role "+role);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
}
}
public static Map getConnProp() throws Exception {
final Map connProp = new HashMap();
try {
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL,
"t3://" + environment +
"-abc.com:" + serverPort);
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL,
username);
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS,
password);
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.CLIENT_TYPE,
WorkflowServiceClientFactory.REMOTE_CLIENT);
} catch (Exception e) {
e.printStackTrace();
}
return connProp;
}
}


Libraries

Oracle BPM : Get list of roles and its corresponding users using BPM Api

Get list of Roles and users using the below code.


package com.raylabs.bpm;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import oracle.bpel.services.bpm.common.IBPMContext;
import oracle.bpel.services.workflow.client.IWorkflowServiceClientConstants;
import oracle.bpel.services.workflow.client.WorkflowServiceClientFactory;
import oracle.bpm.client.BPMServiceClientFactory;
import oracle.bpm.services.client.IBPMServiceClient;
import oracle.bpm.services.organization.IBPMOrganizationService;
import oracle.bpm.services.organization.model.ApplicationRoleType;
import oracle.bpm.services.organization.model.ApplicationRoles;
import oracle.bpm.services.organization.model.Organization;
import oracle.bpm.services.organization.model.PrincipleRefType;
public class Class1 {
private static String username;
private static String password;
private static String environment;
private static String serverPort;
private Class1() {
super();
}
public static void main(String[] args) {
username="xxx";
password="xxx";
environment="dev";
serverPort="7009";
BPMServiceClientFactory wfSvcClient = null;
IBPMContext bpmCtx = null;
IBPMServiceClient bPMServiceClient = null;
try {
final Map connectionProperty = getConnProp();
wfSvcClient =
BPMServiceClientFactory.getInstance(connectionProperty,
null, null);
bPMServiceClient = wfSvcClient.getBPMServiceClient();
IBPMOrganizationService bpmOrgSvc =
bPMServiceClient.getBPMOrganizationService();
bpmCtx =
(IBPMContext)wfSvcClient.getWorkflowServiceClient().getTaskQueryService().authenticate(null,
null,
null);
Organization org = bpmOrgSvc.exportOrganization(bpmCtx);
ApplicationRoles applicationRoles = org.getApplicationRoles();
List<ApplicationRoleType> roleList =
applicationRoles.getApplicationRole();
for (ApplicationRoleType role : roleList) {
System.out.println("Role name :" + role.getName());
System.out.println("Identity context :"+role.getIdentityContext());
System.out.println("List of users for the role :");
List<PrincipleRefType> list = role.getMember();
for(PrincipleRefType users:list){
System.out.println(users.getType()+"-->"+users.getName());
}
System.out.println("------------------------------------------");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
}
}
public static Map getConnProp() throws Exception {
final Map connProp = new HashMap();
try {
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL,
"t3://"+environment+".abc.com:"+serverPort);
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL,
username);
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS,
password);
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.CLIENT_TYPE,
WorkflowServiceClientFactory.REMOTE_CLIENT);
} catch (Exception e) {
e.printStackTrace();
}
return connProp;
}
}

Libraries




Tuesday, February 10, 2015

Oracle SOA : Get Number of messages in JMS using JMX api's

Below is the java code to get Number of messages in JMS using JMX api's


package com.raylabs.jmx;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.naming.Context;
public class Class1 {
public Class1() {
super();
}
public static void main(String[] args) {
String environment = "dev";
String userName = "xxx";
String password = "xxx";
List jmsDestinations=new ArrayList();
jmsDestinations.add("topic1");
jmsDestinations.add("queu1");
jmsDestinations.add("topic2");
JMXConnector connector = null;
String node1BPMHostname =
environment + "-node1BPM.com";
String node1BPMPort = "7002";
String node2BPMHostname =
environment + "-node2BPM.com";
String node2BPMPort = "7002";
String node1SOAHostname =
environment + "-node1SOA";
String node1SOAPort = "7002";
String node2SOAHostname =
environment + "-node2SOA";
String node2SOAPort = "7002";
List server = new ArrayList();
server.add(node1BPMHostname + ":" + node1BPMPort);
server.add(node2BPMHostname + ":" + node2BPMPort);
server.add(node1SOAHostname + ":" + node1SOAPort);
server.add(node2SOAHostname + ":" + node2SOAPort);
System.out.println("Environment : "+environment);
for (int i = 0; i < server.size(); i++) {
try {
ObjectName SERVICE =
new ObjectName("com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean");
Map<String, String> map = new HashMap<String, String>();
map.put(Context.SECURITY_PRINCIPAL, userName);
map.put(Context.SECURITY_CREDENTIALS, password);
map.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,
"weblogic.management.remote");
map.put("jmx.remote.x.request.waiting.timeout", "20000");
JMXServiceURL url =
new JMXServiceURL("service:jmx:t3://" + (String)server.get(i) +
"/jndi/weblogic.management.mbeanservers.runtime");
connector = JMXConnectorFactory.connect(url, map);
MBeanServerConnection connection =
connector.getMBeanServerConnection();
ObjectName serverRuntimeMBean =
(ObjectName)connection.getAttribute(SERVICE,
"ServerRuntime");
String serverName =
(String)connection.getAttribute(serverRuntimeMBean,
"Name");
System.out.println("Server name :" + serverName);
String listenAddress =
(String)connection.getAttribute(serverRuntimeMBean,
"ListenAddress");
System.out.println("Listen Address : " + listenAddress);
ObjectName jmsRuntimeMbean =
(ObjectName)connection.getAttribute(serverRuntimeMBean,
"JMSRuntime");
ObjectName[] jmsServerRuntimeMbeans =
(ObjectName[])connection.getAttribute(jmsRuntimeMbean,
"JMSServers");
for (ObjectName jmsServerRuntime : jmsServerRuntimeMbeans) {
ObjectName[] jmsDestinationRuntimeMbeans =
(ObjectName[])connection.getAttribute(jmsServerRuntime,
"Destinations");
for (ObjectName jmsDestinationRuntime :
jmsDestinationRuntimeMbeans) {
String destinationName =
(String)connection.getAttribute(jmsDestinationRuntime,
"Name");
if (destinationName.split("@").length == 2) {
destinationName =
destinationName.split("@")[1];
}
if (destinationName.split("!").length == 2) {
destinationName =
destinationName.split("!")[1];
}
// Specified topics and QUeues
if (jmsDestinations.contains(destinationName)) {
// All topics and QUeues
// if (1==1) {
System.out.println(destinationName);
//The current number of messages in the destination. This does not include the pending messages.
long messagesCurrentCount =
(Long)connection.getAttribute(jmsDestinationRuntime,
"MessagesCurrentCount");
System.out.println("messagesCurrentCount " +
messagesCurrentCount);
//Pending messages are over and above the current number of messages.
//A pending message is one that has either been sent in a transaction and not committed, or that has been received and not committed or acknowledged.
long messagesPendingCount =
(Long)connection.getAttribute(jmsDestinationRuntime,
"MessagesPendingCount");
System.out.println("messagesPendingCount " +
messagesPendingCount);
//The current number of consumers accessing this destination
long consumersCurrentCount =
(Long)connection.getAttribute(jmsDestinationRuntime,
"ConsumersCurrentCount");
System.out.println("consumersCurrentCount " +
consumersCurrentCount);
System.out.println("--------------------------------------------------");
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
connector.close();
System.out.println("Connection closed");
System.out.println("---------------------------------------------------------------");
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}




Libraries


Oracle SOA : Get server health data using JMX api's

Below is the java code to retrieve server health data using JMX api's

package com.raylabs.jmx;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.naming.Context;
import weblogic.health.HealthState;
public class Class1 {
public Class1() {
super();
}
public static void main(String[] args) {
String environment = "dev";
JMXConnector connector = null;
String userName = "xxx";
String password = "xxxxxx";
String adminBPMHostname =
environment + "-admin.com";
String adminBPMPort = "7001";
String node1BPMHostname =
environment + "-node1.com";
String node1BPMPort = "7002";
String node2BPMHostname =
environment + "-node1.com";
String node2BPMPort = "7002";
String adminSOAHostname =
environment + "-admins.com";
String adminSOAPort = "7001";
String node1SOAHostname =
environment + "-node1s.com";
String node1SOAPort = "7002";
String node2SOAHostname =
environment + "-node2s.com";
String node2SOAPort = "7002";
List server = new ArrayList();
server.add(adminBPMHostname + ":" + adminBPMPort);
server.add(node1BPMHostname + ":" + node1BPMPort);
server.add(node2BPMHostname + ":" + node2BPMPort);
server.add(adminSOAHostname + ":" + adminSOAPort);
server.add(node1SOAHostname + ":" + node1SOAPort);
server.add(node2SOAHostname + ":" + node2SOAPort);
for (int i = 0; i < server.size(); i++) {
try {
ObjectName SERVICE =
new ObjectName("com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean");
Map<String, String> map = new HashMap<String, String>();
map.put(Context.SECURITY_PRINCIPAL, userName);
map.put(Context.SECURITY_CREDENTIALS, password);
map.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,
"weblogic.management.remote");
map.put("jmx.remote.x.request.waiting.timeout", "20000");
JMXServiceURL url =
new JMXServiceURL("service:jmx:t3://" + (String)server.get(i) +
"/jndi/weblogic.management.mbeanservers.runtime");
connector = JMXConnectorFactory.connect(url, map);
MBeanServerConnection connection =
connector.getMBeanServerConnection();
ObjectName serverRuntimeMBean =
(ObjectName)connection.getAttribute(SERVICE,
"ServerRuntime");
System.out.println("Environment :" + environment);
String serverName =
(String)connection.getAttribute(serverRuntimeMBean,
"Name");
System.out.println("Server name :" + serverName);
String state =
(String)connection.getAttribute(serverRuntimeMBean,
"State");
System.out.println("Server State : " + state);
String listenAddress =
(String)connection.getAttribute(serverRuntimeMBean,
"ListenAddress");
System.out.println("Listen Address : " + listenAddress);
Integer listenPort =
(Integer)connection.getAttribute(serverRuntimeMBean,
"ListenPort");
System.out.println("Listen Port : " + listenPort);
HealthState health =
(HealthState)connection.getAttribute(serverRuntimeMBean,
"HealthState");
int serverState = health.getState();
if (serverState == HealthState.HEALTH_CRITICAL) {
System.out.println("Health : HEALTH_CRITICAL");
} else if (serverState == HealthState.HEALTH_FAILED) {
System.out.println("Health : HEALTH_FAILED");
} else if (serverState == HealthState.HEALTH_OK) {
System.out.println("Health : HEALTH_OK");
} else if (serverState == HealthState.HEALTH_OVERLOADED) {
System.out.println("Health : HEALTH_OK");
} else if (serverState == HealthState.HEALTH_WARN) {
System.out.println("Health : HEALTH_WARN");
} else {
System.out.println("Health : UNDEFINED");
}
// String dir= (String)connection.getAttribute(serverRuntimeMBean, "CurrentDirectory");
// System.out.println("Current directory :"+dir);
ObjectName jvm =
(ObjectName)connection.getAttribute(serverRuntimeMBean,
"JVMRuntime");
Long totalHeap =
(Long)connection.getAttribute(jvm, "TotalHeap");
System.out.println("TotalHeap free:" +
bytesToString(totalHeap));
Long freeHeap = (Long)connection.getAttribute(jvm, "FreeHeap");
System.out.println("Free Heap:" + bytesToString(freeHeap));
Long usedHeap = (Long)connection.getAttribute(jvm, "UsedHeap");
System.out.println("Used Heap:" + bytesToString(usedHeap));
Long totalPhysicalMemory =
(Long)connection.getAttribute(jvm, "TotalPhysicalMemory");
System.out.println("Total Physical Memory:" +
bytesToString(totalPhysicalMemory));
Long usedPhysicalMemory =
(Long)connection.getAttribute(jvm, "UsedPhysicalMemory");
System.out.println("Used Physical Memory:" +
bytesToString(usedPhysicalMemory));
Integer totalThreads =
(Integer)connection.getAttribute(jvm, "TotalNumberOfThreads");
System.out.println("Total threads:" + totalThreads);
Integer daemonThreads =
(Integer)connection.getAttribute(jvm, "NumberOfDaemonThreads");
System.out.println("Daemon threads:" + daemonThreads);
Double processorLoad =
(Double)connection.getAttribute(jvm, "AllProcessorsAverageLoad");
System.out.println("Processor Load:" + processorLoad * 100 +
"%");
Double jvmLoad =
(Double)connection.getAttribute(jvm, "JvmProcessorLoad");
System.out.println("JVM Load:" + jvmLoad * 100 + "%");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
connector.close();
System.out.println("Connection closed");
System.out.println("---------------------------------------------------------------");
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static String bytesToString(long size) {
long Kb = 1 * 1024;
long Mb = Kb * 1024;
long Gb = Mb * 1024;
long Tb = Gb * 1024;
long Pb = Tb * 1024;
long Eb = Pb * 1024;
if (size < Kb)
return floatForm(size) + " byte";
if (size >= Kb && size < Mb)
return floatForm((double)size / Kb) + " Kb";
if (size >= Mb && size < Gb)
return floatForm((double)size / Mb) + " Mb";
if (size >= Gb && size < Tb)
return floatForm((double)size / Gb) + " Gb";
if (size >= Tb && size < Pb)
return floatForm((double)size / Tb) + " Tb";
if (size >= Pb && size < Eb)
return floatForm((double)size / Pb) + " Pb";
if (size >= Eb)
return floatForm((double)size / Eb) + " Eb";
return "???";
}
public static String floatForm(double d) {
return new DecimalFormat("#.##").format(d);
}
}
view raw GetServerHealth hosted with ❤ by GitHub



Libraries


Friday, February 6, 2015

Oracle SOA BPM : Get list of faulted BPMN instances using SOA managment API's

Below is the code to get list of BPMN instances which are faulted.

package com.raylabs.bpel;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import javax.naming.Context;
import oracle.soa.management.facade.Locator;
import oracle.soa.management.facade.LocatorFactory;
import oracle.soa.management.util.MessageFilter;
import oracle.soa.management.facade.bpm.BPMInvokeMessage;
import oracle.soa.management.facade.bpmn.BPMNServiceEngine;
public class Class1 {
public Class1() {
super();
}
public static void main(String[] args) {
Locator locator = null;
BPMNServiceEngine mBPMNServiceEngine;
Map<Integer, String> states = new HashMap<Integer, String>();
states.put(0, "Undelivered");
states.put(1, "Resolved");
states.put(2, "delivered");
states.put(3, "Cancelled");
states.put(4, "Exhausted");
try {
locator = LocatorFactory.createLocator(getConnectionForLocator());
mBPMNServiceEngine =
(BPMNServiceEngine)locator.getServiceEngine(Locator.SE_BPMN);
MessageFilter filter = new MessageFilter();
// 0 for Undelivered
// 1 for Resolved
// 2 for delivered
// 3 for Cancelled
// 4 for exhausted
int[] state = { 0, 3, 4 };
filter.setStates(state);
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -10);
filter.setMinCreationDate(cal.getTime());
List<BPMInvokeMessage> recoverable =
mBPMNServiceEngine.getInvokeMessages(filter);
ListIterator it = recoverable.listIterator();
while (it.hasNext()) {
BPMInvokeMessage instance = (BPMInvokeMessage)it.next();
System.out.println("Composite name :" +
instance.getCompositeDN());
System.out.println("ECID :" + instance.getEcid());
System.out.println("State :" +
states.get(instance.getState()));
System.out.println("Conversation id :" +
instance.getConversationId());
System.out.println("------------------------------------");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
locator.close();
}
}
public static Hashtable getConnectionForLocator() {
Hashtable jndiProps = new Hashtable();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
jndiProps.put(Context.PROVIDER_URL,
"t3://xxxxxx:1234/soa-infra");
jndiProps.put(Context.SECURITY_PRINCIPAL, "xxxx");
jndiProps.put(Context.SECURITY_CREDENTIALS, "xxxxxxx");
jndiProps.put("dedicated.connection", "true");
return jndiProps;
}
}


Libraries :


Oracle SOA : Get list of instances that are recoverable using SOA managment api's Ver2

There are five message states

1. Undelivered
2. Resolved
3. Delivered
4. Cancelled
5. Exhausted

The int value for the above state is as below
0 for Undelivered
1 for Resolved
2 for delivered
3 for Cancelled
4 for exhausted
This is set in the mfilter.setState(0);


package com.raylabs.bpel;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import javax.naming.Context;
import oracle.soa.management.facade.Locator;
import oracle.soa.management.facade.LocatorFactory;
import oracle.soa.management.facade.bpel.BPELServiceEngine;
import oracle.soa.management.util.MessageFilter;
import oracle.soa.management.facade.bpm.BPMInvokeMessage;
public class Class1 {
public Class1() {
super();
}
public static void main(String[] args) {
Locator locator = null;
BPELServiceEngine mBPELServiceEngine = null;
MessageFilter mfilter = null;
Map<Integer,String> states=new HashMap<Integer,String>();
states.put(0, "Undelivered");
states.put(1, "Resolved");
states.put(2, "delivered");
states.put(3, "Cancelled");
states.put(4, "exhausted");
try {
try {
locator =
LocatorFactory.createLocator(getConnectionForLocator());
System.out.println("Got locator succesfully ");
} catch (Exception e) {
System.out.println("Exception while getting locator");
e.printStackTrace();
}
try {
mBPELServiceEngine =
(BPELServiceEngine)locator.getServiceEngine(Locator.SE_BPEL);
System.out.println("Got BPELServiceEngine handle succesfully ");
} catch (Exception e) {
System.out.println("Exception BPELServiceEngine handle ");
e.printStackTrace();
}
mfilter = new MessageFilter();
// 0 for Undelivered
// 1 for Resolved
// 2 for delivered
// 3 for Cancelled
// 4 for exhausted
int state[]={0,3,4};
mfilter.setStates(state);
Calendar cal=Calendar.getInstance();
cal.add(Calendar.DATE,-30);
mfilter.setMinCreationDate(cal.getTime());
List<BPMInvokeMessage> recoverable;
try {
recoverable = mBPELServiceEngine.getInvokeMessages(mfilter);
ListIterator it = recoverable.listIterator();
System.out.println(recoverable.size());
while (it.hasNext()) {
BPMInvokeMessage invokemsg = (BPMInvokeMessage)it.next();
System.out.println("Composite instance :"+invokemsg.getCompositeDN());
System.out.println("ECID :"+invokemsg.getEcid());
System.out.println("State : "+states.get(invokemsg.getState()));
}
} catch (Exception e) {
System.out.println("Exception while getting recoverable instances");
e.printStackTrace();
}
} catch (Exception e) {
System.out.println("Unknown Exception ");
e.printStackTrace();
} finally {
try {
locator.close();
System.out.println("Locator closed successfully");
} catch (Exception e) {
System.out.println("Exception while closing Locator handle");
e.printStackTrace();
}
}
}
public static Hashtable getConnectionForLocator() {
Hashtable jndiProps = new Hashtable();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
jndiProps.put(Context.PROVIDER_URL,
"t3://xxx:1234/soa-infra");
jndiProps.put(Context.SECURITY_PRINCIPAL, "xxx");
jndiProps.put(Context.SECURITY_CREDENTIALS, "xxxx");
jndiProps.put("dedicated.connection", "true");
return jndiProps;
}
}


Jdev libraries



Note :
If you get "org.omg.CORBA.MARSHAL:   vmcid: 0x0  minor code: 0  completed: No" exceptions then use weblogic.jar instead of wlclient.jar

Oracle SOA : Get Composite instance details based on Sensor value

Below is the java code to retrieve composite instance data based on sensor value.


package com.raylabs.soa.management;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import javax.naming.Context;
import oracle.soa.management.facade.CompositeInstance;
import oracle.soa.management.facade.Locator;
import oracle.soa.management.facade.LocatorFactory;
import oracle.soa.management.facade.Sensor;
import oracle.soa.management.util.CompositeInstanceFilter;
import oracle.soa.management.util.Operator;
import oracle.soa.management.util.SensorFilter;
public class Class1 {
public Class1() {
super();
}
public static void main(String[] args) {
Locator loc = null;
String sensorValue = "9004";
try {
loc = LocatorFactory.createLocator(getConnectionDetails());
CompositeInstanceFilter compInstFilter =
new CompositeInstanceFilter();
SensorFilter sensorFilter =
new SensorFilter("SENSOR_NAME", Sensor.SensorDataType.STRING,
Operator.EQUALS, sensorValue);
List<SensorFilter> sensorFilters = new ArrayList<SensorFilter>();
sensorFilters.add(sensorFilter);
compInstFilter.setSensorFilter(sensorFilters);
List<CompositeInstance> compositeInstances =
loc.getCompositeInstances(compInstFilter);
System.out.println(compositeInstances.size());
Iterator compIterator = compositeInstances.iterator();
while (compIterator.hasNext()) {
CompositeInstance instance =
(CompositeInstance)compIterator.next();
System.out.println("Composite name :" +
instance.getCompositeDN().getCompositeName());
System.out.println("Composite domain name :" +
instance.getCompositeDN().getStringDN());
System.out.println("Composite instance id :" +
instance.getId());
System.out.println("ECID :"+instance.getECID());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
loc.close();
}
}
private static Hashtable getConnectionDetails() {
Hashtable jndiProps = new Hashtable();
jndiProps.put(Context.PROVIDER_URL,
"t3://xxxxx:1234/soa-infra");
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
jndiProps.put(Context.SECURITY_PRINCIPAL, "xxx");
jndiProps.put(Context.SECURITY_CREDENTIALS, "xxxxxxx");
jndiProps.put("dedicated.connection", "true");
return jndiProps;
}
}

Libraries

Oracle SOA : Getting default revision and deployment times from SOA managment api's

Below is the code to retrieve default revision and deployment dates for a given composite.
Other operations that you can perform is
1. activate();
2. getFaultCount();
3. getInstanceCount();
4. isShutdown();
5.retire();
6.setAsDefaultRevision();
7.start();
8.stop();

package com.raylabs.soa.management;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import javax.naming.Context;
import oracle.soa.management.facade.Composite;
import oracle.soa.management.facade.Locator;
import oracle.soa.management.facade.LocatorFactory;
import oracle.soa.management.util.CompositeFilter;
public class Class1 {
public Class1() {
super();
}
public static void main(String[] args) {
Locator loc = null;
try {
loc = LocatorFactory.createLocator(getConnectionDetails());
CompositeFilter compositeFilter = new CompositeFilter();
compositeFilter.setPartition("default");
List<Composite> composites = new ArrayList<Composite>();
composites = loc.getComposites(compositeFilter);
Iterator compositesIterator = composites.iterator();
while (compositesIterator.hasNext()) {
Composite composite = (Composite)compositesIterator.next();
if (composite.isDefaultRevision()) {
System.out.println("Composite name :" +
composite.getCompositeDN().getCompositeName());
System.out.println("Composite revision :" +
composite.getCompositeDN().getRevision());
System.out.println("Deployment time :" +
composite.getDeploymentTime());
System.out.println("Composite Domain Name :" +
composite.getDN());
System.out.println("-------------------------------------------------");
// Options avaiable are
//composite.activate();
// composite.getDeploymentTime();
// composite.getFaultCount();
// composite.getInstanceCount();
// composite.isDefaultRevision();
// composite.isShutdown();
// composite.retire();
// composite.setAsDefaultRevision();
// composite.start();
// composite.stop();
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
loc.close();
}
}
private static Hashtable getConnectionDetails() {
Hashtable jndiProps = new Hashtable();
jndiProps.put(Context.PROVIDER_URL,
"t3://xxxxxxx:1234/soa-infra");
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
jndiProps.put(Context.SECURITY_PRINCIPAL, "xxxxx");
jndiProps.put(Context.SECURITY_CREDENTIALS, "xxxxxx");
jndiProps.put("dedicated.connection", "true");
return jndiProps;
}
}


Libraries


Thursday, February 5, 2015

Oracle SOA : Get composite instance state using SOA Management api's

The below code is used to get composite instances state

package com.raylabs.soa.management;
import java.util.Calendar;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import javax.naming.Context;
import oracle.soa.management.facade.CompositeInstance;
import oracle.soa.management.facade.Locator;
import oracle.soa.management.facade.LocatorFactory;
import oracle.soa.management.util.CompositeInstanceFilter;
public class Class1 {
public Class1() {
super();
}
public static void main(String[] args) {
Locator loc = null;
try {
loc = LocatorFactory.createLocator(getConnectionDetails());
CompositeInstanceFilter compositeInFilter =
new CompositeInstanceFilter();
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MINUTE, -5);
compositeInFilter.setMinCreationDate(cal.getTime());
//compositeInFilter.setState(2);
List<CompositeInstance> compositeInstances =
loc.getCompositeInstances(compositeInFilter);
System.out.println(compositeInstances.size());
Iterator compositeInstancesIterator =
compositeInstances.iterator();
while (compositeInstancesIterator.hasNext()) {
CompositeInstance compositeInstance =
(CompositeInstance)compositeInstancesIterator.next();
System.out.println(compositeInstance.getECID());
System.out.println(compositeInstance.getCompositeDN().getCompositeName());
System.out.println(compositeInstance.getId());
if (compositeInstance.getState() ==
CompositeInstance.STATE_COMPLETED_SUCCESSFULLY) {
System.out.println("State : COMPLETED_SUCCESSFULLY");
} else if (compositeInstance.getState() ==
CompositeInstance.STATE_FAULTED) {
System.out.println("State : STATE_FAULTED");
} else if (compositeInstance.getState() ==
CompositeInstance.STATE_RUNNING) {
System.out.println("State : STATE_RUNNING");
} else if (compositeInstance.getState() ==
CompositeInstance.STATE_STALE) {
System.out.println("State : STATE_STALE");
} else if (compositeInstance.getState() ==
CompositeInstance.STATE_RECOVERY_REQUIRED) {
System.out.println("State : STATE_RECOVERY_REQUIRED");
} else if (compositeInstance.getState() ==
CompositeInstance.STATE_SUSPENDED) {
System.out.println("State : STATE_SUSPENDED");
} else if (compositeInstance.getState() ==
CompositeInstance.STATE_TERMINATED_BY_USER) {
System.out.println("State : STATE_SUSPENDED");
} else if (compositeInstance.getState() ==
CompositeInstance.STATE_UNKNOWN) {
System.out.println("State : STATE_UNKNOWN");
} else {
System.out.println("State : Undefined");
}
System.out.println("--------------------------------------------");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
loc.close();
}
}
private static Hashtable getConnectionDetails() {
Hashtable jndiProps = new Hashtable();
jndiProps.put(Context.PROVIDER_URL,
"t3://xxx:1234/soa-infra");
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
jndiProps.put(Context.SECURITY_PRINCIPAL, "xxx");
jndiProps.put(Context.SECURITY_CREDENTIALS, "xxxxx");
jndiProps.put("dedicated.connection", "true");
return jndiProps;
}
}


Libraries




Note : If the state comes as STATE_UNKNOWN then enable the instance capture option in EM console 



Oracle SOA : Get instance details for composites using SOA management api's

Below is the code to get instance details for composites and by applying filters you can retrieve at composite level and sensor level.


package com.raylabs.soa.management;
import java.util.Calendar;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import javax.naming.Context;
import oracle.soa.management.facade.CompositeInstance;
import oracle.soa.management.facade.Locator;
import oracle.soa.management.facade.LocatorFactory;
import oracle.soa.management.facade.SensorData;
import oracle.soa.management.util.CompositeInstanceFilter;
public class Class1 {
public Class1() {
super();
}
public static void main(String[] args) {
Locator loc = null;
try {
loc = LocatorFactory.createLocator(getConnectionDetails());
CompositeInstanceFilter compFilter = new CompositeInstanceFilter();
//compFilter.setCompositeDN(compositeDN);
Calendar cal = Calendar.getInstance();
//Getting instances triggered within 5 min
cal.add(Calendar.MINUTE,-5);
System.out.println(cal.getTime());
compFilter.setMinCreationDate(cal.getTime());
// compFilter.setMaxCreationDate(cal.getTime());
List<CompositeInstance> compositeInstances =
loc.getCompositeInstances(compFilter);
System.out.println("Number of instances :"+compositeInstances.size());
Iterator compositeInstanceIterator = compositeInstances.iterator();
while (compositeInstanceIterator.hasNext()) {
CompositeInstance instance =
(CompositeInstance)compositeInstanceIterator.next();
System.out.println(instance.getCompositeDN());
System.out.println(instance.getStatus());
System.out.println(instance.getTitle());
List<SensorData> data = instance.getSensorData();
int count=0;
while (count < data.size()) {
SensorData sensorData = data.get(count);
System.out.println("Sensor name : " +
sensorData.getSensor().getName());
System.out.println("Sensor data : " +
sensorData.getData().toString());
count++;
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
loc.close();
}
}
private static Hashtable getConnectionDetails() {
Hashtable jndiProps = new Hashtable();
jndiProps.put(Context.PROVIDER_URL,
"t3://xxx:1234/soa-infra");
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
jndiProps.put(Context.SECURITY_PRINCIPAL, "xxx");
jndiProps.put(Context.SECURITY_CREDENTIALS, "xxxxx");
jndiProps.put("dedicated.connection", "true");
return jndiProps;
}
}


Libraries :


Oracle SOA : Get list of composites deployed using SOA management api's

Use the below code to get the list of composites and other information about the composites deployed into the server.


package com.raylabs.soa.management;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import javax.naming.Context;
import oracle.soa.management.facade.Component;
import oracle.soa.management.facade.Composite;
import oracle.soa.management.facade.Locator;
import oracle.soa.management.facade.LocatorFactory;
import oracle.soa.management.util.CompositeFilter;
public class Class1 {
public Class1() {
super();
}
public static void main(String[] args) {
Locator loc = null;
try {
loc = LocatorFactory.createLocator(getConnectionDetails());
CompositeFilter compositeFilter = new CompositeFilter();
compositeFilter.setPartition("default");
//compositeFilter.setRevision("1.0");
List<Composite> composites = new ArrayList<Composite>();
composites = loc.getComposites(compositeFilter);
System.out.println("Number of Composites deployed :" +
composites.size());
Iterator compositesIterator = composites.iterator();
System.out.println("-----------------------------------------------------");
while (compositesIterator.hasNext()) {
Composite composite = (Composite)compositesIterator.next();
System.out.println(composite.getCompositeDN());
System.out.println(composite.getState());
System.out.println(composite.getInstanceCount());
// composite.getFaultCount();
List<Component> components = composite.getComponents();
Iterator componentIterator = components.iterator();
while (componentIterator.hasNext()) {
Component component = (Component)componentIterator.next();
// component.
System.out.println(component.getDN());
System.out.println(component.getName());
System.out.println(component.getImplementationType());
System.out.println(component.getNumberOfInstances());
System.out.println(component.getNumberOfActiveInstances());
}
System.out.println("-------------------------------------------------");
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static Hashtable getConnectionDetails() {
Hashtable jndiProps = new Hashtable();
jndiProps.put(Context.PROVIDER_URL, "t3://xxx:1234/soa-infra");
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
jndiProps.put(Context.SECURITY_PRINCIPAL, "xxx");
jndiProps.put(Context.SECURITY_CREDENTIALS, "xxxxx");
jndiProps.put("dedicated.connection", "true");
return jndiProps;
}
}

Libraries





Oracle SOA : Get Task service and Task Query service

Below is the java code and screenshot for getting task query service and Task service to query and update tasks


package com.raylab.util;
import java.util.HashMap;
import java.util.Map;
import oracle.bpel.services.workflow.WorkflowException;
import oracle.bpel.services.workflow.client.IWorkflowServiceClient;
import oracle.bpel.services.workflow.client.IWorkflowServiceClientConstants;
import oracle.bpel.services.workflow.client.WorkflowServiceClientFactory;
import oracle.bpel.services.workflow.query.ITaskQueryService;
import oracle.bpel.services.workflow.task.ITaskService;
import oracle.bpel.services.workflow.task.model.Task;
import oracle.bpel.services.workflow.verification.IWorkflowContext;
public class Class1 {
public Class1() {
super();
}
public static void main(String[] args){
IWorkflowServiceClient wfSvcClient = null;
ITaskQueryService querySvc = null;
ITaskService taskSvc=null;
Map connectionProperties=null;
String taskId="2add9056-3f50-4f19-9ff1-8eaad99aedbb";
connectionProperties=getConnectionforTaskDetails();
try{
wfSvcClient=WorkflowServiceClientFactory.getWorkflowServiceClient(connectionProperties,null );
}catch(WorkflowException wex){
System.out.println("Exception while getting client factor :"+wex.getMessage());
}
System.out.println("Got workflow client");
querySvc=wfSvcClient.getTaskQueryService();
IWorkflowContext authenticate;
try {
authenticate =
querySvc.authenticate("adminUser", "adminPassword".toCharArray(), null);
authenticate=querySvc.authenticateOnBehalfOf(authenticate, "user");
Task task= querySvc.getTaskDetailsById(authenticate, taskId);
System.out.println(task.getSystemAttributes().getState());
taskSvc=wfSvcClient.getTaskService();
} catch (WorkflowException e) {
e.printStackTrace();
}
}
public static Map getConnectionforTaskDetails(){
Map jndiProps = new HashMap();
jndiProps.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
jndiProps.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL,"t3://xxx:1234");
jndiProps.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL,"admin");
jndiProps.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS,"adminPassword");
jndiProps.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.CLIENT_TYPE,WorkflowServiceClientFactory.REMOTE_CLIENT);
return jndiProps;
}
}
view raw TaskService hosted with ❤ by GitHub



Libraries




Wednesday, February 4, 2015

Oracle SOA : Get list of instances that are recoverable using SOA managment api's Ver1

There are five message states

1. Undelivered
2. Resolved
3. Delivered
4. Cancelled
5. Exhausted

The int value for the above state is as below
0 for Undelivered
1 for Resolved
2 for delivered
3 for Cancelled
4 for exhausted
This is set in the mfilter.setState(0);



package com.raylabs.bpel;
import java.util.Hashtable;
import java.util.List;
import java.util.ListIterator;
import javax.naming.Context;
import oracle.soa.management.facade.Locator;
import oracle.soa.management.facade.LocatorFactory;
import oracle.soa.management.facade.bpel.BPELServiceEngine;
import oracle.soa.management.util.MessageFilter;
import oracle.soa.management.facade.bpm.BPMInvokeMessage;
public class Class1 {
public Class1() {
super();
}
public static void main(String[] args) {
Locator locator = null;
BPELServiceEngine mBPELServiceEngine = null;
MessageFilter mfilter = null;
try {
try {
locator =
LocatorFactory.createLocator(getConnectionForLocator());
System.out.println("Got locator succesfully ");
} catch (Exception e) {
System.out.println("Exception while getting locator");
e.printStackTrace();
}
try {
mBPELServiceEngine =
(BPELServiceEngine)locator.getServiceEngine(Locator.SE_BPEL);
System.out.println("Got BPELServiceEngine handle succesfully ");
} catch (Exception e) {
System.out.println("Exception BPELServiceEngine handle ");
e.printStackTrace();
}
mfilter = new MessageFilter();
mfilter.setState(0);
List<BPMInvokeMessage> recoverable;
try {
recoverable = mBPELServiceEngine.getInvokeMessages(mfilter);
ListIterator it = recoverable.listIterator();
System.out.println(recoverable.size());
while (it.hasNext()) {
BPMInvokeMessage invokemsg = (BPMInvokeMessage)it.next();
System.out.println(invokemsg.getCompositeDN() + "," +
invokemsg.getCreationTime() + "," +
invokemsg.getEcid());
}
} catch (Exception e) {
System.out.println("Exception while getting recoverable instances");
e.printStackTrace();
}
} catch (Exception e) {
System.out.println("Unknown Exception ");
e.printStackTrace();
} finally {
try {
locator.close();
System.out.println("Locator closed successfully");
} catch (Exception e) {
System.out.println("Exception while closing Locator handle");
e.printStackTrace();
}
}
}
public static Hashtable getConnectionForLocator() {
Hashtable jndiProps = new Hashtable();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
jndiProps.put(Context.PROVIDER_URL,
"t3://xxx:1234/soa-infra");
jndiProps.put(Context.SECURITY_PRINCIPAL, "xxx");
jndiProps.put(Context.SECURITY_CREDENTIALS, "xxxx");
jndiProps.put("dedicated.connection", "true");
return jndiProps;
}
}


Jdev libraries



Note :
If you get "org.omg.CORBA.MARSHAL:   vmcid: 0x0  minor code: 0  completed: No" exceptions then use weblogic.jar instead of wlclient.jar

Oracle BPM ; Get Process text audit trail using BPM api's

Using the below code you can get text audit trail details of a process instance using process id.

import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.model.IProcessInstance;
import oracle.bpm.services.instancequery.IAuditInstance;
import oracle.bpm.services.instancequery.IInstanceQueryService;
import oracle.bpm.services.internal.processmodel.model.IProcessModelPackage;
public class Class2 {
private static BPMServiceClientFactory bpmscf;
public Class2() {
super();
}
public static void main(String[] args) throws Exception {
// process id will be like bpmn:240481 in EM console
String instanceIdS = "240481";
// get the BPMServiceClient
IBPMServiceClient bpmServiceClient =
getBPMServiceClientFactory().getBPMServiceClient();
IBPMContext bpmContext =
getBPMServiceClientFactory().getBPMUserAuthenticationService().authenticate("xxx",
"xxx".toCharArray(),
null);
// get details of the process instance
IInstanceQueryService instanceQueryService =
bpmServiceClient.getInstanceQueryService();
IProcessInstance processInstance =
instanceQueryService.getProcessInstance(bpmContext, instanceIdS);
if (processInstance != null) {
// get details of the process (not a specific instance of it,
// but the actual process definition itself)
// WARNING WARNING WARNING
// The ProcessModelService is an UNDOCUMENTED API - this means
// that it could (and probably will) change in some future
// release - you SHOULD NOT build any code that relies on it,
// unless you understand and accept the risks of using an
// undocumented API.
IProcessModelPackage processModelPackage =
bpmServiceClient.getProcessModelService().getProcessModel(bpmContext,
processInstance.getSca().getCompositeDN(),
processInstance.getSca().getComponentName());
// get a list of the audit events that have occurred in this instance
List<IAuditInstance> auditInstances =
bpmServiceClient.getInstanceQueryService().queryAuditInstanceByProcessId(bpmContext,
instanceIdS);
for (IAuditInstance a1 : auditInstances) {
System.out.println(a1.getActivityName());
System.out.println(a1.getCompositeInstanceId());
System.out.println(a1.getLabel());
System.out.println(a1.getCreateTime().getTime());
System.out.println("---------------------------");
}
} else {
System.out.println("Could not find instance");
}
}
protected static BPMServiceClientFactory getBPMServiceClientFactory() {
if (bpmscf == null) {
Map properties = new HashMap();
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.CLIENT_TYPE,
IWorkflowServiceClientConstants.CLIENT_TYPE_REMOTE);
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL,
"t3://xxx:xxx");
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS,
"xxxx");
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL,
"xxx");
bpmscf =
BPMServiceClientFactory.getInstance(properties, null, null);
}
return bpmscf;
}
}


Libraries used : 




Audit trail : 




Oracle BPM : Determine the current task and next task using BPM Api

Below is the java code which will show you the current task and next task for a given process id .


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import oracle.bpel.services.bpm.common.IBPMContext;
import oracle.bpel.services.workflow.client.IWorkflowServiceClientConstants;
import oracle.bpm.client.BPMServiceClientFactory;
import oracle.bpm.project.SequenceFlowImpl;
import oracle.bpm.project.model.ProjectObject;
import oracle.bpm.services.client.IBPMServiceClient;
import oracle.bpm.services.instancemanagement.model.IProcessInstance;
import oracle.bpm.services.instancequery.IAuditInstance;
import oracle.bpm.services.instancequery.IInstanceQueryService;
import oracle.bpm.services.internal.processmodel.model.IProcessModelPackage;
public class Class2 {
private static BPMServiceClientFactory bpmscf;
public Class2() {
super();
}
public static void main(String[] args) throws Exception{
//The process id in EM will be like bpmn:240469
String instanceIdS="240481";
// get the BPMServiceClient
IBPMServiceClient bpmServiceClient =
getBPMServiceClientFactory().getBPMServiceClient();
IBPMContext bpmContext =
getBPMServiceClientFactory()
.getBPMUserAuthenticationService()
.authenticate("xxx", "xxx".toCharArray(), null);
// get details of the process instance
IInstanceQueryService instanceQueryService =
bpmServiceClient.getInstanceQueryService();
IProcessInstance processInstance =
instanceQueryService.getProcessInstance(bpmContext,
instanceIdS);
if (processInstance != null) {
// get details of the process (not a specific instance of it,
// but the actual process definition itself)
// WARNING WARNING WARNING
// The ProcessModelService is an UNDOCUMENTED API - this means
// that it could (and probably will) change in some future
// release - you SHOULD NOT build any code that relies on it,
// unless you understand and accept the risks of using an
// undocumented API.
IProcessModelPackage processModelPackage =
bpmServiceClient
.getProcessModelService()
.getProcessModel(bpmContext,
processInstance.getSca().getCompositeDN(),
processInstance.getSca().getComponentName());
// get a list of the audit events that have occurred in this instance
List<IAuditInstance> auditInstances =
bpmServiceClient
.getInstanceQueryService().queryAuditInstanceByProcessId(bpmContext, instanceIdS);
// // work out which activities have not finished
List<IAuditInstance> started = new ArrayList<IAuditInstance>();
System.out.println(auditInstances.size());
for (IAuditInstance a1 : auditInstances) {
if (a1.getAuditInstanceType().compareTo("START") == 0) {
// ingore the process instance itself, we only care
// about tasks in the process
if (a1.getActivityName().compareTo("PROCESS") != 0) {
started.add(a1);
}
}
}
next:
for (IAuditInstance a2 : auditInstances) {
if (a2.getAuditInstanceType().compareTo("END") == 0) {
for (int i = 0; i < started.size(); i++) {
// IAuditInstance temp=(IAuditInstance)started.get(i);
if (a2.getActivityId().compareTo(started.get(i).getActivityId())== 0) {
started.remove(i);
continue next;
}
}
}
}
System.out.println("\n\nLooks like the following have started but not ended:");
for (IAuditInstance s : started) {
System.out.println(s.getActivityId() + "\nwhich is a "
+ s.getActivityName() + "\ncalled "
+ s.getLabel() + "\n");
}
// now we need to find what is after these activities...
// WARNING WARNING WARNING
// The ProcessModel, ProcessObject, etc. are UNDOCUMENTED APIs -
// this means that they could (and probably will) change
// in some future release - you SHOULD NOT build any code
// that relies on them, unless you understand and
// accept the risks of using undocumented APIs.
List<ProjectObject> nextActivities = new ArrayList<ProjectObject>();
next2:
for (ProjectObject po : processModelPackage.getProcessModel().getChildren()) {
if (po instanceof SequenceFlowImpl) {
for (IAuditInstance s2 : started) {
if (((SequenceFlowImpl)po).getSource()
.getId().compareTo(s2.getActivityId()) == 0) {
nextActivities.add(po);
continue next2;
}
}
}
}
System.out.println("\n\nLooks like the next activities are:");
for (ProjectObject po2 : nextActivities) {
System.out.println(((SequenceFlowImpl)po2).getTarget().getId()
+ "\nwhich is a "
+ ((SequenceFlowImpl)po2).getTarget().getBpmnType()
+ "\ncalled "
+ ((SequenceFlowImpl)po2).getTarget().getDefaultLabel()
+ "\n");
}
}else{
System.out.println("Could not find instance, aborting");
}
}
protected static BPMServiceClientFactory getBPMServiceClientFactory() {
if (bpmscf == null) {
Map properties = new HashMap();
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.CLIENT_TYPE,
IWorkflowServiceClientConstants.CLIENT_TYPE_REMOTE);
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL,
"t3://xxx:xxx");
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS,
"xxx");
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL,
"xxx");
bpmscf = BPMServiceClientFactory.getInstance(properties, null, null);
}
return bpmscf;
}
}




Libraries and jar files required are as shown in the below screen shot 



Tuesday, February 3, 2015

Oracle BPM : Generate process audit and process model image

There might be some requirements from the customer to generate BPMN process image or Audit image. This can be achieved by using BPM api's .

import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Map;
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.instancequery.IInstanceQueryService;
import oracle.bpm.util.Base64;
public class Class1 {
private static BPMServiceClientFactory bpmscf;
public static void main(String args[]) throws Exception{
//The process id in EM will be like bpmn:240469
String instanceIdS="200479";
// get the BPMServiceClient
IBPMServiceClient bpmServiceClient =
getBPMServiceClientFactory().getBPMServiceClient();
IBPMContext bpmContext =
getBPMServiceClientFactory()
.getBPMUserAuthenticationService()
.authenticate("xxx", "xxx".toCharArray(), null);
// get details of the process instance
IInstanceQueryService instanceQueryService =
bpmServiceClient.getInstanceQueryService();
//Image in PNG format and base64 coded
//String imageSeq=instanceQueryService.getProcessDiagram(bpmContext, instanceIdS,java.util.Locale.ENGLISH );
String imageSeq=instanceQueryService.getProcessAuditDiagram(bpmContext, instanceIdS, java.util.Locale.ENGLISH );
byte[] decode = Base64.decode(imageSeq);
// Write a image byte array into file system
FileOutputStream imageOutFile = new FileOutputStream("C:\\"+instanceIdS+".png");
imageOutFile.write(decode);
imageOutFile.close();
}
protected static BPMServiceClientFactory getBPMServiceClientFactory() {
if (bpmscf == null) {
Map properties = new HashMap();
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.CLIENT_TYPE,
IWorkflowServiceClientConstants.CLIENT_TYPE_REMOTE);
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL,
"t3://xxx:123");
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS,
"xxx");
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL,
"xxx");
bpmscf = BPMServiceClientFactory.getInstance(properties, null, null);
}
return bpmscf;
}
}



The libraries need to be added in the classpath of the project is as follows :





Monday, February 2, 2015

Oracle BPM : Splitting the process into Different Composites

If you have multiple processes in a single composite and you want to split each process into single composite then follow the below steps

     Split the processes into multiple composites to enable modularity and developer productivity.
     Reducing developer job in recreation of process again.

     Cloning the BPM project.


a.       Take the project which has  multiple  process



  Export the current project to a file.






An .exp file will be created.





Creating multiple projects out of the .exp file by selecting Fileà Import




Select import BPM project



Select .exp file which was generated earlier




Give the process name as a project name.







New project will be created and will have all the process of the one exported earlier





Delete the process which is not required






Expose the process as a web service.




Define arguments and click on OK.




A Web service interface would be created.






Repeat the same procedure to create another project for process 2.




Delete the process which is not required and enable the process to be invoked through web service.





After separating out the processes into different composites deploy the different projects into the server. Then you can invoke this individual process through web service call. This way modularity is achieved and every developer can work on individual process.

Oracle BPM : How to use MDS for using XSD as Business objects

Creating BUSINESS OBJECTS using MDS as reference




Click on BPM project navigator for the particular BPM project and click on Business Catalog


  
 Create new Module




 Create new Business object in the new module.


Give a proper name to Business object and select “Based on external Schema” and click on the magnifying glass.




Click on OK




      Click on “Import schema file”








Click on magnifying glass again




      Select Resource palette



From the SOA resource browseràResource palette select the MDS and select the xsd you want to refer and click on OK.




 Do NOT select the option  “Copy to Project “  and click on OK



 Select the appropriate element for the particular data type and click on OK.





 After click on OK similar pop up box will appear and click on OK.




 A Business object will be created based on external schema



 Now you can create Project data objects or Process data objects based on this Business object.

   Create a process




 Click on next



       Create an input argument based on external schema by clicking on “+” sign 



 Select “Component”



   Click on magnifying glass


 Select the Business object created earlier or you can create by clicking on “New” for creating new Business object.





      Click on OK



       Similar way you can create for Output also



 Creating  project data objects from Business objects.

 Click on the process



Navigate to Structure window









    Right click on the  “Project data objects”  and click on new





Click on Component



 Click on Magnifying glass




   Select the Business object  and click on OK.


 Project data object would have been created and ready to use in the process.  Usually appending variables with abcBO(Business object ) , abcPDO(Project data object) or abcPO(Process objects).  



Similarly the variables can be created for Process data objects.