Search in sources :

Example 66 with JMException

use of javax.management.JMException in project nhin-d by DirectProject.

the class RDBMSAuditor method registerMBean.

/*
	 * Register the MBean
	 */
private void registerMBean() {
    LOGGER.info("Registering RDBMSAuditor MBean");
    try {
        itemNames = new String[] { "Event Id", "Event Time", "Event Principal", "Event Name", "Event Type", "Contexts" };
        OpenType<?>[] types = { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, ArrayType.getArrayType(SimpleType.STRING) };
        eventType = new CompositeType("AuditEvent", "Direct Auditable Event", itemNames, itemNames, types);
    } catch (OpenDataException e) {
        LOGGER.error("Failed to create settings composite type: " + e.getLocalizedMessage(), e);
        return;
    }
    final Class<?> clazz = this.getClass();
    final StringBuilder objectNameBuilder = new StringBuilder(clazz.getPackage().getName());
    objectNameBuilder.append(":type=").append(clazz.getSimpleName());
    objectNameBuilder.append(",name=").append(UUID.randomUUID());
    try {
        final StandardMBean mbean = new StandardMBean(this, AuditorMBean.class);
        final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
        mbeanServer.registerMBean(mbean, new ObjectName(objectNameBuilder.toString()));
    } catch (JMException e) {
        LOGGER.error("Unable to register the RDBMSAuditors MBean", e);
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) OpenDataException(javax.management.openmbean.OpenDataException) StandardMBean(javax.management.StandardMBean) JMException(javax.management.JMException) CompositeType(javax.management.openmbean.CompositeType) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 67 with JMException

use of javax.management.JMException in project opennms by OpenNMS.

the class MBeanServerQuery method execute.

public QueryResult execute(MBeanServerConnection mbeanServerConnection) throws MBeanServerQueryException {
    try {
        if (filterCriteriaList.isEmpty()) {
            filterCriteriaList.add(new FilterCriteria());
        }
        // retrieve all Mbeans
        QueryResult queryResult = executeQuery(filterCriteriaList, mbeanServerConnection);
        queryResult.setTotalMBeanCount(mbeanServerConnection.getMBeanCount());
        // retrieve all ignoring Mbeans
        QueryResult ignoreResult = executeQuery(ignoreFilterList, mbeanServerConnection);
        // filter out all ignored attributes
        for (QueryResult.MBeanResult eachResult : ignoreResult.getMBeanResults()) {
            for (MBeanAttributeInfo eachAttribute : eachResult.attributeResult.attributes) {
                queryResult.remove(eachResult.objectName, eachAttribute);
            }
        }
        // now build the result
        if (!showEmptyMbeans) {
            queryResult.removeEmptyMBeanResults();
        }
        if (sort) {
            queryResult.sort();
        }
        if (fetchValues) {
            for (QueryResult.MBeanResult eachMbeanResult : queryResult.getMBeanResults()) {
                QueryResult.AttributeResult attributeResult = eachMbeanResult.attributeResult;
                for (MBeanAttributeInfo eachAttribute : attributeResult.attributes) {
                    if (eachAttribute.isReadable()) {
                        try {
                            Object value = mbeanServerConnection.getAttribute(eachMbeanResult.objectName, eachAttribute.getName());
                            attributeResult.setValue(eachAttribute, value);
                        } catch (Exception uoe) {
                            // while receiving the value an exception could occur, we mark
                            // the values as such.
                            attributeResult.setValue(eachAttribute, "ERROR: " + uoe.getMessage());
                        }
                    }
                }
            }
        }
        return queryResult;
    } catch (IOException | JMException e) {
        throw new MBeanServerQueryException(e);
    }
}
Also used : JMException(javax.management.JMException) IOException(java.io.IOException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) JMException(javax.management.JMException) IOException(java.io.IOException)

Example 68 with JMException

use of javax.management.JMException in project opennms by OpenNMS.

the class JmxCommand method execute.

protected void execute() throws CmdLineException, CmdRunException {
    try (JMXConnector connector = getJmxConnector()) {
        MBeanServerConnection mbeanServerConnection = connector.getMBeanServerConnection();
        execute(mbeanServerConnection);
    } catch (MBeanServerQueryException | JMException | IOException e) {
        throw new CmdRunException(e);
    }
}
Also used : JMXConnector(javax.management.remote.JMXConnector) MBeanServerQueryException(org.opennms.features.jmxconfiggenerator.jmxconfig.query.MBeanServerQueryException) JMException(javax.management.JMException) IOException(java.io.IOException) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 69 with JMException

use of javax.management.JMException in project Activiti by Activiti.

the class DefaultManagementMBeanAssembler method assemble.

public ModelMBean assemble(Object obj, ObjectName name) throws JMException {
    ModelMBeanInfo mbi = null;
    // use the default provided mbean which has been annotated with JMX
    // annotations
    LOG.trace("Assembling MBeanInfo for: {} from @ManagedResource object: {}", name, obj);
    mbi = assembler.getMBeanInfo(obj, null, name.toString());
    if (mbi == null) {
        return null;
    }
    RequiredModelMBean mbean = new RequiredModelMBean(mbi);
    try {
        mbean.setManagedResource(obj, "ObjectReference");
    } catch (InvalidTargetObjectTypeException e) {
        throw new JMException(e.getMessage());
    }
    // Allows the managed object to send notifications
    if (obj instanceof NotificationSenderAware) {
        ((NotificationSenderAware) obj).setNotificationSender(new NotificationSenderAdapter(mbean));
    }
    return mbean;
}
Also used : JMException(javax.management.JMException) NotificationSenderAware(org.activiti.management.jmx.annotations.NotificationSenderAware) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) RequiredModelMBean(javax.management.modelmbean.RequiredModelMBean)

