Wednesday, August 13, 2014

Create Service Bus Customization File using WLST

For one of our Oracle Fusion Middleware projects we had the requirement that the IT Ops activities should be scripted as much as possible. These activities included things like packaging, deploying, and automated testing of Service Bus projects, SOA Composites, and BPM processes. One of the more challenging tasks to script was to create and extract the runtime configuration of services deployed on Oracle Service Bus 11g using customization files. There seems to be no WLST feature readily available for this purpose. Based on some resources that all contained part of the solution, we were able to construct a WLST script for this purpose which you can find in this blog.

This blog briefly explains the use of customization files, how to create a customization file using the Service Bus Console, includes the WLST script to execute this task, and provides a brief conclusion.

Customization Files

Customization files are XML files that contain the configuration of Service Bus resources and projects. Examples of such configurations are Service URIs, JCA settings, Retry Settings, and so on. Customization files provide a convenient way to apply environment-specific configuration during deployment. You can both apply, as well as create and extract the runtime configuration of Service Bus resources and projects into customization files using the Service Bus Console.

Creating customization file using the Service Bus Console

Read more about customization files in the Oracle Fusion Middleware Administrator's Guide for Oracle Service Bus.

WLST Script

Based on the following resources a WLST script can be created to export an OSB project including its customization file from a runtime environment:

The WLST script is as follows:

from import FileOutputStream
from java.util import Collections

from com.bea.wli.config import Ref
from com.bea.wli.config.mbeans import ConfigMBean 
from import EnvValueTypes

import sys

# Utility function to export project and cust file
def exportProject():

        if projectName == "None":
            print "No project specified, exiting deployment"

        if customizationFile == "None":
            print "No customization file specified, exiting"

        ALSBConfigurationMBean = findService("ALSBConfiguration", "")
        print "ALSBConfigurationMBean found"
        configMBean = JMX.newMBeanProxy(mbs, ObjectName.getInstance("com.bea:Name=Config.XBus Kernel,Type=com.bea.wli.config.mbeans.ConfigMBean"), ConfigMBean)
        print "ConfigMBean found"

        # Get reference to OSB project        
        ref = Ref.makeProjectRef(projectName);
        collection = Collections.singleton(ref)
        # Export OSB project JAR            
        print "Export JAR for OSB project:", projectName
        theBytes = ALSBConfigurationMBean.exportProjects(collection, passphrase)
        aFile = File(exportJar)
        out = FileOutputStream(aFile)
        print "Project " + projectName + " exported"

        # Export OSB customization file
        print "Export customization file for:", projectName
        theBytes = configMBean.createCustomizationFile(collection, EnvValueTypes.ENV_VALUE_TYPES);
        out = FileOutputStream(customizationFile);
        print "Cust file for " + projectName + " exported"

    adminUser         = sys.argv[1]  
    adminPassword     = sys.argv[2]  
    adminUrl          = sys.argv[3]   
    projectName       = sys.argv[4]
    exportJar         = sys.argv[5]
    customizationFile = sys.argv[6]    
    passphrase        = "your-passphrase"
    connect(adminUser, adminPassword, adminUrl) 

    print "Unexpected error: ", sys.exc_info()[0]


WLST provides a very powerful and comprehensive scripting environment for Oracle Fusion Middleware products. While most administration and management features can be accessed and executed through WLST, some of the features that are available through IDEs or consoles are not (easily) available through WLST and require a workaround or some research. One of these examples was shown in this blog.