How to get the audit level settings of a Composite through Java - Oracle SOA Suite
This blog will explain how to get the audit level settings of a Composite through Java in Oracle SOA Suite
import java.util.Hashtable;
import java.util.Set;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.naming.Context;
import oracle.fabric.composite.model.CompositeNameModel;
public class GetCompositeAuditLevel {
static MBeanServerConnection m_connection = null;
public static String getCompositeAuditLevel(String compositeName,String version) throws Exception {
String auditLevel = "";
String mBeanName = "*:j2eeType=SCAComposite,revision=" + version + ",*,name=\"" + compositeName + "\"";
Set<ObjectName> mbeans = m_connection.queryNames(new ObjectName(mBeanName), null);
System.out.println(mbeans);
ObjectName mbean = (ObjectName)mbeans.iterator().next();
javax.management.openmbean.CompositeData[] properties =(javax.management.openmbean.CompositeData[])m_connection.getAttribute(mbean,"Properties");
if (properties.length > 0) {
for (int i = 0; i < properties.length; i++) {
CompositeDataSupport cds = (CompositeDataSupport)properties[i];
if (cds.get("name").equals("auditLevel")) {
auditLevel = (String)cds.get("value");
break;
}
auditLevel = "Inherit";
}
}
if (auditLevel.equals("Inherit")) {
auditLevel = getSOAINFRAAuditLevel();
}
return auditLevel;
}
public static String getSOAINFRAAuditLevel() throws Exception {
String auditLevel = "";
String mBeanName ="*:*,name=soa-infra,type=SoaInfraConfig,Application=soa-infra";
Set<ObjectName> mbeans = m_connection.queryNames(new ObjectName(mBeanName), null);
ObjectName mbean = (ObjectName)mbeans.iterator().next();
auditLevel = (String)m_connection.getAttribute(mbean, "AuditLevel");
return auditLevel;
}
public static String getDefaultCompositeRevision(String partiitionName,
String compositeName) throws Exception {
ObjectName compositeLifeCycleMBean = null;
Set queryResult = m_connection.queryNames(new ObjectName("*:j2eeType=CompositeLifecycleConfig,*"), null);
if (!queryResult.isEmpty()) {
compositeLifeCycleMBean =(ObjectName)queryResult.iterator().next();
}
//CompositeDN - DomainName/CompositeName
String compositeDN = partiitionName + '/' + compositeName;
String revision = null;
CompositeData deployedComposite =(CompositeData)m_connection.invoke(compositeLifeCycleMBean, "getDefaultComposite",
new Object[] { compositeDN },
new String[] { String.class.getName() });
if (deployedComposite != null) {
CompositeNameModel cm = CompositeNameModel.parseDN((String)deployedComposite.get("DN"));
revision = cm.getRevision();
}
return revision;
}
public static MBeanServerConnection getMbeanServerConnection(String host,int port,String userName,
String password) throws Exception {
String jndiroot = "/jndi/";
MBeanServerConnection m_connection = null;
try {
Hashtable jndiProps = new Hashtable();
jndiProps.put(Context.SECURITY_PRINCIPAL, userName);
jndiProps.put(Context.SECURITY_CREDENTIALS, password);
jndiProps.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote");
JMXServiceURL serviceURL =new JMXServiceURL("t3", host, port, jndiroot +"weblogic.management.mbeanservers.runtime");
JMXConnector m_connector =JMXConnectorFactory.newJMXConnector(serviceURL, jndiProps);
m_connector.connect();
m_connection = m_connector.getMBeanServerConnection();
} catch (Exception e) {
e.printStackTrace();
}
return m_connection;
}
public static void main(String[] args) {
try {
m_connection =getMbeanServerConnection("localhost", 7001,"weblogic", "welcome1");
String defaultVersion =getDefaultCompositeRevision("default", "TestComposite");
String auditLevel=getCompositeAuditLevel("TestComposite", defaultVersion);
System.out.println("auditLevel:"+auditLevel);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Jar files required in the class path:
- SOA Runtime jars
- weblogic.jar