<commit_before>package io.tracee.contextlogger.jms;

import io.tracee.contextlogger.ImplicitContext;
import io.tracee.contextlogger.builder.TraceeContextLogger;

import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
import javax.jms.Message;
import java.lang.reflect.Method;

/**
 * Message listener to detect exceptions that happened during jms message processing.
 * In case of an exception contextual information will be written to the log.
 * Created by <NAME>, holisticon AG on 13.03.14.
 */
public class TraceeJmsErrorMessageListener {

    @SuppressWarnings("unused")
    public TraceeJmsErrorMessageListener() {

    }

    @AroundInvoke
    public Object intercept(InvocationContext ctx) throws Exception {
        final boolean isMdbInvocation = isMessageListenerOnMessageMethod(ctx.getMethod());
        try {
            return ctx.proceed();
        } catch (Exception e) {

            if (isMdbInvocation) {
                TraceeContextLogger.createDefault().logJsonWithPrefixedMessage("TRACEE JMS ERROR CONTEXT LOGGING LISTENER  : ",
						ImplicitContext.COMMON, ImplicitContext.TRACEE, ctx, e);
            }

            throw e;
        }
    }

    final boolean isMessageListenerOnMessageMethod(Method method) {
        return "onMessage".equals(method.getName())
                && method.getParameterTypes().length == 1
                && method.getParameterTypes()[0] == Message.class;
    }

}<commit_msg>Let's do the reflection stuff only in case of exception<commit_after>package io.tracee.contextlogger.jms;

import io.tracee.contextlogger.ImplicitContext;
import io.tracee.contextlogger.builder.TraceeContextLogger;

import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
import javax.jms.Message;
import java.lang.reflect.Method;

/**
 * Message listener to detect exceptions that happened during jms message processing.
 * In case of an exception contextual information will be written to the log.
 * Created by <NAME>, holisticon AG on 13.03.14.
 */
public class TraceeJmsErrorMessageListener {

	static final String JSON_PREFIXED_MESSAGE = "TRACEE JMS ERROR CONTEXT LOGGING LISTENER  : ";

	@SuppressWarnings("unused")
    public TraceeJmsErrorMessageListener() {

    }

    @AroundInvoke
    public Object intercept(InvocationContext ctx) throws Exception {
        try {
            return ctx.proceed();
        } catch (Exception e) {
        	final boolean isMdbInvocation = isMessageListenerOnMessageMethod(ctx.getMethod());

            if (isMdbInvocation) {
                TraceeContextLogger.createDefault().logJsonWithPrefixedMessage(JSON_PREFIXED_MESSAGE,
						ImplicitContext.COMMON, ImplicitContext.TRACEE, ctx, e);
            }

            throw e;
        }
    }

    boolean isMessageListenerOnMessageMethod(Method method) {
        return "onMessage".equals(method.getName())
                && method.getParameterTypes().length == 1
                && method.getParameterTypes()[0] == Message.class;
    }

}
{'fraction_non_alphanumeric': 0.08694214876033057, 'fraction_numerical': 0.005289256198347108, 'mean_word_length': 3.3044096728307255, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2566968', 'n_tokens_mistral': 847, 'n_tokens_neox': 803, 'n_words': 197}