Togotutor Blog Join US!

Enter your email address:

Delivered by FeedBurner

WLST Script To Create JMS Server

WLST Script To create a JMS server

In this blog post, we are going to write a WLST script to create a JMS server. We are going to create a JMS server using WLST after reading the information from the properties file. The following code can be downloaded from the following link:

1. The first step is to create a properties file and name it as domain.properties


#*****************************************************

# Security Info

#*****************************************************

ADMIN_USERNAME=weblogic

ADMIN_PASSWORD=weblogic01

ADMIN_URL=t3://192.168.1.9:8001

DOMAIN_NAME=togodomain

#*****************************************************

# Server Info

#*****************************************************

SERVER_NAME=AdminServer

#*****************************************************

# JMS Info

#*****************************************************

JMS_SERVER_NAME=jmserver1

2. In the next step we are going to write a utility to read the properties file in a given format


#! /usr/bin/python

#****************************************************************************

# File: utils.py

#****************************************************************************

from java.lang import System

#****************************************************************************

# def notNullOrEmpty()

#****************************************************************************

def notNullOrEmpty(val):

return val != None and len(val) != 0

#****************************************************************************

# def substitute()

#****************************************************************************

def substitute(orig, subs):

startIndex = orig.find(‘${‘)

#print ‘startIndex =’, startIndex

if startIndex == -1:

return orig

endIndex = orig.find(‘}’, startIndex)

#print ‘endIndex =’, endIndex

if endIndex == -1:

return orig

substitutionKey = orig[startIndex + 2:endIndex]

value = System.getProperty(substitutionKey)

if subs.has_key(substitutionKey):

value = subs[substitutionKey]

if value != None:

return orig[0:startIndex] + value + substitute(orig[endIndex + 1:], subs)

if len(orig) == endIndex + 1:

print ‘WARNING: No substitution found for key:’, orig

return orig

else:

return orig[0:endIndex + 1] + substitute(orig[endIndex + 1], subs)

#****************************************************************************

# def loadOrderedProps

#****************************************************************************

def loadOrderedProps(filename):

def split(line):

index = line.find(‘=’)

if index == -1:

return None

else:

return (line[:index], line[index + 1:])

propLines = open(filename, ‘r’).readlines()

propLines = [line.strip() for line in propLines]

propLines = [line for line in propLines if len(line) > 0 and not line.startswith('#')]

propLines = [split(line) for line in propLines]

propLines = [line for line in propLines if line]

return propLines

#****************************************************************************

# def loadProperties()

#****************************************************************************

def loadProperties(propFile):

props = {}

originalProps = loadOrderedProps(propFile)

for key, value in originalProps:

#print ‘ KEY: [' + key + ']‘

value = substitute(value, props)

#print ‘ VALUE: [' + value + ']‘

props[key] = value

return props

#****************************************************************************

# def getValue

#****************************************************************************

def getValue(propKey, defaultKey, properties):

if properties.get(propKey) != None:

val = properties[propKey]

else:

if properties.get(defaultKey) != None:

val = properties[defaultKey]

else:

val = ”

return val

#****************************************************************************

# def getKeyValue

#****************************************************************************

def getKeyValue(propkey, properties):

if properties.get(propkey) != None:

val = properties[propkey]

else:

val = ”

return val

3. This is the step where we are going to write the WLST online script to create the JMS server.


#################################################

#

# Name : Create JMS Server WLST Script

# Author : Togotutor

# Copyright ©2012 <a href="http://www.togotutor.com">www.togotutor.com</a>

#

################################################

“”"

Connection To Admin Server

“”"

def __connectToAdmin(properties):

adminusername = getKeyValue(‘ADMIN_USERNAME’, properties)

adminpassword = getKeyValue(‘ADMIN_PASSWORD’, properties)

adminurl = getKeyValue(‘ADMIN_URL’, properties)

domainname = getKeyValue(‘DOMAIN_NAME’, properties)

print ‘[INFO]: Connecting to the domain’ +domainname

try:

connect(adminusername, adminpassword, adminurl)

except WLSTException:

print ‘[ERROR]: Trying to connect to the domain:’ + domainname

exit()

“”"

Connection To Admin Server

“”"

def __disconnectToAdmin():

disconnect()

“”"

Edit Session

“”"

def __editSession():

edit()

startEdit()

“”"

Save Session

“”"

def __closeSession():

save()

activate()

“”"

Create JMS Server

“”"

def __createJMSServer(properties):

servername = getKeyValue(‘SERVER_NAME’, properties)

jmsservername = getKeyValue(‘JMS_SERVER_NAME’, properties)

print ‘[INFO]: Creating the JMS Server:’ +jmsservername

try:

cmo.createJMSServer(jmsservername)

cd(‘/JMSServers/’+jmsservername)

print ‘[INFO]: Targetting the JMS Server:’ +jmsservername+ ‘ ‘+’to the server’+’ ‘+servername

set(‘Targets’,jarray.array([ObjectName('com.bea:Name='+servername+',Type=Server')], ObjectName))

except WLSTException:

print ‘[ERROR]: Exception Trying to Create the JMS Server’

exit()

#****************************************************************************

# MAIN

#****************************************************************************

#

# Calling all the Methods here

print(‘ ————————– ‘)

print(‘[INFO] Printing the output’)

print(”)

execfile(‘utils.py’)

propFilename = ‘domain.properties’

properties = {}

properties = loadProperties(propFilename)

__connectToAdmin(properties)

__editSession()

__createJMSServer(properties)

__closeSession()

__disconnectToAdmin()

print ”

print ‘[INFO]: Quitting the WLST script’

print(‘ ————————– ‘)

print ‘[INFO] Completed.’

We also have a tutorial on how to create a jms server using JMX.

Speak Your Mind

*

CAPTCHA Image

*

Visit Us On TwitterVisit Us On FacebookVisit Us On PinterestVisit Us On YoutubeCheck Our Feed