SOA 11g Audit Trail : Programmatically Managing SOA Composite Applications with the Facade API using Groovy Scripting

My previous post  was dealing about how retrieve the SOA payload from the database using SQL statement and Oracle XML API.

In this post, I will use the Oracle facade API to interact with the SOA composite application, achieving the same goal, e.g programmatically using Groovy to retrieve the SOA payload contains in the Audit Trail.

You can have more information from the official documentation : Programmatically Managing SOAComposite Applications with the Facade API

I prefer to use groovy to prototype quickly what I want to achieve.  Please forgive me to provide so quick and dirty code, but as always it works for me :-).

For my customer who are reading this blog, don’t be afraid with this, it is just a prototype to demonstrate with 10 lines of code how we can use theses facade API.

To launch the groovy script:

set MIDLEWARE_HOME=E:\middleware\mid70
groovy -cp "%MIDLEWARE_HOME%\oracle_common\soa\modules\oracle.soa.mgmt_11.1.1\soa-infra-mgmt.jar;%MIDLEWARE_HOME%\oracle_common\modules\wlthint3client.jar;%MIDLEWARE_HOME%\oracle_common\modules\oracle.jrf_11.1.1\jrf-api.jar;%MIDLEWARE_HOME%\oracle_common\modules\oracle.fabriccommon_11.1.1\fabric-common.jar;%MIDLEWARE_HOME%\oracle_common\modules\oracle.mds_11.1.1\mdsrt.jar" soa_infra_API.groovy

Here is the sample code using Groovy

import java.util.Hashtable
import javax.naming.Context
import oracle.soa.management.facade.ServerManagerFactory
import oracle.soa.management.facade.Locator
import oracle.soa.management.facade.LocatorFactory
import oracle.soa.management.facade.Composite
import oracle.soa.management.facade.ComponentInstance
import oracle.soa.management.util.ComponentInstanceFilter
import oracle.soa.management.util.CompositeInstanceFilter
import oracle.soa.management.facade.CompositeInstance

 Hashtable<String, String> jndiProps = new Hashtable<String, String>();

 jndiProps.put(Context.PROVIDER_URL, "t3://127.0.0.1:7001");
 jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
 jndiProps.put(Context.SECURITY_PRINCIPAL, "weblogic");
 jndiProps.put(Context.SECURITY_CREDENTIALS, "Welcome1");
 Locator locator = LocatorFactory.createLocator(jndiProps);
 
 // I know that this componentInstanceID exist; so quick and dirty method to get the AuditTrail
 String componentInstanceID = "510001";
 Composite composite = (Composite)locator.lookupComposite("default/soaHelloWorld!1.0");
 CompositeInstanceFilter paramCompositeInstanceFilter = new CompositeInstanceFilter()
 List<CompositeInstance> listCompositeInstance = composite.getInstances(paramCompositeInstanceFilter)
 println listCompositeInstance[0]
 ComponentInstanceFilter componentInstanceFilter = new ComponentInstanceFilter ();
 List<ComponentInstance> listComponentInstance= listCompositeInstance[0].getChildComponentInstances(componentInstanceFilter);
 println listComponentInstance
 println listComponentInstance[0].getAuditTrail() 
 new File('c:/tmp/soa_instance_audit_trail.xml').write(listComponentInstance[0].getAuditTrail())

Groovy output

C:\Users\Chenda\Documents>groovy -cp "E:\middleware\mid70\oracle_common\soa\modules\oracle.soa.mgmt_11.1.1\soa-infra-mgmt.jar;E:\middleware\mid70\oracle_common\modules\wlthint3client.jar;E:\middleware\mid70\oracle_common\modules\oracle.jrf_11.1.1\jrf-api.jar;E:\middleware\mid70\oracle_common\modules\oracle.fabriccommon_11.1.1\fabric-common.jar;E:\middleware\mid70\oracle_common\modules\oracle.mds_11.1.1\mdsrt.jar" soa_infra_API.groovy

CompositeDN: default/soaHelloWorld!1.0
Id: 510001
Native State: 1
State: 2
Execution State: 2

[BPELInstance {
BPMInstance {
mCompositeDN=default/soaHelloWorld!1.0
mComponentName=BPELProcess1
mId=bpel:510001
mECID=5f9c6d236487b476:-6762c93c:14214875f3c:-8000-000000000000030b
mCompositeInstanceId=510001
mCreationDate=Fri Nov 01 17:43:50 CET 2013
mCreator=null
mModifyDate=Fri Nov 01 17:43:52 CET 2013
mState=5
mConversationId=null
mAuditTrail=null
mParentId=null
mFaultMessage=null
isTestCase=Do not know
}
}
]

and the generated audit trail output is:

