in log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/request/RequestContextMappings.java [52:99]
public RequestContextMappings(Class<?> clazz) {
if (clazz == null) {
throw new IllegalArgumentException("A RequestContext class must be provided");
}
Annotation annotation = clazz.getAnnotation(HeaderPrefix.class);
this.headerPrefix = annotation != null ? ((HeaderPrefix) annotation).value().toLowerCase() : DEFAULT_HEADER_PREFIX;
Field[] fields = clazz.getFields();
for (Field field : fields) {
if (!Modifier.isStatic(field.getModifiers())) {
continue;
}
if (field.getType().equals(String.class)) {
String fieldName;
try {
fieldName = (String) field.get(null);
} catch (IllegalAccessException ex) {
continue;
}
if (fieldName == null) {
continue;
}
annotation = field.getAnnotation(ClientServer.class);
if (annotation != null) {
mappings.put(fieldName.toLowerCase(), new ClientServerMapping(fieldName));
continue;
}
annotation = field.getAnnotation(Local.class);
if (annotation != null) {
mappings.put(fieldName.toLowerCase(), new LocalMapping(fieldName));
}
} else if (field.getType().equals(Supplier.class)) {
annotation = field.getAnnotation(Chained.class);
if (annotation != null) {
Chained chained = (Chained) annotation;
try {
@SuppressWarnings("unchecked")
Supplier<String> supplier = (Supplier<String>) field.get(null);
mappings.put(chained.fieldName().toLowerCase(),
new ChainedMapping(chained.fieldName(), chained.chainedFieldName(), supplier));
} catch (IllegalAccessException ex) {
throw new IllegalArgumentException("Unable to retrieve Supplier for chained field " + chained.fieldName());
}
}
}
}
mappings.entrySet().removeIf(a -> validateChained(a.getValue()));
}