Search in sources :

Example 6 with WrapperRequest

use of com.pamirs.attach.plugin.hessian.common.WrapperRequest 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

WrapperRequest (com.pamirs.attach.plugin.hessian.common.WrapperRequest)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)5 SpanRecord (com.pamirs.pradar.interceptor.SpanRecord)5 ReflectException (com.shulie.instrument.simulator.api.reflect.ReflectException)3 HessianSkeleton (com.caucho.hessian.server.HessianSkeleton)2 BurlapServlet (com.caucho.burlap.server.BurlapServlet)1 BurlapSkeleton (com.caucho.burlap.server.BurlapSkeleton)1 HessianServlet (com.caucho.hessian.server.HessianServlet)1 HessianServiceExporter (org.springframework.remoting.caucho.HessianServiceExporter)1