Created
March 9, 2013 02:46
-
-
Save dunse/5122258 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////////////////////////////////////////////////////// | |
// getbs.js - Copyright (c) 2013 Pehr Johansson <[email protected]> | |
// | |
// This program is free software: you can redistribute it and/or modify | |
// it under the terms of the GNU Lesser General Public License as published | |
// by the Free Software Foundation, either version 3 of the License, or | |
// (at your option) any later version. | |
// | |
// This program is distributed in the hope that it will be useful, | |
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
// GNU Lesser General Public License for more details. | |
// | |
// You should have received a copy of the GNU Lesser General Public License | |
// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
//////////////////////////////////////////////////////////////////////////////////// | |
var java = require('java'); | |
var config = { | |
admin_server: { | |
"hostname": "my_admin.server.com", | |
"port": 7001, | |
"username": "weblogic", | |
"password": "weblogic" | |
} | |
}; | |
// OSB: Only setup classpath once | |
java.classpath.push('configfwk-1.1.0.0.jar'); | |
java.classpath.push('sb-kernel-impl-1.1.3.0.jar'); | |
java.classpath.push('sb-kernel-api-3.0.jar'); | |
java.classpath.push('sb-kernel-common-1.1.3.0.jar'); | |
java.classpath.push('wlfullclient-10.3.0.jar'); | |
java.classpath.push('standalone_client-11.1.1.jar'); | |
function getOSBBusinessServiceEndpoints() { | |
// Imports | |
var JMXServiceURL = java.import('javax.management.remote.JMXServiceURL'); | |
var DomainRuntimeServiceMBean = java.import('weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean'); | |
var Hashtable = java.import('java.util.Hashtable'); | |
var Context = java.import('javax.naming.Context'); | |
var JMXConnectorFactory = java.import('javax.management.remote.JMXConnectorFactory'); | |
var JMXConnector = java.import('javax.management.remote.JMXConnector'); | |
var ALSBConfigurationMBean = java.import('com.bea.wli.sb.management.configuration.ALSBConfigurationMBean'); | |
var ObjectName = java.import('javax.management.ObjectName'); | |
var Collections = java.import('java.util.Collections') | |
var EnvValueQuery = java.import('com.bea.wli.config.env.EnvValueQuery'); | |
var Iterator = java.import('java.util.Iterator'); | |
var QualifiedEnvValue = java.import('com.bea.wli.config.env.QualifiedEnvValue'); | |
var MBeanServerInvocationHandler = java.import('weblogic.management.jmx.MBeanServerInvocationHandler'); | |
var Refs = java.import('com.bea.wli.sb.util.Refs'); | |
var EnvValueTypes = java.import('com.bea.wli.sb.util.EnvValueTypes'); | |
// Connect | |
var admin_server = config.admin_server | |
var serviceURL = new JMXServiceURL('t3', admin_server.hostname, admin_server.port, | |
'/jndi/' + DomainRuntimeServiceMBean.MBEANSERVER_JNDI_NAME); | |
var h = new Hashtable(); | |
var username = admin_server.username; | |
var password = admin_server.password; | |
h.putSync(Context.SECURITY_PRINCIPAL, username); | |
if (password == null) password = username; | |
h.putSync(Context.SECURITY_CREDENTIALS, password); | |
h.putSync(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, 'weblogic.management.remote'); | |
var conn = JMXConnectorFactory.connectSync(serviceURL, h); | |
var mbconn = conn.getMBeanServerConnectionSync(); | |
// Get MBeans | |
var domainService = | |
MBeanServerInvocationHandler.newProxyInstanceSync( | |
mbconn, new ObjectName(DomainRuntimeServiceMBean.OBJECT_NAME)); | |
var alsbCore = domainService.findServiceSync( | |
ALSBConfigurationMBean.NAME, | |
ALSBConfigurationMBean.TYPE, null); | |
// Search for Service URI's part of Business Service | |
var evquery = new EnvValueQuery( | |
Collections.singletonSync(Refs.BUSINESS_SERVICE_TYPE), // null means all resource types | |
Collections.singletonSync(EnvValueTypes.SERVICE_URI), // envValueTypes (i.e. search URIs) | |
null, // refsToSearch | |
false, // includeOnlyModifiedResources | |
null, // searchString | |
false // isCompleteMatch | |
); | |
var results = alsbCore.findEnvValuesSync(evquery); | |
results.toArraySync().forEach(function(result) { | |
console.log(result.getOwnerSync().getFullNameSync() + "\t=>\t" + result.getValueSync()); | |
}); | |
} | |
getOSBBusinessServiceEndpoints(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment