Hi,
This script is created based on the query asked by “varunkolanu” http://middlewaremagic.com/weblogic/?p=1473#comment-3074
A WebLogic Server can have only one XML registry associated with it, although an XML Registry can be targetted to more than one WebLogic Server. When you create an XML registry, you have the option of associating it with one or more WebLogic Servers; this procedure describes how change the XML registry currently associated to a particular WebLogic Server.
The same thing we can do very easily using the WLST script provided below which uses a properties file. We need to just make changes in the properties file and no additional changes are required in the WLST Script.
Step1) Create a Directory somewhere in your file system like : “C:WLST”
Step2) Write a Properties file “registry.properties” inside “C:WLST” like following:
target.server.name=AdminServer admin.server.url=t3://10.10.10.10:7001 admin.username=weblogic admin.password=weblogic registryName=MyXMLRegistry DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl TransformerFactory=com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl registryPublicId=Registry Entry Public ID-0 registrySystemId=Registry Entry System ID-0 registryRootElement=Registry Entry Root Element-0 xmlEntityPublicId=XML Entity Spec Public ID Entry-0 xmlEntitySpecSystemId=XML Entity Spec System ID Entry-0 entityURI= registrySetting=defer-to-registry-setting cacheTimeoutInterval=0
Step-3) Create a WLST Script somewhere in your file system with some name like “createXMLRegistry.py” inside “C:WLST” contents will be something like following:
############################################################################# # # @author Copyright (c) 2010 - 2011 by Middleware Magic, All Rights Reserved. # ############################################################################# from java.util import Date from java.io import FileInputStream import java.lang import os import string propInputStream = FileInputStream("registry.properties") configProps = Properties() configProps.load(propInputStream) adminUser = configProps.get("admin.username") adminPassword = configProps.get("admin.password") targetServerName = configProps.get("target.server.name") adminServerUrl = configProps.get("admin.server.url") registryName=configProps.get("registryName") documentBuilderFactory=configProps.get("DocumentBuilderFactory") saxParserFactory=configProps.get("SAXParserFactory") transformerFactory=configProps.get("TransformerFactory") registryPublicId=configProps.get("registryPublicId") registrySystemId=configProps.get("registrySystemId") registryRootElement=configProps.get("registryRootElement") xmlEntityPublicId=configProps.get("xmlEntityPublicId") xmlEntitySpecSystemId=configProps.get("xmlEntitySpecSystemId") entityURI='' registrySetting=configProps.get("registrySetting") timeout=configProps.get("cacheTimeoutInterval") cacheTimeoutInterval=int(timeout) ############# Infinite Loop to check the Status of Server in Mentioned Interval ################# try: connect(adminUser,adminPassword,adminServerUrl) print 'Hiiiiiiiiiiiiii' edit() startEdit() cd('/') cmo.createXMLRegistry(registryName) cd('/Servers/'+ targetServerName) cmo.setXMLRegistry(getMBean('/XMLRegistries/' + registryName)) cd('/XMLRegistries/' + registryName) cmo.setDocumentBuilderFactory(documentBuilderFactory) cmo.setSAXParserFactory(saxParserFactory) cmo.setTransformerFactory(transformerFactory) activate() startEdit() cmo.findParserSelectMBeanByKey(registryPublicId, registrySystemId, registryRootElement) cmo.createXMLParserSelectRegistryEntry(registryPublicId) cd('/XMLRegistries/'+ registryName +'/XMLParserSelectRegistryEntries/' + registryPublicId) cmo.setPublicId(registryPublicId) cmo.setSystemId(registrySystemId) cmo.setRootElementTag(registryRootElement) cmo.setDocumentBuilderFactory(documentBuilderFactory) cmo.setSAXParserFactory(saxParserFactory) activate() startEdit() cd('/XMLRegistries/'+ registryName) cmo.findEntitySpecMBeanByKey(xmlEntityPublicId, xmlEntitySpecSystemId) cmo.createXMLEntitySpecRegistryEntry(xmlEntityPublicId) cd('/XMLRegistries/'+ registryName +'/XMLEntitySpecRegistryEntries/' + xmlEntityPublicId) cmo.setPublicId(xmlEntityPublicId) cmo.setSystemId(xmlEntitySpecSystemId) cmo.setEntityURI(entityURI) cmo.setWhenToCache(registrySetting) cmo.setCacheTimeoutInterval(cacheTimeoutInterval) activate() disconnect() print 'Registry Created Successfully....' except: print 'Sorry !!! Unable to Connect to Server OR UserName/Password incorrect Or Some Other Issue: ' , adminServerUrl dumpStack() #######################################################################
Step-4) Open a command prompt and then run the “setWLSEnv.cmd” or “setWLSEnv.sh” to set the CLASSPATH and PATH variables. Better you do echo %CLASSPATH% or echo $CLASSPATH to see whether the CLASSPATH is set properly or not. If you see an Empty Classpath even after running the “setWLSEnv.sh” then please refer to the Note mentioned at Step3) in the Following post: http://middlewaremagic.com/weblogic/?page_id=1492
Step-5) Now run the WLST Script in the same command prompt using the following command:
java weblogic.WLST createXMLRegistry.py
You will see the following kind of results in the command prompt
Initializing WebLogic Scripting Tool (WLST) ... $ java weblogic.WLST createXMLRegistry.py Initializing WebLogic Scripting Tool (WLST) ... Welcome to WebLogic Server Administration Scripting Shell Type help() for help on available commands Connecting to t3://10.10.10.10:7001 with userid weblogic ... Successfully connected to Admin Server 'AdminServer' that belongs to domain 'Test_Domain'. Warning: An insecure protocol was used to connect to the server. To ensure on-the-wire security, the SSL port or Admin port should be used instead. Hiiiiiiiiiiiiii Location changed to edit tree. This is a writable tree with DomainMBean as the root. To make changes you will need to start an edit session via startEdit(). For more help, use help(edit) You already have an edit session in progress and hence WLST will continue with your edit session. Starting an edit session ... Started edit session, please be sure to save and activate your changes once you are done. Activating all your changes, this may take a while ... The edit lock associated with this edit session is released once the activation is completed. The following non-dynamic attribute(s) have been changed on MBeans that require server re-start: MBean Changed : com.bea:Name=AdminServer,Type=Server Attributes changed : XMLRegistry Activation completed Starting an edit session ... Started edit session, please be sure to save and activate your changes once you are done. Activating all your changes, this may take a while ... The edit lock associated with this edit session is released once the activation is completed. The following non-dynamic attribute(s) have been changed on MBeans that require server re-start: MBean Changed : com.bea:Name=MyXMLRegistry,Type=XMLRegistry Attributes changed : XMLParserSelectRegistryEntries MBean Changed : com.bea:XMLRegistry=MyXMLRegistry,Name=Registry Entry Public ID-0,Type=XMLParserSelectRegistryEntry Attributes changed : SystemId, PublicId, SAXParserFactory, DocumentBuilderFactory, RootElementTag Activation completed Starting an edit session ... Started edit session, please be sure to save and activate your changes once you are done. Activating all your changes, this may take a while ... The edit lock associated with this edit session is released once the activation is completed. The following non-dynamic attribute(s) have been changed on MBeans that require server re-start: MBean Changed : com.bea:XMLRegistry=MyXMLRegistry,Name=XML Entity Spec Public ID Entry-0,Type=XMLEntitySpecRegistryEntry Attributes changed : SystemId, PublicId, CacheTimeoutInterval, EntityURI MBean Changed : com.bea:Name=MyXMLRegistry,Type=XMLRegistry Attributes changed : XMLEntitySpecRegistryEntries Activation completed Disconnected from weblogic server: AdminServer Registry Created Successfully....
.
.
Regards,
Jay SenSharma