Search in sources :

Example 16 with ReflectException

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

the class KafkaListenerContainerInterceptor method tryRefreshBeanFactory.

private boolean tryRefreshBeanFactory(Object target) {
    try {
        KafkaMessageListenerContainer kafkaMessageListenerContainer = Reflect.on(target).get("this$0");
        ApplicationEventPublisher applicationEventPublisher = kafkaMessageListenerContainer.getApplicationEventPublisher();
        if (applicationEventPublisher instanceof AnnotationConfigApplicationContext) {
            PradarSpringUtil.refreshBeanFactory((DefaultListableBeanFactory) ((AnnotationConfigApplicationContext) applicationEventPublisher).getAutowireCapableBeanFactory());
            return true;
        } else if (applicationEventPublisher instanceof AbstractRefreshableApplicationContext) {
            PradarSpringUtil.refreshBeanFactory((DefaultListableBeanFactory) ((AbstractRefreshableApplicationContext) applicationEventPublisher).getAutowireCapableBeanFactory());
            return true;
        } else {
            try {
                PradarSpringUtil.refreshBeanFactory((DefaultListableBeanFactory) Reflect.on(applicationEventPublisher).call("getAutowireCapableBeanFactory").get());
                return true;
            } catch (ReflectException e) {
                logger.warn("tryRefreshBeanFactory fail spring-kafka version is not support, applicationEventPublisher is a " + applicationEventPublisher.getClass().getName());
            }
        }
    } catch (Exception e) {
        logger.warn("kafka tryRefreshBeanFactory fail", e);
    }
    return false;
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AbstractRefreshableApplicationContext(org.springframework.context.support.AbstractRefreshableApplicationContext) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) KafkaMessageListenerContainer(org.springframework.kafka.listener.KafkaMessageListenerContainer) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException)

Example 17 with ReflectException

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

the class RedissonNodesStrategy method getAddress.

public static List getAddress(Config config) {
    SingleServerConfig singleServerConfig = null;
    try {
        singleServerConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_SINGLE_SERVER_CONFIG);
    } catch (ReflectException e) {
    }
    ClusterServersConfig clusterServersConfig = null;
    try {
        clusterServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_CLUSTER_SERVERS_CONFIG);
    } catch (ReflectException e) {
    }
    SentinelServersConfig sentinelServersConfig = null;
    try {
        sentinelServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_SENTINEL_SERVERS_CONFIG);
    } catch (ReflectException e) {
    }
    ReplicatedServersConfig replicatedServersConfig = null;
    try {
        replicatedServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_REPLICATED_SERVERS_CONFIG);
    } catch (ReflectException e) {
    }
    MasterSlaveServersConfig masterSlaveServersConfig = null;
    try {
        masterSlaveServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_MASTER_SLAVE_SERVERS_CONFIG);
    } catch (ReflectException e) {
    }
    if (singleServerConfig != null) {
        // 在这里返回的address在不同版本可能返回String,可能返回URI在这里做处理
        Object address = Reflect.on(singleServerConfig).get("address");
        String addressConvert = null;
        if (address instanceof URI) {
            URI uriConvert = (URI) address;
            addressConvert = RedissonUtils.addPre(new StringBuilder().append(uriConvert.getHost()).append(":").append(uriConvert.getPort()).toString());
        } else if (address instanceof String) {
            addressConvert = (String) address;
        }
        return RedissonUtils.removePre(addressConvert);
    } else if (clusterServersConfig != null) {
        return RedissonUtils.removePre(clusterServersConfig.getNodeAddresses());
    } else if (sentinelServersConfig != null) {
        List<String> result = RedissonUtils.removePre(sentinelServersConfig.getSentinelAddresses());
        result.add(sentinelServersConfig.getMasterName());
        return result;
    } else if (replicatedServersConfig != null) {
        return RedissonUtils.removePre(replicatedServersConfig.getNodeAddresses());
    } else if (masterSlaveServersConfig != null) {
        String master = masterSlaveServersConfig.getMasterAddress();
        Set<String> slave = masterSlaveServersConfig.getSlaveAddresses();
        List<String> result = new ArrayList(RedissonUtils.removePre(slave));
        result.addAll(RedissonUtils.removePre(master));
        return result;
    }
    return null;
}
Also used : ClusterServersConfig(org.redisson.config.ClusterServersConfig) ArrayList(java.util.ArrayList) SingleServerConfig(org.redisson.config.SingleServerConfig) MasterSlaveServersConfig(org.redisson.config.MasterSlaveServersConfig) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException) URI(java.net.URI) ReplicatedServersConfig(org.redisson.config.ReplicatedServersConfig) SentinelServersConfig(org.redisson.config.SentinelServersConfig)

