Friday, October 28, 2011

Changing the Audit Level for Oracle SOA Suite

 Changing the Audit Level for Oracle SOA Suite 11g or Oracle SOA Suite 12c


SOA 11g has three different Audit levels – Production, Development and Off

Audit Level Details:

Audit Level
Description
Production(Default)
Composite instance tracking is collected, but Mediator engine will not collect payload details and BPEL engine will not collect payload details for assign activities (payload details for other BPEL activities are collected). This level is optimal for most normal production operations.
Development
Allows both the composite instance tracking and payload detail tracking. However it may impact the performance. This level is useful mostly for testing and debugging purposes.
Off
No logging is performed. Composite instance tracking and payload details are not collected.

Changing the Audit Level for SOA:

1. Login to EM console.
2. Expand the SOA folder and right-click the soa-infra and select SOA Administration – Click on Common Properties



Oracle SOA Suite – different user roles to restrict the access of EM console

Oracle SOA Suite – different user roles to restrict the access of EM console:

Not like oracle SOA Suite 10g, Oracle SOA Suite 11g or Oracle SOA Suite 12c is having different roles to restrict the access of the EM console.
Refer the below URL for the details about user roles for EM console.
Access to the Enterprise Manager console is determined by the role assigned to the user.
The steps to configure the different EM console roles to the user.

Through EM console

1. Create the corresponding users through weblogic console
2. Now log in to the Enterprise Manager console with admin privileges. Under SOA folder right-click on soa-infra and select Security -> Application Roles.




Thursday, October 27, 2011

Oracle SOA Suite – Getting the payload from the Composite instance through Java API - Part1


Oracle SOA Suite– Getting the payload from the Composite instance through Java API - Part1 

This blog explains the approach to retrieve the request payload from the closed composite instance.
The below code snippet will enable you to retrieve the request payload from the closed composite instance for Oracle SOA Suite 11g or Oracle SOA Suite 12c

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

import org.w3c.dom.Document;
import org.w3c.dom.Node;

public class GetCompositeInstancePayload {
    //Invoke this method with the composite instance id
    public static String getCompositeInstancePayload(String compInstanceId, String ecid) {
        String compositeName = "GetOpenCompositeInstances";
        Hashtable jndiProps = new Hashtable();
        String inputPayload = "";
        try {
            jndiProps.put(Context.PROVIDER_URL, "t3://localhost:7201");
            jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
            jndiProps.put(Context.SECURITY_PRINCIPAL, "weblogic");
            jndiProps.put(Context.SECURITY_CREDENTIALS, "Test1234");
            jndiProps.put("dedicated.connection", "true");
            Locator locator = LocatorFactory.createLocator(jndiProps);
            CompositeInstanceFilter filter = new CompositeInstanceFilter();
            filter.setECID(ecid); //Set the composite ECID
            List compositeInstance = locator.getCompositeInstances(filter);
            ComponentInstanceFilter instanceFilter = new ComponentInstanceFilter();
            instanceFilter.setCompositeInstanceId(compInstanceId);           
            List componentInstance =((CompositeInstance) compositeInstance.get(0)).getChildComponentInstances(instanceFilter);
            if (compositeInstance.size() > 0) {
                Document docAudit = XMLUtil.convertToDOM(((ComponentInstance) componentInstance.get(0)).getAuditTrail().toString());
                String payloadAudit = XPathUtils.executeXPath(docAudit, "//details").toString();
                Document docPayload = XMLUtil.convertToDOM(payloadAudit);
                Node payloadNode = XPathUtils.executeXPath(docPayload, "//part//*", "NODE");
                inputPayload = XMLUtil.nodeToString(payloadNode);
                System.out.println("InputPayload: "+ inputPayload);
            }
           
        } catch (Exception e) {
            e.printStackTrace();
        }
       
        return inputPayload;
    }

    public static void main(String[] args) {
       getCompositeInstancePayload("23","9897cfe2-ee70-44d6-9e40-9c77651c7025-00000783");
    }
}

XPathUtils:


Utility class to retrieve the XML payload from the instance audit trail.
import javax.xml.xpath.*;

import org.w3c.dom.*;

public class XPathUtils {
    public static Object executeXPath(Document doc, String xpathStr) throws Exception {
        XPath xpath = null;
        String value = null;
        try {
            xpath = new org.apache.xpath.jaxp.XPathFactoryImpl().newXPath();
            XPathExpression expr = xpath.compile(xpathStr);
            value = (String) expr.evaluate(doc, XPathConstants.STRING);
            return value;
        } catch (Exception e) {
            throw e;
        }
    }

