use of javax.management.openmbean.OpenDataException in project nhin-d by DirectProject.
the class FileAuditor method registerMBean.
/*
* Register the MBean
*/
private void registerMBean() {
LOGGER.info("Registering FileAuditor 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;
}
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 FileAuditor MBean", e);
}
}
use of javax.management.openmbean.OpenDataException 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);
}
}
use of javax.management.openmbean.OpenDataException in project nhin-d by DirectProject.
the class RDBMSAuditor method getEvents.
/**
* {@inheritDoc}
*/
@Override
public CompositeData[] getEvents(Integer eventCount) {
if (eventType == null || eventCount == 0)
return null;
final Vector<CompositeData> retVal = new Vector<CompositeData>();
final Collection<org.nhindirect.common.audit.impl.entity.AuditEvent> rs = this.dao.getRDBMSEvents(eventCount);
if (rs.size() == 0)
return null;
for (org.nhindirect.common.audit.impl.entity.AuditEvent event : rs) {
String[] contexts = null;
if (event.getAuditContexts() != null && !event.getAuditContexts().isEmpty()) {
contexts = new String[event.getAuditContexts().size()];
int idx = 0;
for (org.nhindirect.common.audit.impl.entity.AuditContext ctx : event.getAuditContexts()) {
contexts[idx++] = ctx.getContextName() + ":" + ctx.getContextValue();
}
}
if (contexts == null)
contexts = new String[] { " " };
try {
final Object[] eventValues = { event.getUUID(), event.getEventTime().toString(), event.getPrincipal(), event.getEventName(), event.getEventType(), contexts };
retVal.add(new CompositeDataSupport(eventType, itemNames, eventValues));
} catch (OpenDataException e) {
LOGGER.error("Error create composit data for audit event.", e);
}
}
return retVal.toArray(new CompositeData[retVal.size()]);
}
use of javax.management.openmbean.OpenDataException in project jdk8u_jdk by JetBrains.
the class MXBeanLookup method mxbeanToObjectName.
synchronized ObjectName mxbeanToObjectName(Object mxbean) throws OpenDataException {
String wrong;
if (mxbean instanceof Proxy) {
InvocationHandler ih = Proxy.getInvocationHandler(mxbean);
if (ih instanceof MBeanServerInvocationHandler) {
MBeanServerInvocationHandler mbsih = (MBeanServerInvocationHandler) ih;
if (mbsih.getMBeanServerConnection().equals(mbsc))
return mbsih.getObjectName();
else
wrong = "proxy for a different MBeanServer";
} else
wrong = "not a JMX proxy";
} else {
ObjectName name = mxbeanToObjectName.get(mxbean);
if (name != null)
return name;
wrong = "not an MXBean registered in this MBeanServer";
}
String s = (mxbean == null) ? "null" : "object of type " + mxbean.getClass().getName();
throw new OpenDataException("Could not convert " + s + " to an ObjectName: " + wrong);
// Message will be strange if mxbean is null but it is not
// supposed to be.
}
use of javax.management.openmbean.OpenDataException in project jdk8u_jdk by JetBrains.
the class ConvertingMethod method invokeWithOpenReturn.
private Object invokeWithOpenReturn(Object obj, Object[] params) throws MBeanException, IllegalAccessException, InvocationTargetException {
final Object[] javaParams;
try {
javaParams = fromOpenParameters(params);
} catch (InvalidObjectException e) {
// probably can't happen
final String msg = methodName() + ": cannot convert parameters " + "from open values: " + e;
throw new MBeanException(e, msg);
}
final Object javaReturn = MethodUtil.invoke(method, obj, javaParams);
try {
return returnMapping.toOpenValue(javaReturn);
} catch (OpenDataException e) {
// probably can't happen
final String msg = methodName() + ": cannot convert return " + "value to open value: " + e;
throw new MBeanException(e, msg);
}
}
Aggregations