WLST script to add DataSource and DBAdapter EIS Connection Factory

Share this on .. Tweet about this on Twitter0Share on LinkedIn0Share on Facebook0Share on Google+0Email this to someoneShare on TumblrBuffer this page

Creating a EIS ConnectionFactory in your Database Adapter can be done with the WebLogic Administration Console, but of course this is also “scriptable”. What I needed was a script that created a Data Source with EIS Connection factory bound to the specific datasource.

First I created a properties file, let’s call it DsCf.properties. Everything between <> should be replaced with your own values:

# Propertie file for creating datasource and EIS DB Adapter
# Created by Michel Schildmeijer
# Domain settings
domainname="&lt;your WLS DOMAIN&gt;"
adminurl=&lt;WLS HOST:Admin Port&gt;
adminpassword=&lt;passwd weblogic&gt;
#datasource settings
datasourcename=&lt;Name DataSource&gt;
datasourcetarget=&lt;targeted manaegd server&gt;
datasourcefilename= datasourcename + '.xml'
datasourcejndiname= 'jdbc/' + datasourcename
datasourceurl=jdbc:oracle:thin:@&lt;db host&gt;:1521:&lt;db sid&gt;
datasourceusername=&lt;db user&gt;
datasourcepassword=&lt;db user password
datasourcetestquery=SQL SELECT * FROM DUAL
#EIS Connection Factory settings
connfactname=eis/DB/&lt;Connection factory Name&gt;

Second, I created a WLST script to execute these properties and added the DataSource and ConnectionFactory. See the script below.

When running on a UNIX or linux system, navigate to the WLS DOMAIN DIR /bin( Specified during domaincreation) like /app/oracle/middleware/user_projects/domains/<Your domain>/bin and run


After this you are able to deploy the DataSource en ConnectionFactory:

java weblogic.WLST loadProperties DsCf.properties

After finished you can check in the WebLogic Admin Console to see:

  • If datasource is created
  • If in your outbound connections of the database adapter the EIS connection factory with binding to the DataSource has been created.

Script DsCf.py


<code></code><code>import os
</code><code>import time
</code><code>domainName = domainname
</code><code>adminURL= adminurl
</code><code>adminUserName= adminusername
</code><code>adminPassword= adminpassword
</code><code>dsName= datasourcename
</code><code>dsFileName= datasourcefilename
</code><code>connect(adminUserName, adminPassword, adminURL)
</code><code>cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName)
</code><code>cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDataSourceParams/' + dsName )
</code><code>set('JNDINames',jarray.array([String('jdbc/' + dsName )], String))
</code><code>cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName )
</code><code>cmo.setDriverName( dsDriverName )
</code><code>cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCConnectionPoolParams/' + dsName )
</code><code>cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName + '/Properties/' + dsName )
</code><code>cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName + '/Properties/' + dsName + '/Properties/user')
</code><code>cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName + '/Properties/' + dsName )
</code><code>cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName + '/Properties/' + dsName + '/Properties/databaseName')
</code><code>cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDataSourceParams/' + dsName )
</code><code>cd('/SystemResources/' + dsName )
</code><code>set('Targets',jarray.array([ObjectName('com.bea:Name=' + datasourceTarget + ',Type=Server')], ObjectName))
</code><code>print 'Data source ' + dsName + ' configured'</code>
<code></code><code></code>oracleHome = os.environ.get(“ORACLE_HOME”)
<code></code><code>appPath= oracleHome + 'soa/connectors/DbAdapter.rar'
planPath=oracleHome + 'soa/connectors/DbAdapterPlanGenerated.xml'</code>
</code><code>def makeDeploymentPlanVariable(wlstPlan, name, value, xpath, origin='planbased'):
</code><code>while wlstPlan.getVariableAssignment(name, moduleOverrideName, moduleDescriptorName):
</code><code>wlstPlan.destroyVariableAssignment(name, moduleOverrideName, moduleDescriptorName)
</code><code>while wlstPlan.getVariable(name):
</code><code>variableAssignment = wlstPlan.createVariableAssignment( name, moduleOverrideName, moduleDescriptorName )
</code><code>variableAssignment.setXpath( xpath )
</code><code>variableAssignment.setOrigin( origin )
</code><code>wlstPlan.createVariable( name, value )
</code><code>             def main():
</code><code>                     connect(adminUserName, adminPassword, adminURL)
</code><code>                     edit()
</code><code>                           try:
</code><code>                           startEdit()
</code><code>                           planPath = get('/AppDeployments/DbAdapter/PlanPath')
</code><code>                           print '__ Using plan ' + planPath
</code><code>                           myPlan=loadApplication(appPath, planPath)
</code><code>                           print '___ BEGIN change plan'
</code><code>                           makeDeploymentPlanVariable(myPlan, 'ConnectionInstance_' '+ CFName' +'_JNDIName_abc123XXX','+ CFName', '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ CFName + '"]/jndi-name')
</code><code>                           makeDeploymentPlanVariable(myPlan, 'ConfigProperty_xADataSourceName_'+ dsName +'_abc123XXX',dsName, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ CFName + '"]/connection-properties/properties/property/[name="xADataSourceName"]/value')
</code><code>                           print '___ DONE change plan'
</code><code>                           myPlan.save();
</code><code>                           save();
</code><code>                           activate(block='true');
</code><code>                           cd('/AppDeployments/DbAdapter/Targets');
</code><code>                           redeploy(appName, planPath,targets=cmo.getTargets());
</code><code>                           print 'EIS Connection factory ' + CFName + 'using' + dsName + ' configured';
</code><code>                    except:
</code><code>                           stopEdit('y')

Share this on .. Tweet about this on Twitter0Share on LinkedIn0Share on Facebook0Share on Google+0Email this to someoneShare on TumblrBuffer this page

About Author

Started in pharmacy, I made the change to IT in 1996. I am an Oracle Fusion Middleware Architect at AMIS, with focus on technical infrastructure, Serverside solutions, installing, administering, configuring the Oracle Fusion Middleware stack. My experience is from integrations at telco´s using Oracle AIA, Oracle Portal, OID, Forms&Reports, Discoverer upto the latest Oracle WebLogic 11g releases with practically all Oracle products running on top of it


  1. Hi,
    I’m new to this WLST script. I’m trying to do this.
    BTW, you have provided the Python script in this article but I’m confused where to keep this script and how to run.
    Please clarify.


  2. Michel Schildmeijer on

    Hi Edwin
    Thanks for you input
    About the hard paths
    You als could set the paths in you property file instead of the run script
    First get the ORACLE_HOME thats been set
    oracleHome = os.environ.get(“ORACLE_HOME”)
    And add this to you plan and app path:
    appPath= oracleHome + ‘/soa/connectors/DbAdapter.rar’

    planPath=oracleHome + ‘/soa/connectors/DbAdapterPlanGenerated.xml’
    About specific connectionfactory settings, it depends on wht you want to create with it. I’ll try to extend it with more options later on.


  3. Hi,
    great post, I was always wondering if it is possible. but it would be great to make it more flexible and add some warnings

    this is a hard path to your soa env and also has a DB plan with a hard value.
    And second you can only add the XA Datasource property , sometimes you need to add the datasource or set transacted.
    but I make some ANT macrodefs and use it in my scripts, also do this for AQ and JMS and make it more flexible.
    Keep up the good work.

Leave a Reply