    public static Node executeXPath(Document doc, String xpathStr, String type) throws Exception {
        XPath xpath = null;
        Node value = null;
        try {
            xpath = new org.apache.xpath.jaxp.XPathFactoryImpl().newXPath();
            XPathExpression expr = xpath.compile(xpathStr);
            value = (Node) expr.evaluate(doc, XPathConstants.NODE);
            return value;
        } catch (Exception e) {
            throw e;
        }
    }
}



Oracle SOA Suite – Finding the Running Instances of a Composite


Oracle SOA Suite – Finding the Running Instances of a Composite:

SQL Query:

We can use the below query to find all the Running instances of a Composite.
select * from composite_instance where state =0 or state=8 and composite_dn likexxxxxxxxx%'

Example query:

select * from composite_instance where state =0 or state=8 and composite_dn likedefault/GetOpenCompositeInstances!1.0%'

Java API:

The SOA Suite 11g provides a Java API’s that can be used to find the Running instances of the Composite.
The client API provides the Locator class to look up the Composite instances based on the filter.
The CompositeInstanceFilter class is used to filter the instance of the composite based on the condition.
The following code snippet will enable you to find all the open instances for a particular Composite process.
try
{
String compositeName="GetOpenCompositeInstances";
Hashtable jndiProps = new Hashtable();
jndiProps.put(Context.PROVIDER_URL,"t3://:");
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
jndiProps.put(Context.SECURITY_PRINCIPAL,"weblogic");
jndiProps.put(Context.SECURITY_CREDENTIALS,"password");
jndiProps.put("dedicated.connection","true");
Locator locator = LocatorFactory.createLocator(jndiProps);
CompositeInstanceFilter filter =new CompositeInstanceFilter();
filter.setState(CompositeInstance.STATE_RUNNING);
filter.setCompositeName(compositeName);
List compositeInstance = locator.getCompositeInstances(filter);
setVariableData("openCompositeInstances",new Integer(compositeInstance.size()).toString());
}catch(Exception e)
{
setVariableData("openCompositeInstances",e.getMessage());
e.printStackTrace();
}
Please refer the attached sample for your reference.



Wednesday, October 26, 2011

Oracle SOA Suite – Creating Resource Adapter Connection factories through WLST for Database Adapter,MQ Adapter and FTP Adapter


Oracle SOA Suite – Creating Resource Adapter Connection factories through WLST for Database Adapter,MQ Adapter and FTP Adapter:

WLST script can be use to create the Resource Adapter connection factories (DB, FTP and MQ) and set the different configuration parameters in weblogic server.
Here we will use the property file to configure the connection factories details, the WLST script will create the connection factories in the server based on the property file.
Just edit the ResourceAdapter.properties file with the connection factories details.
Set the global.resource.deployment.plan.path property with the where the generated deploymentPlan files needs to be stored.

ResourceAdapter.properties


domain.AdminIP=xxxxxxxx
domain.AdminPort=xxxx
domain.AdminPasswd=xxxxxxxxxx
global.resource.deployment.plan.path= /config/deployplan
domain.resource.ftpHost = 10.10.10.10
domain.resource.ftpUserName=
domain.resource.ftpPassword=
domain.resource.mqQueueManager=TCRMGEN1
domain.resource.mqHost=LOCALHOST
domain.resource.mqport=2022
domain.resource.mqChannel=L_CRM_FUSION_CLNT_N2

The below WLST code snippet will create the required connection factories in the server.
Set the DB data source Connection Factory JNDI Name and the data source name as per the requirement. In this sample we are creating two connection factories. Change the method createDBConnectionFactory to create more Database Adapter connection factories.
Change the method createFTPConnectionFactory to create more FTP Adapter connection factories.
Change the method createMQConnectionFactory to create more FTP Adapter Connection factories.

ResourceAdapterCreation.py


