Thursday, February 10, 2011

Part 2: Getting Component instance state...

Leading on from the previous post - I've kicked off the process, now I want to check on the instance state.

Again, a big thanks to Edwin -

http://biemond.blogspot.com/2009/11/invoking-soa-suite-11g-service-from.html

I added the following to my client Java class -

public String checkInstanceState(String uuid){

//
// connect to soa and find composite
//
Hashtable jndiProps = new Hashtable();
jndiProps.put(Context.PROVIDER_URL, "t3://localhost:7001/soa-infra");
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
jndiProps.put(Context.SECURITY_PRINCIPAL, "weblogic");
jndiProps.put(Context.SECURITY_CREDENTIALS, "welcome1");
jndiProps.put("dedicated.connection", "true");

Locator locator = null;

try{
locator = LocatorFactory.createLocator(jndiProps);
Composite composite = locator.lookupComposite("default/InvokeDirectBinding!1.0");
CompositeInstanceFilter filter = new CompositeInstanceFilter();
filter.setConversationId(uuid);

List cis = composite.getInstances(filter);
// for each of the returned composite instances..
for (CompositeInstance instance : cis) {
System.out.println(" DN: " + instance.getCompositeDN() +"\n" +
" Instance: " + instance.getId() +"\n" +
" creation-date: " + instance.getCreationDate() +"\n" +
" state (" + instance.getState() + "): " + getStateAsString(instance.getState()) );
}

}
catch (Exception e){
e.printStackTrace();
}
return "done";
}


private String getStateAsString(int state)
{
// note that this is dependent on wheter the composite state is captured or not
if (state == CompositeInstance.STATE_COMPLETED_SUCCESSFULLY)
return ("STATE_COMPLETED_SUCCESSFULLY");
else if (state == CompositeInstance.STATE_FAULTED)
return ("STATE_FAULTED");
else if (state == CompositeInstance.STATE_RECOVERY_REQUIRED)
return ("STATE_RECOVERY_REQUIRED");
else if (state == CompositeInstance.STATE_RUNNING)
return ("STATE_RUNNING");
else if (state == CompositeInstance.STATE_STALE)
return ("STATE_STALE");
else
return ("STATE_UNKNOWN");


}

I also had to add the JRF Runtime library -




I then invoked a new instance -



tested the new code ...

No comments: