Search in sources :

Example 26 with ReflectException

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

the class MapperBuilderAssistantUseNewCacheInterceptor method doAfter.

@Override
public void doAfter(Advice advice) {
    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);
    }
    Object[] args = advice.getParameterArray();
    Class<? extends Cache> typeClass = (Class<? extends Cache>) args[0];
    Class<? extends Cache> evictionClass = (Class<? extends Cache>) args[1];
    Long flushInterval = (Long) args[2];
    Integer size = (Integer) args[3];
    boolean readWrite = (Boolean) args[4];
    boolean blocking = (Boolean) args[5];
    Properties props = (Properties) args[6];
    Cache ptCache = initPtCache(Pradar.CLUSTER_TEST_PREFIX + currentNamespace, typeClass, evictionClass, flushInterval, size, readWrite, blocking, props);
    MybatisConstants.currentName2PtCacheMap.put(currentNamespace, ptCache);
}
Also used : Properties(java.util.Properties) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException) Cache(org.apache.ibatis.cache.Cache) PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) LruCache(org.apache.ibatis.cache.decorators.LruCache)

Example 27 with ReflectException

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

the class BurlapServletServiceInterceptor method beforeTrace.

@Override
public SpanRecord beforeTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    Object target = advice.getTarget();
    if (args == null || args.length == 0) {
        return null;
    }
    if (!(args[0] instanceof HttpServletRequest)) {
        if (Pradar.isClusterTest()) {
            throw new PressureMeasureError("hessian servlet trace err! can't cast to HttpServletRequest");
        }
        return null;
    }
    WrapperRequest request = (WrapperRequest) args[0];
    if (!request.getMethod().equals("POST") && !request.getMethod().equals("post")) {
        return null;
    }
    String method = request.getHeader(HessianConstants.METHOD_HEADER);
    BurlapServlet burlapServlet = (BurlapServlet) target;
    BurlapSkeleton hessianSkeleton = null;
    try {
        hessianSkeleton = Reflect.on(burlapServlet).get(HessianConstants.DYNAMIC_FIELD_SKELETON);
    } catch (ReflectException e) {
    }
    Object[] result = getMethodArgs(request.getInputStream(), hessianSkeleton);
    Object[] arguments = (Object[]) result[1];
    if (method == null) {
        method = (String) result[0];
    }
    Class<?> clazz = null;
    try {
        clazz = Reflect.on(burlapServlet).get(HessianConstants.DYNAMIC_FIELD_TYPE);
    } catch (ReflectException e) {
    }
    SpanRecord spanRecord = new SpanRecord();
    spanRecord.setService(clazz == null ? null : clazz.getName());
    spanRecord.setMethod(method);
    spanRecord.setRequest(arguments);
    spanRecord.setPort(request.getRemotePort());
    return spanRecord;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) BurlapServlet(com.caucho.burlap.server.BurlapServlet) SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) WrapperRequest(com.pamirs.attach.plugin.hessian.common.WrapperRequest) BurlapSkeleton(com.caucho.burlap.server.BurlapSkeleton) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException)

Example 28 with ReflectException

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

the class BurlapServletServiceInterceptor method getMethodArgs.

public Object[] getMethodArgs(InputStream is, BurlapSkeleton burlapSkeleton) {
    try {
        BurlapInput in = new BurlapInput(is);
        HessianInputFactory.HeaderType header = _inputFactory.readHeader(is);
        while ((in.readHeader()) != null) {
            in.readObject();
        }
        String methodName = in.readMethod();
        int argLength = in.readMethodArgLength();
        Method method = null;
        try {
            Map map = Reflect.on(burlapSkeleton).get(HessianConstants.DYNAMIC_FIELD_METHOD_MAP);
            method = (Method) map.get(methodName + "__" + argLength);
        } catch (ReflectException e) {
        }
        if (method != null) {
        } else if ("_hessian_getAttribute".equals(methodName)) {
            String attrName = in.readString();
            in.completeCall();
        } else if (method == null) {
        }
        Class<?>[] args = method.getParameterTypes();
        if (argLength != args.length && argLength >= 0) {
            return null;
        }
        Object[] values = new Object[args.length];
        for (int i = 0; i < args.length; i++) {
            values[i] = in.readObject(args[i]);
        }
        in.completeCall();
        return new Object[] { methodName, args };
    } catch (IOException e) {
        return EMPTY_ARGS;
    }
}
Also used : Method(java.lang.reflect.Method) IOException(java.io.IOException) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException) BurlapInput(com.caucho.burlap.io.BurlapInput) HessianInputFactory(com.caucho.hessian.io.HessianInputFactory) Map(java.util.Map)

Example 29 with ReflectException

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