Example 70 with JMException

use of javax.management.JMException in project OpenAM by OpenRock.

the class Agent method saml1TPConfig.

/**
     *  process saml1.x trusted partners (global)
     */
public static int saml1TPConfig(List<String> s1TPInfo) {
    String classMethod = "Agent.saml1TPConfig:";
    StringBuilder sb = new StringBuilder(classMethod);
    int sz = s1TPInfo.size();
    // until instrumentation done
    boolean skipSAML1EndPoints = true;
    Date startDate = new Date();
    if (debug.messageEnabled()) {
        sb.append("number of SAML1 Trusted Partners = ").append(sz).append("\n");
    }
    if (server == null) {
        // can't do anything without a server
        debug.error(classMethod + "no server");
        return -1;
    }
    for (int i = 0; i < sz; i++) {
        String pName = s1TPInfo.get(i);
        if (debug.messageEnabled()) {
            sb.append("    ").append(pName).append("\n");
        }
        SsoServerSAML1TrustPrtnrsEntryImpl sstpe = new SsoServerSAML1TrustPrtnrsEntryImpl(sunMib);
        sstpe.SAML1TrustPrtnrIndex = new Integer(i + 1);
        sstpe.SAML1TrustPrtnrName = getEscapedString(pName);
        SsoServerSAML1Svc sss = (SsoServerSAML1SvcImpl) sunMib.getSaml1SvcGroup();
        TableSsoServerSAML1TrustPrtnrsTable tptab = null;
        if (sss != null) {
            try {
                tptab = sss.accessSsoServerSAML1TrustPrtnrsTable();
            } catch (SnmpStatusException ex) {
                debug.error(classMethod + "getting SAML1 trusted partner table: ", ex);
                // can't do anything without the table
                return -2;
            }
        }
        if (tptab == null) {
            // can't do anything without the table
            return -2;
        }
        ObjectName aname = sstpe.createSsoServerSAML1TrustPrtnrsEntryObjectName(server);
        if (aname == null) {
            debug.error(classMethod + "Error creating object for SAML1 Trusted Partner '" + pName + "'");
            continue;
        }
        try {
            tptab.addEntry(sstpe, aname);
            if (sstpe != null) {
                server.registerMBean(sstpe, aname);
            }
        } catch (JMException ex) {
            debug.error(classMethod + pName + ": " + ex.getMessage());
        } catch (SnmpStatusException ex) {
            debug.error(classMethod + pName + ": " + ex.getMessage());
        }
    }
    if (debug.messageEnabled()) {
        debug.message(sb.toString());
    }
    /*
         *  while we're here, setup the 
         *    SAML1 Cache table (Artifacts and Assertions)
         *    SAML1 Endpoints for SOAPReceiver, POSTProfile,
         *      SAMLAware/ArtifactProfile
         */
    // assertions
    SsoServerSAML1CacheEntryImpl ssce = new SsoServerSAML1CacheEntryImpl(sunMib);
    ssce.SAML1CacheIndex = Integer.valueOf(1);
    ssce.SAML1CacheName = "Assertion_Cache";
    ssce.SAML1CacheMisses = 0L;
    ssce.SAML1CacheHits = 0L;
    ssce.SAML1CacheWrites = 0L;
    ssce.SAML1CacheReads = 0L;
    SsoServerSAML1SvcImpl sss = sunMib.getSaml1SvcGroup();
    TableSsoServerSAML1CacheTable tptab = null;
    if (sss != null) {
        try {
            tptab = sss.accessSsoServerSAML1CacheTable();
        } catch (SnmpStatusException ex) {
            debug.error(classMethod + "getting SAML1 Cache table: ", ex);
        }
    }
    if (tptab != null) {
        // if sss is null, so will tptab
        sss.assertCache = ssce;
        ObjectName aname = ssce.createSsoServerSAML1CacheEntryObjectName(server);
        if (aname == null) {
            debug.error(classMethod + "Error creating object for SAML1 Assertion Cache");
        } else {
            try {
                tptab.addEntry(ssce, aname);
                if (ssce != null) {
                    server.registerMBean(ssce, aname);
                }
            } catch (JMException ex) {
                debug.error(classMethod + "SAML1 Assertion Cache table: " + ex.getMessage());
            } catch (SnmpStatusException ex) {
                debug.error(classMethod + "SAML1 Assertion Cache table: " + ex.getMessage());
            }
        }
        // artifacts
        ssce = new SsoServerSAML1CacheEntryImpl(sunMib);
        ssce.SAML1CacheIndex = Integer.valueOf(2);
        ssce.SAML1CacheName = "Artifact_Cache";
        ssce.SAML1CacheMisses = 0L;
        ssce.SAML1CacheHits = 0L;
        ssce.SAML1CacheWrites = 0L;
        ssce.SAML1CacheReads = 0L;
        aname = ssce.createSsoServerSAML1CacheEntryObjectName(server);
        if (aname == null) {
            debug.error(classMethod + "Error creating object for SAML1 Artifact Cache");
        } else {
            try {
                tptab.addEntry(ssce, aname);
                if (ssce != null) {
                    server.registerMBean(ssce, aname);
                }
            } catch (JMException ex) {
                debug.error(classMethod + "SAML1 Artifact Cache table: " + ex.getMessage());
            } catch (SnmpStatusException ex) {
                debug.error(classMethod + "SAML1 Artifact Cache table: " + ex.getMessage());
            }
            sss.artifactCache = ssce;
        }
    }
    // SOAPReceiver endpoint
    if (!skipSAML1EndPoints) {
        SsoServerSAML1EndPointEntryImpl ssee = new SsoServerSAML1EndPointEntryImpl(sunMib);
        ssee.SAML1EndPointIndex = Integer.valueOf(1);
        ssee.SAML1EndPointName = "SOAPReceiver_EndPoint";
        ssee.SAML1EndPointRqtFailed = 0L;
        ssee.SAML1EndPointRqtOut = 0L;
        ssee.SAML1EndPointRqtIn = 0L;
        ssee.SAML1EndPointRqtAborted = 0L;
        ssee.SAML1EndPointStatus = "operational";
        TableSsoServerSAML1EndPointTable tetab = null;
        if (sss != null) {
            try {
                tetab = sss.accessSsoServerSAML1EndPointTable();
            } catch (SnmpStatusException ex) {
                debug.error(classMethod + "getting SAML1 EndPoint table: ", ex);
            }
        }
        if (tetab != null) {
            // if sss is null, so will tetab
            ObjectName aname = ssee.createSsoServerSAML1EndPointEntryObjectName(server);
            if (aname == null) {
                debug.error(classMethod + "Error creating object for SAML1 SOAPReceiver_EndPoint");
            } else {
                try {
                    tetab.addEntry(ssee, aname);
                    if (ssee != null) {
                        server.registerMBean(ssee, aname);
                    }
                } catch (JMException ex) {
                    debug.error(classMethod + "SAML1 SOAPReceiver EndPoint table: " + ex.getMessage());
                } catch (SnmpStatusException ex) {
                    debug.error(classMethod + "SAML1 SOAPReceiver EndPoint table: " + ex.getMessage());
                }
                sss.soapEP = ssee;
            }
            // POSTProfile table
            ssee = new SsoServerSAML1EndPointEntryImpl(sunMib);
            ssee.SAML1EndPointIndex = Integer.valueOf(2);
            ssee.SAML1EndPointName = "POSTProfile_EndPoint";
            ssee.SAML1EndPointRqtFailed = 0L;
            ssee.SAML1EndPointRqtOut = 0L;
            ssee.SAML1EndPointRqtIn = 0L;
            ssee.SAML1EndPointRqtAborted = 0L;
            ssee.SAML1EndPointStatus = "operational";
            aname = ssee.createSsoServerSAML1EndPointEntryObjectName(server);
            if (aname == null) {
                debug.error(classMethod + "Error creating object for SAML1 POSTProfile_EndPoint");
            } else {
                try {
                    tetab.addEntry(ssee, aname);
                    if (ssee != null) {
                        server.registerMBean(ssee, aname);
                    }
                } catch (JMException ex) {
                    debug.error(classMethod + "SAML1 POSTProfile EndPoint table: " + ex.getMessage());
                } catch (SnmpStatusException ex) {
                    debug.error(classMethod + "SAML1 POSTProfile EndPoint table: " + ex.getMessage());
                }
                sss.pprofEP = ssee;
            }
            // SAMLAware/ArtifactProfile table
            ssee = new SsoServerSAML1EndPointEntryImpl(sunMib);
            ssee.SAML1EndPointIndex = Integer.valueOf(3);
            ssee.SAML1EndPointName = "SAMLAware_EndPoint";
            ssee.SAML1EndPointRqtFailed = 0L;
            ssee.SAML1EndPointRqtOut = 0L;
            ssee.SAML1EndPointRqtIn = 0L;
            ssee.SAML1EndPointRqtAborted = 0L;
            ssee.SAML1EndPointStatus = "operational";
            aname = ssee.createSsoServerSAML1EndPointEntryObjectName(server);
            if (aname == null) {
                debug.error(classMethod + "Error creating object for SAML1 SAMLAware_EndPoint");
            } else {
                try {
                    tetab.addEntry(ssee, aname);
                    if (ssee != null) {
                        server.registerMBean(ssee, aname);
                    }
                } catch (JMException ex) {
                    debug.error(classMethod + "SAML1 SAMLAware/ArtifactProfile EndPoint table: " + ex.getMessage());
                } catch (SnmpStatusException ex) {
                    debug.error(classMethod + "SAML1 SAMLAware/ArtifactProfile EndPoint table: " + ex.getMessage());
                }
                sss.samlAwareEP = ssee;
            }
        }
    }
    // if (!skipSAML1EndPoints)
    Date stopDate = new Date();
    if (debug.messageEnabled()) {
        String stDate = sdf.format(startDate);
        String endDate = sdf.format(stopDate);
        debug.message("Agent.saml1TPConfig:\n    Start Time = " + stDate + "\n      End Time = " + endDate);
    }
    return 0;
}
Also used : SnmpStatusException(com.sun.management.snmp.SnmpStatusException) Date(java.util.Date) ObjectName(javax.management.ObjectName) JMException(javax.management.JMException)

Aggregations

JMException (javax.management.JMException)116 ObjectName (javax.management.ObjectName)66 MBeanServer (javax.management.MBeanServer)33 IOException (java.io.IOException)22 InstrumentationManager (org.apache.cxf.management.InstrumentationManager)13 MBeanInfo (javax.management.MBeanInfo)11 MalformedObjectNameException (javax.management.MalformedObjectNameException)11 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)9 SnmpStatusException (com.sun.management.snmp.SnmpStatusException)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 StandardMBean (javax.management.StandardMBean)7 RequiredModelMBean (javax.management.modelmbean.RequiredModelMBean)6 Date (java.util.Date)5 Attribute (javax.management.Attribute)5 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)5 Element (org.w3c.dom.Element)5 PostConstruct (javax.annotation.PostConstruct)4 ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)4