Tuesday, June 21, 2011

Oracle Weblogic 10.3.4

After installing Oracle Weblogic 10.3.4 zip installation on Window XP I was wondering how to create JNDI Data Source using the admin console and did not find a way. So finally I have to write my WLST script and after that I started to like WLST and was amazed with so many things that you can do with this little tool. Below is the WLST script to create Datasource using properties file.

1. Save WLST as CreateDataSource.py
2. Save the below properties file as domain.properties
3. For running WLST scripts follow this link

#Conditionally import wlstModule only when script is executed with jython
if __name__ == '__main__': 
    from wlstModule import *#@UnusedWildImport

from java.io import FileInputStream

propInputStream = FileInputStream("PATH_TO_PROP_FILES/domain.properties")
configProps = Properties()
configProps.load(propInputStream)

print 'starting the script ....'

connect(configProps.get("domain.admin.username"),
        configProps.get("domain.admin.password"), 
        configProps.get("domain.admin.url"))


edit()
startEdit()

server= configProps.get("domain.server.name")

print 'server is ' + server

cd("Servers/"+server)
target=cmo
cd("../..")

dsname=configProps.get("domain.ds.name")
jndiname=configProps.get("domain.jndi.name")
jdbc_url =configProps.get("domain.ds.jdbc.url")
jdbc_driver= configProps.get("domain.ds.jdbc.driver") 
jdbc_user=configProps.get("domain.ds.jdbc.user")
jdbc_pwd=configProps.get("domain.ds.jdbc.pwd")

# start creation
print 'Creating JDBCSystemResource with name '+dsname
jdbcSR = create(dsname,"JDBCSystemResource")
theJDBCResource = jdbcSR.getJDBCResource()
theJDBCResource.setName(dsname)

connectionPoolParams = theJDBCResource.getJDBCConnectionPoolParams()
connectionPoolParams.setConnectionReserveTimeoutSeconds(25)
connectionPoolParams.setMaxCapacity(100)
connectionPoolParams.setTestTableName("SQL SELECT 1 FROM DUAL")
connectionPoolParams.setConnectionCreationRetryFrequencySeconds(100);

dsParams = theJDBCResource.getJDBCDataSourceParams()
dsParams.addJNDIName(jndiname)


driverParams = theJDBCResource.getJDBCDriverParams()
driverParams.setUrl(jdbc_url)
driverParams.setDriverName(jdbc_driver)

driverParams.setPassword(jdbc_pwd)
driverProperties = driverParams.getProperties()

proper = driverProperties.createProperty("user")
proper.setValue(jdbc_user)

jdbcSR.addTarget(target)

save()
activate(block="true")

print 'Done configuring the data source'

Below are the properties files

###################
 Domain-1 Details
###################
domain.name=mydomain
domain.admin.url=t3://localhost:7001
domain.admin.username=weblogic
domain.admin.password=WL_PASSWORD
domain.server.name=myserver

domain.ds.name=JDBCDataSource
domain.jndi.name=jdbc.tempDS 


domain.ds.jdbc.url=jdbc:oracle:thin:@SERVER_NAME:1521:SERVER_INSTANCE
domain.ds.jdbc.driver=oracle.jdbc.driver.OracleDriver
domain.ds.jdbc.user=scott
domain.ds.jdbc.pwd=tiger

No comments:

Post a Comment

PF