Search in sources :

Example 21 with ReflectException

use of com.shulie.instrument.simulator.api.reflect.ReflectException in project LinkAgent by shulieTech.

the class SpringBlockingQueueConsumerDeliveryInterceptorV2 method beforeTrace.

@Override
public SpanRecord beforeTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    if (args == null || args[0] == null) {
        return null;
    }
    initReflectionProps(advice.getTarget());
    Object deliveryObj = args[0];
    SpanRecord record = new SpanRecord();
    try {
        Envelope envelope = Reflect.on(deliveryObj).get(envelopeField);
        record.setService(envelope.getExchange());
        record.setMethod(envelope.getRoutingKey());
    } catch (ReflectException e) {
    }
    try {
        AMQP.BasicProperties properties = Reflect.on(deliveryObj).get(propertiesField);
        final Map<String, Object> headers = properties.getHeaders();
        if (headers != null) {
            Map<String, String> rpcContext = new HashMap<String, String>();
            for (String key : Pradar.getInvokeContextTransformKeys()) {
                String value = (String) headers.get(key);
                if (!StringUtil.isEmpty(value)) {
                    rpcContext.put(key, value);
                }
            }
            record.setContext(rpcContext);
        }
    } catch (ReflectException e) {
    }
    try {
        byte[] body = Reflect.on(deliveryObj).get(bodyField);
        record.setRequestSize(body.length);
        record.setRequest(body);
    } catch (ReflectException e) {
    }
    return record;
}
Also used : SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) AMQP(com.rabbitmq.client.AMQP) HashMap(java.util.HashMap) Envelope(com.rabbitmq.client.Envelope) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException)

Example 22 with ReflectException

use of com.shulie.instrument.simulator.api.reflect.ReflectException in project LinkAgent by shulieTech.

the class SpringBlockingQueueConsumerDeliveryInterceptorV2 method initEnvelopeField.

private void initEnvelopeField(Class deliveryClass) {
    if (propertiesField != null) {
        return;
    }
    try {
        envelopeField = deliveryClass.getDeclaredField("envelope");
        envelopeField.setAccessible(true);
    } catch (NoSuchFieldException e) {
        throw new ReflectException(e);
    }
}
Also used : ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException)

Example 23 with ReflectException

use of com.shulie.instrument.simulator.api.reflect.ReflectException in project LinkAgent by shulieTech.

the class SpringBlockingQueueConsumerDeliveryInterceptorV2 method initBodyField.

private void initBodyField(Class deliveryClass) {
    if (propertiesField != null) {
        return;
    }
    try {
        bodyField = deliveryClass.getDeclaredField("body");
        bodyField.setAccessible(true);
    } catch (NoSuchFieldException e) {
        throw new ReflectException(e);
    }
}
Also used : ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException)

Example 24 with ReflectException

use of com.shulie.instrument.simulator.api.reflect.ReflectException in project LinkAgent by shulieTech.

the class HttpClientv3MethodInterceptor method buildParameters.

private void buildParameters(HttpParams httpParams, Map map) {
    if (httpParams == null) {
        return;
    }
    if (!(httpParams instanceof DefaultHttpParams)) {
        return;
    }
    HttpParams defaults = httpParams.getDefaults();
    if (defaults != null) {
        buildParameters(defaults, map);
    }
    HashMap hashMap = null;
    try {
        hashMap = Reflect.on(httpParams).get(HttpClientConstants.DYNAMIC_FIELD_PARAMETERS);
    } catch (ReflectException e) {
        LOGGER.warn("{} has not field {}", httpParams.getClass().getName(), HttpClientConstants.DYNAMIC_FIELD_PARAMETERS);
    }
    if (hashMap != null) {
        map.putAll(hashMap);
    }
}
Also used : HttpParams(org.apache.commons.httpclient.params.HttpParams) DefaultHttpParams(org.apache.commons.httpclient.params.DefaultHttpParams) HashMap(java.util.HashMap) DefaultHttpParams(org.apache.commons.httpclient.params.DefaultHttpParams) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException)

Example 25 with ReflectException

use of com.shulie.instrument.simulator.api.reflect.ReflectException in project LinkAgent by shulieTech.

the class MappedStatementGetCacheInterceptor method cutoff0.

@Override
public CutOffResult cutoff0(Advice advice) {
    if (!Pradar.isClusterTest()) {
        return CutOffResult.passed();
    }
    try {
        Object cache = Reflect.on(advice.getTarget()).get(MybatisConstants.DYNAMIC_FIELD_CACHE);
        if (cache == null) {
            return CutOffResult.passed();
        }
    } catch (ReflectException e) {
        return CutOffResult.passed();
    }
    String currentNamespace = null;
    try {
        currentNamespace = Reflect.on(advice.getTarget()).get(MybatisConstants.DYNAMIC_FIELD_CURRENT_NAMESPACE);
    } catch (ReflectException e) {
        currentNamespace = manager.getDynamicField(advice.getTarget(), MybatisConstants.DYNAMIC_FIELD_CURRENT_NAMESPACE);
    }
    Cache cache = MybatisConstants.currentName2PtCacheMap.get(currentNamespace);
    return CutOffResult.cutoff(cache);
}
Also used : ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException) Cache(org.apache.ibatis.cache.Cache)

Aggregations

ReflectException (com.shulie.instrument.simulator.api.reflect.ReflectException)33 SpanRecord (com.pamirs.pradar.interceptor.SpanRecord)11 PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)6 IOException (java.io.IOException)6 Map (java.util.Map)6 JSONObject (com.alibaba.fastjson.JSONObject)4 Request (com.squareup.okhttp.Request)4 HashMap (java.util.HashMap)4 WrapperRequest (com.pamirs.attach.plugin.hessian.common.WrapperRequest)3 MatchConfig (com.pamirs.pradar.internal.config.MatchConfig)3 ProcessControlException (com.shulie.instrument.simulator.api.ProcessControlException)3 Method (java.lang.reflect.Method)3 URL (java.net.URL)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HessianInputFactory (com.caucho.hessian.io.HessianInputFactory)2 HessianSkeleton (com.caucho.hessian.server.HessianSkeleton)2 ExecutionForwardCall (com.pamirs.pradar.internal.adapter.ExecutionForwardCall)2 AMQP (com.rabbitmq.client.AMQP)2 Envelope (com.rabbitmq.client.Envelope)2 Headers (com.squareup.okhttp.Headers)2