<audit-trail xmlns="http://schemas.oracle.com/bpel/audit-trail/">
	<event sid="0" cat="2" n="0" date="2013-11-01T17:43:50.935+01:00" type="2">
		<message>
			<![CDATA[New instance of BPEL process "1.0" initiated (# "BPELProcess1").]]>
		</message>
	</event>
	<event sid="BpPrc0.1" cat="1" n="1" label="process" psid="0" date="2013-11-01T17:43:50.971+01:00" type="2">
		<message>
			<![CDATA[_cr_]]>
		</message>
	</event>
	<event sid="BpTry0.2" cat="1" n="2" label="tryBlock of process (29)" psid="BpPrc0.1" date="2013-11-01T17:43:50.984+01:00" type="2">
		<message>
			<![CDATA[_cr_]]>
		</message>
	</event>
	<event sid="BpSeq0.3" cat="1" n="3" label="main (68)" psid="BpTry0.2" date="2013-11-01T17:43:50.992+01:00" type="2">
		<message>
			<![CDATA[_cr_]]>
		</message>
	</event>
	<event sid="BpSeq0.3" cat="2" wikey="510001-BpRcv0-BpSeq0.3-1" state="5" n="4" label="receiveInput" date="2013-11-01T17:43:51.072+01:00" type="2">
		<message>
			<![CDATA[Received "process" call from partner "bpelprocess1_client"]]>
		</message>
		<details>
			<![CDATA[
<inputVariable><part name="payload" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><bpel:process xmlns:bpel="http://xmlns.oracle.com/Application1/soaHelloWorld/BPELProcess1">
         <bpel:input>gero et</bpel:input>
      </bpel:process></part></inputVariable>]]></details>
	</event>
	<event to="outputVariable" sid="BpSeq0.3" cat="2" wikey="510001-BpAss0-BpSeq0.3-2" state="1" n="5" label="Assign1" date="2013-11-01T17:43:51.292+01:00" type="1">
		<message>
			<![CDATA[Updated variable "outputVariable"]]>
		</message>
		<details>
			<![CDATA[
<outputVariable><part name="payload" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><processResponse xmlns="http://xmlns.oracle.com/Application1/soaHelloWorld/BPELProcess1"><result>Hello gero et</result></processResponse></part></outputVariable>]]></details>
	</event>
	<event sid="BpSeq0.3" cat="2" wikey="510001-BpAss0-BpSeq0.3-2" state="5" n="6" label="Assign1" date="2013-11-01T17:43:51.292+01:00" type="1">
		<message>
			<![CDATA[Completed assign]]>
		</message>
	</event>
	<event sid="BpSeq0.3" cat="2" wikey="510001-BpRpl0-BpSeq0.3-3" state="5" n="7" label="replyOutput" date="2013-11-01T17:43:51.308+01:00" type="2">
		<message>
			<![CDATA[Reply to partner "bpelprocess1_client".]]>
		</message>
		<details>
			<![CDATA[
<outputVariable><part name="payload" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><processResponse xmlns="http://xmlns.oracle.com/Application1/soaHelloWorld/BPELProcess1"><result>Hello gero et</result></processResponse></part></outputVariable>]]></details>
	</event>
	<event sid="BpSeq0.3" cat="1" n="8" date="2013-11-01T17:43:51.328+01:00" type="2">
		<message>
			<![CDATA[_cl_]]>
		</message>
	</event>
	<event sid="BpTry0.2" cat="1" n="9" date="2013-11-01T17:43:51.328+01:00" type="2">
		<message>
			<![CDATA[_cl_]]>
		</message>
	</event>
	<event sid="BpPrc0.1" cat="1" n="10" date="2013-11-01T17:43:51.329+01:00" type="2">
		<message>
			<![CDATA[_cl_]]>
		</message>
	</event>
	<event sid="BpPrc0.1" cat="2" n="11" date="2013-11-01T17:43:51.331+01:00" type="2">
		<message>
			<![CDATA[BPEL process instance "510001" completed]]>
		</message>
	</event>
</audit-trail>

Exactly the same as we got from the Enterprise Manager !

More to come …

Advertisements

About Chenda Mok

19 years of hands on experience in software design and development with emphasis on Enterprise Application Integration (EAI), Services Oriented Architecture (SOA) and Identity Management (IDM) solutions. I’m a software engineer, member of the professional service delivery team working for Salesforce. Prior to this, I worked for Oracle as Solution Architect, through SeeBeyond(06/2005), then SUN’s acquisition (04/2009). After my master’s degree in computer science in 1997; I always delivered consulting on architecture, design, implementation on integration’s field. I’m interested in architecture using EAI/SOA/IDM/BPM/Cloud technologies, software development and Java’s related technologies. I may blog about my work/activities at Salesforce, but I do not speak for my employer, past, present or future.
This entry was posted in bpel, Groovy, script, SOA Suite and tagged , , , , . Bookmark the permalink.