the class HessianServiceExporterHandleRequestInterceptor method getMethodArgs.

public Object[] getMethodArgs(InputStream is, SerializerFactory serializerFactory, HessianSkeleton hessianSkeleton) {
    try {
        InputStream isToUse = is;
        if (!isToUse.markSupported()) {
            isToUse = new BufferedInputStream(isToUse);
            isToUse.mark(1);
        }
        int code = isToUse.read();
        int major;
        int minor;
        AbstractHessianInput in;
        AbstractHessianOutput out;
        if (code == 'H') {
            // Hessian 2.0 stream
            major = isToUse.read();
            minor = isToUse.read();
            if (major != 0x02) {
                throw new IOException("Version " + major + "." + minor + " is not understood");
            }
            in = new Hessian2Input(isToUse);
            in.readCall();
        } else if (code == 'C') {
            // Hessian 2.0 call... for some reason not handled in HessianServlet!
            isToUse.reset();
            in = new Hessian2Input(isToUse);
            in.readCall();
        } else if (code == 'c') {
            // Hessian 1.0 call
            major = isToUse.read();
            minor = isToUse.read();
            in = new HessianInput(isToUse);
        } else {
            throw new IOException("Expected 'H'/'C' (Hessian 2.0) or 'c' (Hessian 1.0) in hessian input at " + code);
        }
        in.setSerializerFactory(serializerFactory);
        in.skipOptionalCall();
        while ((in.readHeader()) != null) {
            in.readObject();
        }
        String methodName = in.readMethod();
        int argLength = in.readMethodArgLength();
        Method method = null;
        if (hessianSkeleton != null) {
            try {
                Map map = Reflect.on(hessianSkeleton).get(HessianConstants.DYNAMIC_FIELD_METHOD_MAP);
                method = (Method) map.get(methodName + "__" + argLength);
            } catch (ReflectException e) {
            }
        }
        if ("_hessian_getAttribute".equals(methodName)) {
            String attrName = in.readString();
            in.completeCall();
            return new Object[] { "_hessian_getAttribute", new Object[0] };
        }
        Class<?>[] args = method == null ? null : method.getParameterTypes();
        if (args == null || (argLength != args.length && argLength >= 0)) {
            return EMPTY_ARGS;
        }
        Object[] values = new Object[args.length];
        for (int i = 0; i < args.length; i++) {
            values[i] = in.readObject(args[i]);
        }
        in.completeCall();
        return new Object[] { methodName, args };
    } catch (IOException e) {
        return EMPTY_ARGS;
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Method(java.lang.reflect.Method) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException) BufferedInputStream(java.io.BufferedInputStream) Map(java.util.Map)

Example 30 with ReflectException

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

the class HessianServletServiceInterceptor method beforeTrace.

@Override
public SpanRecord beforeTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    Object target = advice.getTarget();
    if (args == null || args.length == 0) {
        return null;
    }
    if (!(args[0] instanceof HttpServletRequest)) {
        if (Pradar.isClusterTest()) {
            throw new PressureMeasureError("hessian servlet trace err! can't cast to HttpServletRequest");
        }
        return null;
    }
    WrapperRequest request = (WrapperRequest) args[0];
    if (!request.getMethod().equals("POST") && !request.getMethod().equals("post")) {
        return null;
    }
    String method = request.getHeader(HessianConstants.METHOD_HEADER);
    HessianServlet hessianServlet = (HessianServlet) target;
    String objectId = request.getParameter("id");
    if (objectId == null) {
        objectId = request.getParameter("ejbid");
    }
    HessianSkeleton hessianSkeleton = null;
    try {
        hessianSkeleton = Reflect.on(hessianServlet).get(HessianConstants.DYNAMIC_FIELD_OBJECT_SKELETON);
    } catch (ReflectException e) {
        try {
            hessianSkeleton = Reflect.on(hessianServlet).get(HessianConstants.DYNAMIC_FIELD_HOME_SKELETON);
        } catch (ReflectException reflectException) {
        }
    }
    Object[] result = getMethodArgs(request.getInputStream(), hessianServlet.getSerializerFactory(), hessianSkeleton);
    Object[] arguments = (Object[]) result[1];
    if (method == null) {
        method = (String) result[0];
    }
    Class<?> clazz = hessianServlet.getAPIClass();
    SpanRecord spanRecord = new SpanRecord();
    spanRecord.setService(clazz.getName());
    spanRecord.setMethod(method);
    spanRecord.setRequest(arguments);
    return spanRecord;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) WrapperRequest(com.pamirs.attach.plugin.hessian.common.WrapperRequest) HessianSkeleton(com.caucho.hessian.server.HessianSkeleton) HessianServlet(com.caucho.hessian.server.HessianServlet) 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