Example 18 with ReflectException

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

the class HttpClientInterceptor method doBefore.

@Override
public void doBefore(Advice advice) {
    InnerWhiteListCheckUtil.check();
    Object target = advice.getTarget();
    ClusterTestUtils.validateClusterTest();
    HttpClient client = (HttpClient) target;
    MessageHeader header = null;
    try {
        initField(client);
        header = Reflect.on(client).get(FIELD);
    } catch (ReflectException e) {
        LOGGER.warn("{} has not field {}", client.getClass().getName(), JdkHttpConstants.DYNAMIC_FIELD_REQUESTS);
    }
    if (header == null) {
        header = new MessageHeader();
    }
    Map<String, String> ctx = Pradar.getInvokeContextTransformMap();
    for (Map.Entry<String, String> entry : ctx.entrySet()) {
        header.set(entry.getKey(), entry.getValue());
    }
    try {
        Reflect.on(client).set(FIELD, header);
    } catch (ReflectException e) {
        LOGGER.warn("{} has not field {}", client.getClass().getName(), JdkHttpConstants.DYNAMIC_FIELD_REQUESTS);
    }
}
Also used : HttpClient(sun.net.www.http.HttpClient) MessageHeader(sun.net.www.MessageHeader) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException) Map(java.util.Map)

Example 19 with ReflectException

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

the class HttpURLConnectionInterceptor method beforeTrace.

@Override
public SpanRecord beforeTrace(Advice advice) {
    InnerWhiteListCheckUtil.check();
    Object target = advice.getTarget();
    final HttpURLConnection request = (HttpURLConnection) target;
    boolean connected = false;
    try {
        initConnectedField(target);
        connected = Reflect.on(target).get(CONNECTED_FiELD);
    } catch (ReflectException e) {
        LOGGER.warn("{} has not field {}", target.getClass().getName(), JdkHttpConstants.DYNAMIC_FIELD_CONNECTED);
    }
    boolean connecting = false;
    try {
        initConnectingField(target);
        connecting = Reflect.on(target).get(CONNECTING_FiELD);
    } catch (ReflectException e) {
        LOGGER.warn("{} has not field {}", target.getClass().getName(), JdkHttpConstants.DYNAMIC_FIELD_CONNECTING);
    }
    if (connected) {
        advice.mark(MARK_CONNECTED);
    }
    if (connecting) {
        advice.mark(MARK_CONNECTING);
    }
    if (connected || connecting) {
        return null;
    }
    SpanRecord record = new SpanRecord();
    String host = request.getURL().getHost();
    int port = request.getURL().getPort();
    String path = request.getURL().getPath();
    record.setService(path);
    record.setMethod(StringUtils.upperCase(request.getRequestMethod()));
    record.setRemoteIp(host);
    record.setPort(port);
    return record;
}
Also used : SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) HttpURLConnection(java.net.HttpURLConnection) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException)

Example 20 with ReflectException

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

the class ConsumerMetaData method build.

public static ConsumerMetaData build(KafkaConsumer consumer) {
    Set<String> topics = consumer.subscription();
    try {
        Object coordinator = Reflect.on(consumer).get(KafkaConstants.REFLECT_FIELD_COORDINATOR);
        Object groupId = ReflectUtil.reflectSlience(consumer, KafkaConstants.REFLECT_FIELD_GROUP_ID);
        if (groupId == null) {
            groupId = ReflectUtil.reflectSlience(coordinator, KafkaConstants.REFLECT_FIELD_GROUP_ID);
            if (groupId == null) {
                throw new PressureMeasureError("未支持的kafka版本!未能获取groupId");
            }
        }
        String bootstrapServers = KafkaUtils.getBootstrapServers(consumer);
        String groupIdStr = "";
        if (groupId instanceof String) {
            groupIdStr = (String) groupId;
        } else {
            groupIdStr = ReflectUtil.reflectSlience(groupId, "value");
        }
        return new ConsumerMetaData(topics, groupIdStr, bootstrapServers);
    } catch (ReflectException e) {
        throw new PressureMeasureError(e);
    }
}
Also used : PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException)

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