All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scouter.agent.AgentCommonConstant Maven / Gradle / Ivy

There is a newer version: 2.20.0
Show newest version
package scouter.agent;

/**
 * @author Gun Lee ([email protected]) on 2017. 2. 5.
 * Common constants for scouter agent.
 *
 */
public class AgentCommonConstant {
    public static final String REQUEST_ATTRIBUTE_INITIAL_TRACE_CONTEXT = "__scouter__itc__";
    public static final String REQUEST_ATTRIBUTE_TRACE_CONTEXT = "__scouter__tc__";
    public static final String REQUEST_ATTRIBUTE_ASYNC_DISPATCH = "__scouter__ad__";
    public static final String REQUEST_ATTRIBUTE_CALLER_TRANSFER_MAP = "__scouter__ctm__";
    public static final String REQUEST_ATTRIBUTE_ALL_DISPATCHED_TRACE_CONTEXT = "__scouter__adtc__";
    public static final String REQUEST_ATTRIBUTE_SELF_DISPATCHED = "__scouter__sd__";

    public static final String ASYNC_SERVLET_DISPATCHED_PREFIX = "f>";

    private static final char at = '@';

    public static String normalizeHashCode(String text) {
        if(text == null) return text;
        int atPos = text.lastIndexOf(at);
        if(atPos<=0) {
            return text;
        }

        if(text.length() >= atPos + 8 + 1) {
            try {
                text = normalizeHashCode(text, atPos, 8);
            } catch (NumberFormatException e) {
                try {
                    text = normalizeHashCode(text, atPos, 7);
                } catch (NumberFormatException e1) {
                    return text;
                }
            }
        } else if(text.length() >= atPos + 7 + 1) {
            try {
                text = normalizeHashCode(text, atPos, 7);
            } catch (NumberFormatException e) {
                return text;
            }
        }
        return text;
    }

    private static String normalizeHashCode(String text, int atPos, int length) {
        String hexa = text.substring(atPos+1, atPos+1+length);
        Long.parseLong(hexa, 16);
        if (text.length() > atPos + length + 1) {
            return text.substring(0, atPos+1) + text.substring(atPos+1+length);
        } else {
            return text.substring(0, atPos+1);
        }
    }

    public static void main(String[] args) {
        String serviceName = "xxxiej.s@dfljoeif@1c2ba103";
        System.out.println(normalizeHashCode(serviceName));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy