use of java.beans.IntrospectionException in project wildfly by wildfly.
the class EJBUtilities method createActivationSpecs.
public ActivationSpec createActivationSpecs(final String resourceAdapterName, final Class<?> messageListenerInterface, final Properties activationConfigProperties, final ClassLoader classLoader) {
try {
// first get the ra "identifier" (with which it is registered in the resource adapter repository) for the
// ra name
final String raIdentifier = ConnectorServices.getRegisteredResourceAdapterIdentifier(resourceAdapterName);
if (raIdentifier == null) {
throw EjbLogger.ROOT_LOGGER.unknownResourceAdapter(resourceAdapterName);
}
final ResourceAdapterRepository resourceAdapterRepository = getResourceAdapterRepository();
if (resourceAdapterRepository == null) {
throw EjbLogger.ROOT_LOGGER.resourceAdapterRepositoryUnAvailable();
}
// now get the message listeners for this specific ra identifier
final List<MessageListener> messageListeners = resourceAdapterRepository.getMessageListeners(raIdentifier);
if (messageListeners == null || messageListeners.isEmpty()) {
throw EjbLogger.ROOT_LOGGER.unknownMessageListenerType(messageListenerInterface.getName(), resourceAdapterName);
}
MessageListener requiredMessageListener = null;
// now find the expected message listener from the list of message listeners for this resource adapter
for (final MessageListener messageListener : messageListeners) {
if (messageListenerInterface.equals(messageListener.getType())) {
requiredMessageListener = messageListener;
break;
}
}
if (requiredMessageListener == null) {
throw EjbLogger.ROOT_LOGGER.unknownMessageListenerType(messageListenerInterface.getName(), resourceAdapterName);
}
// found the message listener, now finally create the activation spec
final Activation activation = requiredMessageListener.getActivation();
// filter out the activation config properties, specified on the MDB, which aren't accepted by the resource
// adaptor
final Properties validActivationConfigProps = this.filterUnknownActivationConfigProperties(resourceAdapterName, activation, activationConfigProperties);
// now set the activation config properties on the ActivationSpec
final ActivationSpec activationSpec = activation.createInstance();
BeanUtils.mapJavaBeanProperties(activationSpec, validActivationConfigProps);
return activationSpec;
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (ResourceException e) {
throw new RuntimeException(e);
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (NotFoundException e) {
throw new RuntimeException(e);
} catch (IntrospectionException e) {
throw new RuntimeException(e);
}
}
use of java.beans.IntrospectionException in project apex-core by apache.
the class AppDataPushAgent method extractFields.
private JSONObject extractFields(Object o) {
List<Field> fields;
Map<String, Method> methods;
if (cacheFields.containsKey(o.getClass())) {
fields = cacheFields.get(o.getClass());
} else {
fields = new ArrayList<>();
for (Class<?> c = o.getClass(); c != Object.class; c = c.getSuperclass()) {
Field[] declaredFields = c.getDeclaredFields();
for (Field field : declaredFields) {
field.setAccessible(true);
AutoMetric rfa = field.getAnnotation(AutoMetric.class);
if (rfa != null) {
field.setAccessible(true);
try {
fields.add(field);
} catch (Exception ex) {
LOG.debug("Error extracting fields for app data: {}. Ignoring.", ex.getMessage());
}
}
}
}
cacheFields.put(o.getClass(), fields);
}
JSONObject result = new JSONObject();
for (Field field : fields) {
try {
result.put(field.getName(), field.get(o));
} catch (Exception ex) {
// ignore
}
}
if (cacheGetMethods.containsKey(o.getClass())) {
methods = cacheGetMethods.get(o.getClass());
} else {
methods = new HashMap<>();
try {
BeanInfo info = Introspector.getBeanInfo(o.getClass());
for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
Method method = pd.getReadMethod();
if (pd.getReadMethod() != null) {
AutoMetric rfa = method.getAnnotation(AutoMetric.class);
if (rfa != null) {
methods.put(pd.getName(), method);
}
}
}
} catch (IntrospectionException ex) {
// ignore
}
cacheGetMethods.put(o.getClass(), methods);
}
for (Map.Entry<String, Method> entry : methods.entrySet()) {
try {
result.put(entry.getKey(), entry.getValue().invoke(o));
} catch (Exception ex) {
// ignore
}
}
return result;
}
use of java.beans.IntrospectionException in project lucene-solr by apache.
the class MetricUtils method addMXBeanMetrics.
/**
* Creates a set of metrics (gauges) that correspond to available bean properties for the provided MXBean.
* @param obj an instance of MXBean
* @param intf MXBean interface, one of {@link PlatformManagedObject}-s
* @param consumer consumer for created names and metrics
* @param <T> formal type
*/
public static <T extends PlatformManagedObject> void addMXBeanMetrics(T obj, Class<? extends T> intf, String prefix, BiConsumer<String, Metric> consumer) {
if (intf.isInstance(obj)) {
BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(intf, intf.getSuperclass(), Introspector.IGNORE_ALL_BEANINFO);
} catch (IntrospectionException e) {
LOG.warn("Unable to fetch properties of MXBean " + obj.getClass().getName());
return;
}
for (final PropertyDescriptor desc : beanInfo.getPropertyDescriptors()) {
final String name = desc.getName();
// test if it works at all
try {
desc.getReadMethod().invoke(obj);
// worked - consume it
final Gauge<?> gauge = () -> {
try {
return desc.getReadMethod().invoke(obj);
} catch (InvocationTargetException ite) {
// ignore (some properties throw UOE)
return null;
} catch (IllegalAccessException e) {
return null;
}
};
String metricName = MetricRegistry.name(prefix, name);
consumer.accept(metricName, gauge);
} catch (Exception e) {
// didn't work, skip it...
}
}
}
}
use of java.beans.IntrospectionException in project lucene-solr by apache.
the class SolrPluginUtils method findSetter.
private static Method findSetter(Class<?> clazz, String setterName, String key, Class<?> paramClazz, boolean lenient) {
BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(clazz);
} catch (IntrospectionException ie) {
if (lenient) {
return null;
}
throw new RuntimeException("Error getting bean info for class : " + clazz.getName(), ie);
}
for (final boolean matchParamClazz : new boolean[] { true, false }) {
for (final MethodDescriptor desc : beanInfo.getMethodDescriptors()) {
final Method m = desc.getMethod();
final Class<?>[] p = m.getParameterTypes();
if (m.getName().equals(setterName) && p.length == 1 && (!matchParamClazz || paramClazz.equals(p[0]))) {
return m;
}
}
}
if (lenient) {
return null;
}
throw new RuntimeException("No setter corrresponding to '" + key + "' in " + clazz.getName());
}
use of java.beans.IntrospectionException in project jmeter by apache.
the class TestBeanHelper method prepare.
/**
* Prepare the bean for work by populating the bean's properties from the
* property value map.
* <p>
*
* @param el the TestElement to be prepared
*/
public static void prepare(TestElement el) {
if (!(el instanceof TestBean)) {
return;
}
try {
BeanInfo beanInfo = Introspector.getBeanInfo(el.getClass());
PropertyDescriptor[] descs = beanInfo.getPropertyDescriptors();
if (log.isDebugEnabled()) {
log.debug("Preparing {}", el.getClass());
}
for (PropertyDescriptor desc : descs) {
if (isDescriptorIgnored(desc)) {
if (log.isDebugEnabled()) {
log.debug("Ignoring property '{}' in {}", desc.getName(), el.getClass().getCanonicalName());
}
continue;
}
// Obtain a value of the appropriate type for this property.
JMeterProperty jprop = el.getProperty(desc.getName());
Class<?> type = desc.getPropertyType();
Object value = unwrapProperty(desc, jprop, type);
if (log.isDebugEnabled()) {
log.debug("Setting {}={}", jprop.getName(), value);
}
// Set the bean's property to the value we just obtained:
if (value != null || !type.isPrimitive()) // We can't assign null to primitive types.
{
Method writeMethod = desc.getWriteMethod();
if (writeMethod != null) {
invokeOrBailOut(el, writeMethod, new Object[] { value });
}
}
}
} catch (IntrospectionException e) {
log.error("Couldn't set properties for {}", el.getClass(), e);
} catch (UnsatisfiedLinkError ule) {
// Can occur running headless on Jenkins
log.error("Couldn't set properties for {}", el.getClass());
throw ule;
}
}
Aggregations