Search in sources :

Example 1 with ReflectException

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

the class HessianProxyWrapper method exceptionTrace.

public SpanRecord exceptionTrace(Object target, String methodName, Method method, Object[] args, Throwable throwable) {
    if (args == null || args.length == 0) {
        return null;
    }
    Class<?> type = getType(target, method, args);
    if (type == null) {
        return null;
    }
    SpanRecord spanRecord = new SpanRecord();
    spanRecord.setService(type.getName());
    spanRecord.setMethod(method.getName());
    spanRecord.setRequest(args);
    spanRecord.setResponse(throwable);
    spanRecord.setResultCode(ResultCode.INVOKE_RESULT_FAILED);
    URL url = null;
    try {
        url = Reflect.on(target).get(HessianConstants.DYNAMIC_FIELD_URL);
    } catch (ReflectException e) {
    }
    if (url != null) {
        String host = url.getHost();
        int port = url.getPort();
        if (port == 80 || port == -1) {
            host = host + ":" + port;
        }
        spanRecord.setRemoteIp(host);
    }
    return spanRecord;
}
Also used : SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException) URL(java.net.URL)

Example 2 with ReflectException

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

the class HessianProxyWrapper method beforeTrace.

public SpanRecord beforeTrace(Object target, String methodName, Method method, Object[] args) {
    if (args == null || args.length == 0) {
        return null;
    }
    Class<?> type = getType(target, method, args);
    if (type == null) {
        return null;
    }
    manager.setDynamicField(target, HessianConstants.DYNAMIC_FIELD_METHOD, method);
    SpanRecord spanRecord = new SpanRecord();
    spanRecord.setService(type.getName());
    spanRecord.setMethod(method.getName());
    spanRecord.setRequest(args);
    URL url = null;
    try {
        url = Reflect.on(target).get(HessianConstants.DYNAMIC_FIELD_URL);
    } catch (ReflectException e) {
    }
    if (url != null) {
        String host = url.getHost();
        int port = url.getPort();
        if (port == 80 || port == -1) {
            host = host + ":" + port;
        }
        spanRecord.setRemoteIp(host);
    }
    return spanRecord;
}
Also used : SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException) URL(java.net.URL)

Example 3 with ReflectException

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

the class HessianProxyWrapper method afterTrace.

public SpanRecord afterTrace(Object target, String methodName, Method method, Object[] args, Object result) {
    if (args == null || args.length == 0) {
        return null;
    }
    Class<?> type = getType(target, method, args);
    if (type == null) {
        return null;
    }
    SpanRecord spanRecord = new SpanRecord();
    spanRecord.setService(type.getName());
    spanRecord.setMethod(method.getName());
    spanRecord.setRequest(args);
    spanRecord.setResponse(result);
    URL url = null;
    try {
        url = Reflect.on(target).get(HessianConstants.DYNAMIC_FIELD_URL);
    } catch (ReflectException e) {
    }
    if (url != null) {
        String host = url.getHost();
        int port = url.getPort();
        if (port == 80 || port == -1) {
            host = host + ":" + port;
        }
        spanRecord.setRemoteIp(host);
    }
    return spanRecord;
}
Also used : SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException) URL(java.net.URL)

Example 4 with ReflectException

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

the class RealCallEnqueueV2Interceptor method beforeFirst.

@Override
public void beforeFirst(Advice advice) throws ProcessControlException {
    Object target = advice.getTarget();
    Request request = null;
    try {
        request = Reflect.on(target).get(OKHttpConstants.DYNAMIC_FIELD_REQUEST);
    } catch (ReflectException e) {
        request = Reflect.on(target).get(OKHttpConstants.DYNAMIC_FIELD_ORIGINAL_REQUEST);
    }
    final String url = request.urlString();
    final MatchConfig config = ClusterTestUtils.httpClusterTest(url);
    String check = request.header(OKHttpConstants.DYNAMIC_FIELD_HEADER);
    config.addArgs(PradarService.PRADAR_WHITE_LIST_CHECK, check);
    config.addArgs("url", url);
    config.addArgs("isInterface", Boolean.FALSE);
    final Request finalRequest = request;
    config.getStrategy().processBlock(advice.getBehavior().getReturnType(), advice.getClassLoader(), config, new ExecutionForwardCall() {

        @Override
        public Object forward(Object param) throws ProcessControlException {
            HttpUrl httpUrl = HttpUrl.parse(config.getForwarding());
            Reflect.on(finalRequest).set("url", httpUrl);
            return null;
        }

        @Override
        public Object call(Object param) {
            Headers header = Headers.of(new String[0]);
            Buffer buffer = new Buffer();
            try {
                if (param instanceof String) {
                    buffer.write(String.valueOf(param).getBytes("UTF-8"));
                } else {
                    buffer.write(JSONObject.toJSONBytes(param));
                }
            } catch (IOException e) {
            }
            return new Response.Builder().code(200).body(new RealResponseBody(header, buffer)).request(finalRequest).protocol(Protocol.HTTP_1_0).message("OK").build();
        }
    });
}
Also used : Buffer(okio.Buffer) ProcessControlException(com.shulie.instrument.simulator.api.ProcessControlException) Headers(com.squareup.okhttp.Headers) MatchConfig(com.pamirs.pradar.internal.config.MatchConfig) RealResponseBody(com.squareup.okhttp.internal.http.RealResponseBody) Request(com.squareup.okhttp.Request) IOException(java.io.IOException) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException) HttpUrl(okhttp3.HttpUrl) ExecutionForwardCall(com.pamirs.pradar.internal.adapter.ExecutionForwardCall) Response(com.squareup.okhttp.Response) JSONObject(com.alibaba.fastjson.JSONObject)

Example 5 with ReflectException

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

the class RealCallEnqueueV2Interceptor method beforeTrace.

@Override
public SpanRecord beforeTrace(Advice advice) {
    InnerWhiteListCheckUtil.check();
    Object target = advice.getTarget();
    Request request = null;
    try {
        request = Reflect.on(target).get(OKHttpConstants.DYNAMIC_FIELD_REQUEST);
    } catch (ReflectException e) {
        request = Reflect.on(target).get(OKHttpConstants.DYNAMIC_FIELD_ORIGINAL_REQUEST);
    }
    SpanRecord record = new SpanRecord();
    record.setRemoteIp(request.url().getHost());
    record.setPort(request.url().getPort());
    record.setService(request.url().getPath());
    record.setMethod(StringUtils.upperCase(request.method()));
    record.setRequest(request.url().getQuery());
    String header = request.header("content-length");
    if (StringUtils.isNotBlank(header) && NumberUtils.isDigits(header)) {
        try {
            record.setRequestSize(Integer.valueOf(header));
        } catch (NumberFormatException e) {
        }
    }
    return record;
}
Also used : SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) Request(com.squareup.okhttp.Request) JSONObject(com.alibaba.fastjson.JSONObject) 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