from java.io import FileInputStream
TargetServerName='AdminServer'
#Connect
#The directory of the SOA binaries
soaHome=os.environ["SOAHOME"]
print "SOAHOME="+soaHome
appPathDB=soaHome+'/soa/connectors/DbAdapter.rar'
appNameDB='DbAdapter'
moduleOverrideNameDB=appNameDB+'.rar'
appPathFTP=soaHome+'/soa/connectors/FtpAdapter.rar'
appNameFTP='FtpAdapter'
moduleOverrideNameFTP=appNameFTP+'.rar'
appPathMQ=soaHome+'/soa/connectors/MQSeriesAdapter.rar'
appNameMQ='MQSeriesAdapter'
moduleOverrideNameMQ=appNameMQ+'.rar'
moduleDescriptorName='META-INF/weblogic-ra.xml'
ConnFactory1JNDIName = 'eis/DB/OM'
ConnFactory1DataSourceName = 'eai/ds/EAIReference'
ConnFactory2JNDIName = 'eis/DB/XRef'
ConnFactory2DataSourceName = 'eai/ds/EAIXRef'
transactionSupport='LocalTransaction'
ftpJNDIName='eis/Ftp/ProductRefXML'
mqJNDIName='eis/MQ/MQSeriesAdapterRemoteCRMtoEAI'
domainName='standalone_domain'
def createDBConnectionFactory():
propInputStream = FileInputStream("ResourceAdapter.properties")
configProps1 = Properties()
configProps1.load(propInputStream)
planPathDB=configProps1.get('global.resource.deployment.plan.path')+'/'+domainName+'_PlanDB.xml'
edit()  
startEdit()
myPlanDB=loadApplication(appPathDB, planPathDB)
makeDeploymentPlanVariable(myPlanDB, 'ConnectionInstance_eis/DB/OM_JNDIName_13102979357209', ConnFactory1JNDIName , '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ConnFactory1JNDIName+'"]/jndi-name',moduleOverrideNameDB)
makeDeploymentPlanVariable(myPlanDB, 'ConfigProperty_dataSourceName_Value_13102979357210', ConnFactory1DataSourceName,'/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ConnFactory1JNDIName+'"]/connection-properties/properties/property/[name="xADataSourceName"]/value',moduleOverrideNameDB)
makeDeploymentPlanVariable(myPlanDB, 'ConnectionInstance_eis/DB/XRef_JNDIName_13102979357211', ConnFactory2JNDIName , '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ConnFactory2JNDIName+'"]/jndi-name',moduleOverrideNameDB)
makeDeploymentPlanVariable(myPlanDB, 'ConfigProperty_dataSourceName_Value_13102979357213', ConnFactory2DataSourceName,'/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ConnFactory2JNDIName+'"]/connection-properties/properties/property/[name="xADataSourceName"]/value',moduleOverrideNameDB)
makeDeploymentPlanVariable(myPlanDB, 'ConnectionDefinitionProperties_TransactionSupport_13123107532320', transactionSupport,'/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ConnFactory1JNDIName+'"]/connection-properties/transaction-support',moduleOverrideNameDB)
makeDeploymentPlanVariable(myPlanDB, 'ConnectionDefinitionProperties_TransactionSupport_13123107532320', transactionSupport,'/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ConnFactory2JNDIName+'"]/connection-properties/transaction-support',moduleOverrideNameDB)
myPlanDB.save();
save();
cd('/AppDeployments/DbAdapter/Targets');
updateApplication(appNameDB, planPathDB);
startApplication(appNameDB)
#redeploy(appNameDB, planPathDB,targets=cmo.getTargets());
activate(block='true');
def createFTPConnectionFactory():
propInputStream = FileInputStream("ResourceAdapter.properties")
configProps1 = Properties()
configProps1.load(propInputStream)
planPathFTP=configProps1.get('global.resource.deployment.plan.path')+'/'+domainName+'_PlanFTP.xml'
ftpHost=configProps1.get('domain.resource.ftpHost')
ftpUserName=configProps1.get('domain.resource.ftpUserName')
ftpPassword=configProps1.get('domain.resource.ftpPassword')
edit()
startEdit()
myPlanFTP=loadApplication(appPathFTP, planPathFTP)
makeDeploymentPlanVariable(myPlanFTP, 'ConnectionInstance_eis/Ftp/FtpPRD_JNDIName', ftpJNDIName, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ftpJNDIName+'"]/jndi-name',moduleOverrideNameFTP)
makeDeploymentPlanVariable(myPlanFTP, 'ConfigProperty_useSftp_Value_FtpPRD', 'true', '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ftpJNDIName+'"]/connection-properties/properties/property/[name="useSftp"]/value',moduleOverrideNameFTP)
makeDeploymentPlanVariable(myPlanFTP, 'ConfigProperty_host_Value_FtpPRD', ftpHost, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ftpJNDIName+'"]/connection-properties/properties/property/[name="host"]/value',moduleOverrideNameFTP)
makeDeploymentPlanVariable(myPlanFTP, 'ConfigProperty_password_Value_FtpPRD', ftpUserName, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ftpJNDIName+'"]/connection-properties/properties/property/[name="username"]/value',moduleOverrideNameFTP)
makeDeploymentPlanVariable(myPlanFTP, 'ConfigProperty_password_Value_FtpPRD', ftpPassword, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ftpJNDIName+'"]/connection-properties/properties/property/[name="password"]/value',moduleOverrideNameFTP)
myPlanFTP.save();
save();
cd('/AppDeployments/FtpAdapter/Targets');
updateApplication(appNameFTP, planPathFTP);
startApplication(appNameFTP)
#redeploy(appNameFTP, planPathFTP,targets=cmo.getTargets());
activate(block='true');
def createMQConnectionFactory():
propInputStream = FileInputStream("ResourceAdapter.properties")
configProps1 = Properties()
configProps1.load(propInputStream)
planPathMQ=configProps1.get('global.resource.deployment.plan.path')+'/'+domainName+'_PlanMQ.xml'
mqQueueManager=configProps1.get('domain.resource.mqQueueManager')
mqHostName=configProps1.get('domain.resource.mqHost')
MqPort=configProps1.get('domain.resource.mqport')
mqChannelName=configProps1.get('domain.resource.mqChannel')
edit()
startEdit()
myPlanMQ=loadApplication(appPathMQ, planPathMQ)
makeDeploymentPlanVariable(myPlanMQ, 'ConnectionInstance_eis_MQ_MQSeriesAdapterRemoteCRMtoEAI_JNDIName', mqJNDIName, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+mqJNDIName+'"]/jndi-name',moduleOverrideNameMQ)
makeDeploymentPlanVariable(myPlanMQ, 'ConfigProperty_host_Value_mqQueueManagerPRD', mqQueueManager, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+mqJNDIName+'"]/connection-properties/properties/property/[name="queueManagerName"]/value',moduleOverrideNameMQ)
makeDeploymentPlanVariable(myPlanMQ, 'ConfigProperty_password_Value_mqHostNamePRD', mqHostName, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+mqJNDIName+'"]/connection-properties/properties/property/[name="hostName"]/value',moduleOverrideNameMQ)
makeDeploymentPlanVariable(myPlanMQ, 'ConfigProperty_password_Value_MqPortPRD', MqPort, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+mqJNDIName+'"]/connection-properties/properties/property/[name="portNumber"]/value',moduleOverrideNameMQ)
makeDeploymentPlanVariable(myPlanMQ, 'ConfigProperty_password_Value_mqChannelNamePRD', mqChannelName, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+mqJNDIName+'"]/connection-properties/properties/property/[name="channelName"]/value',moduleOverrideNameMQ)
myPlanMQ.save();
save();
cd('/AppDeployments/MQSeriesAdapter/Targets');
updateApplication(appNameMQ, planPathMQ);
startApplication(appNameMQ)
#redeploy(appNameFTP, planPathMQ,targets=cmo.getTargets());
activate(block='true');
def makeDeploymentPlanVariable(wlstPlan, name, value, xpath,overrideName, origin='planbased'):
wlstPlan.destroyVariable(name)
wlstPlan.destroyVariableAssignment(name, overrideName, moduleDescriptorName)
variableAssignment = wlstPlan.createVariableAssignment(name, overrideName, moduleDescriptorName)
variableAssignment.setXpath(xpath)
variableAssignment.setOrigin(origin)
wlstPlan.createVariable(name, value)
print 'moduleDescriptorName=',moduleDescriptorName
def main():
propInputStream1 = FileInputStream("ResourceAdapter.properties")
domainProps = util.Properties()
domainProps.load(propInputStream1)
adminURL='t3://'+domainProps.get('domain.AdminIP')+':'+domainProps.get('domain.AdminPort')
adminUserName='weblogic'
adminPassword=domainProps.get("domain.AdminPasswd")
connect(adminUserName, adminPassword, adminURL)
createDBConnectionFactory()
createFTPConnectionFactory()
createMQConnectionFactory()
disconnect()
main()

Set the environment variable “SOAHOME”  in the server and execute the WLST script that will create the required Resource Adapter connection factories. Also this will create the deploymentPlan files to the location specified. The generated plan file can be used to modify the configuration of connection factories also to move the connection factories from one server to another server.

>$ORACLE_HOME/common/bin/wlst.sh ResourceAdapterCreation.py

Download: ResourceAdapter.properties   ResourceAdapterCreation.py