
io.tracee.contextlogger.contextprovider.javaee.InvocationContextContextProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of contextlogger-impl Show documentation
Show all versions of contextlogger-impl Show documentation
Please refer to https://github.com/tracee/contextlogger.
The newest version!
package io.tracee.contextlogger.contextprovider.javaee;
import io.tracee.contextlogger.api.TraceeContextProvider;
import io.tracee.contextlogger.api.TraceeContextProviderMethod;
import io.tracee.contextlogger.api.WrappedContextData;
import io.tracee.contextlogger.contextprovider.Order;
import io.tracee.contextlogger.contextprovider.utility.NameStringValuePair;
import io.tracee.contextlogger.utility.RecursiveReflectionToStringStyle;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import javax.interceptor.InvocationContext;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Context provider for ProceedingJoinPoint.
* Created by Tobias Gindler, holisticon AG on 20.03.14.
*/
@TraceeContextProvider(displayName = "invocationContext", order = Order.EJB)
public class InvocationContextContextProvider implements WrappedContextData {
private InvocationContext invocationContext;
public InvocationContextContextProvider() {
}
public InvocationContextContextProvider(final InvocationContext invocationContext) {
this.invocationContext = invocationContext;
}
public final void setContextData(Object instance) throws ClassCastException {
this.invocationContext = (InvocationContext) instance;
}
public final Class getWrappedType() {
return InvocationContext.class;
}
@TraceeContextProviderMethod(displayName = "typeName", order = 0)
public final String getTypeName() {
return this.invocationContext != null && this.invocationContext.getTarget() != null && this.invocationContext.getTarget().getClass() != null ? this.invocationContext.getTarget().getClass().getCanonicalName() : null;
}
@TraceeContextProviderMethod(displayName = "methodName", order = 10)
public final String getMethodName() {
return this.invocationContext != null && this.invocationContext.getMethod() != null ? this.invocationContext.getMethod().getName() : null;
}
@TraceeContextProviderMethod(displayName = "parameters", order = 20)
public final List getParameters() {
List result = new ArrayList();
if (this.invocationContext != null) {
for (Object parameter : invocationContext.getParameters()) {
result.add(parameter != null ? parameter.toString() : null);
}
}
return result.size() > 0 ? result : null;
}
@TraceeContextProviderMethod(displayName = "serialized-target-instance",
order = 30)
public final String getSerializedTargetInstance() {
String result = null;
if (this.invocationContext != null) {
Object targetInstance = this.invocationContext.getTarget();
if (targetInstance != null) {
result = ReflectionToStringBuilder.reflectionToString(targetInstance, new RecursiveReflectionToStringStyle());
} else {
result = null;
}
}
return result;
}
@TraceeContextProviderMethod(displayName = "deserialized.contextData", order = 40)
public final List getContextData() {
List result = new ArrayList();
if (this.invocationContext != null) {
for (Map.Entry entry : this.invocationContext.getContextData().entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
final String deSerializedValue;
if (value != null) {
deSerializedValue = ReflectionToStringBuilder.reflectionToString(value, new RecursiveReflectionToStringStyle());
} else {
deSerializedValue = null;
}
result.add(new NameStringValuePair(key, deSerializedValue));
}
}
return result.size() > 0 ? result : null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy