Create datasource in weblogic by python script

Hi All,

If you want to create datasources in weblogic manually or through program. You can write a python script and invoke that python script with maven to use this in devops. This is quite common requirment. If you want to setup new environment using maven, this will be really helpful.

Below is follow script used for that

adminUserName='weblogic'
adminPassword='Weblogic1'
adminURL='t3://hostname:port'
databasehost='hostname'


connect(UserName, Password, adminURL)
edit()
startEdit()

cd('/')
cmo.createJDBCSystemResource('techartifactDS')

cd('/JDBCSystemResources/techartifact/JDBCResource/techartifactDS')
cmo.setName('techartifactDS')

cd('/JDBCSystemResources/techartifact/JDBCResource/JDBCDataSourceParams/techartifactDS')
set('JNDINames',jarray.array([String('jdbc/techartifactDS')], String))

cd('/JDBCSystemResources/techartifact/JDBCResource/JDBCDriverParams/techartifactDS')
cmo.setUrl('jdbc:oracle:thin:@' + databasehost + ':1521:xe')
cmo.setDriverName('oracle.jdbc.OracleDriver')
cmo.setPassword('passwordFortechartifactDS')

cd('/JDBCSystemResources/techartifact/JDBCResource/JDBCConnectionPoolParams/techartifactDS')
cmo.setTestTableName('SQL SELECT 1 FROM DUAL\r\n\r\n')

cd('/JDBCSystemResources/techartifact/JDBCResource/JDBCDriverParams/techartifactDS/Properties/techartifact')
cmo.createProperty('user')

cd('/JDBCSystemResources/techartifact/JDBCResource/JDBCDriverParams/techartifactDS/Properties/techartifact/Properties/user')
cmo.setValue('techartifact')

cd('/JDBCSystemResources/techartifact/JDBCResource/JDBCDataSourceParams/techartifactDS')
cmo.setGlobalTransactionsProtocol('OnePhaseCommit')

cd('/SystemResources/techartifact')
set('Targets',jarray.array([ObjectName('com.bea:Name=WCP_PORTAL,Type=Cluster')], ObjectName))

activate()

Happy coding with python with Vinay

Setting a WebCenter Maintenance Page

When you shutdown WebCenter, the apache weblogic mod takes over the control of error pages and shows:

Failure of server APACHE bridge:
No backend server available for connection: timed out after 10 seconds or idempotent set to OFF.

Let’s face it that’s not user friendly and needs to be replaced with a nice page.

Solution
You can set a custom error page following the steps below:

*if you haven’t got OHS_HOME, I recommend you set up this environment variable. The path should look similar to the below:
/apps/oracle/product/middleware/Oracle_WT1/instances/instance1/config/OHS/ohs1

First copy your custom html to the server.
Move the files to
$OHS_HOME/htdocs/
For example you have a file called
maintenance.html

Next modify the config file for the weblogic mod
nano $OHS_HOME/mod_wl_ohs.conf
within the Webcenter location add


LOCATION STUFF
ErrorPage http://[hostname]/maintenance.html

Now to test the change, restart OHS. (if you’re in clustered mode run with 1 spaces, 1 OHS only for now)
Stop Spaces.
Go to WebCenter home.
New html maintenance page displays.
Restart spaces in WLS console.
Spaces displays correctly.

Ensure you copy the files/change in every OHS if you’re in a clustered deployment.

——————————————————————————————————————–

You can set up the maintenance page when at the Web server level when the application is down in the App layer. Here is the reference for Oracle HTTP server, same you can do it for any other web server too..!!

You can achieve this by configuring an error page at the WebServer (part of web-tier).

For example, in the case of a Oracle HTTP Server (OHS), you could do the following:

1. Place your maintenance page at /config/OHS//htdocs.

For Example, /config/OHS//htdocs/errorPage500.html

2. Open the OHS httpd.conf located at /config/OHS/ in an editor and search for the string ‘ErrorDocument 403′ which can be seen as commented text. Next to the commented text line, add the below lines for configuring the Error

Pages (500 —> backend server unavailable, 403 —> forbidden request, 404 –> Resource Not available). For the below example, we had 3 html pages errorPage500.html, errorPage403.html and errorPage404.html are deployed in OHS htdocs.

ErrorDocument 500 /errorPage500.html
ErrorDocument 403 /errorPage403.html
ErrorDocument 404 /errorPage404.html

3. Save the changes to the httpd.conf file.

4. Restart OHS server

———————————————————————————————————————-

Maintenance page for weblogic server

In Apache httpd.conf file put the below , replace the /console with proper context root and same with the host and port no.


SetHandler weblogic-handler
WebLogicHost 192.168.50.57
WebLogicPort 7001
ErrorPage /maintain.html

Place your customized maintain.html in the Root directory.

Happy learning with Vinay in techartifact….

Spaces server could not start. Failed to load webapp /wcsdocs.

Hi,

If you have got this weird issue in starting webcenter server

Failed to initialize the application ‘webcenter [Version=11.1.1.4.0]’ due to error weblogic.application.ModuleException: Failed to load webapp: ‘/wcsdocs’.
weblogic.application.ModuleException: Failed to load webapp: ‘/wcsdocs’
at weblogic.servlet.internal.WebAppModule.prepare(WebAppModule.java:395)
at weblogic.application.internal.flow.ScopedModuleDriver.prepare(ScopedModuleDriver.java:176)
at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:199)
at weblogic.application.internal.flow.DeploymentCallbackFlow$1.next(DeploymentCallbackFlow.java:517)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:159)
at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:45)
at weblogic.application.internal.BaseDeployment$1.next(BaseDeployment.java:648)
… …

Caused By: weblogic.management.DeploymentException: Error: Unresolved Webapp Library references for “[email protected][app:webcenter module:/wcsdocs path:/wcsdocs spec-version:2.5 version:11.1.1.4.0]”, defined in weblogic.xml [Extension-Name: SomeLibraryName, exact-match: false]
at weblogic.servlet.internal.WebAppServletContext.processWebAppLibraries(WebAppServletContext.java:2750)
at weblogic.servlet.internal.WebAppServletContext.(WebAppServletContext.java:416)

Solution – You need to delete the reference of this library in weblogic.xml and delete this library.First you can check in
/archives/applications and see if there is reference in weblogic.xml .

You can find weblogic.xml using following command.

find / -iname weblogic.xml

If you cant find then check in
/user_projects/domains/DomainName/servers/WC_Spaces/tmp/_WL_user/webcenter_11.1.1.4.0/extend.spaces.webapp

Check weblogic.xml and delete the reference.

Thats it. Happy coding with vinay in techartifact.