@Override
 public byte[] transform(
     ClassLoader classLoader,
     String className,
     Class<?> classBeingRedefined,
     ProtectionDomain protectionDomain,
     byte[] classfileBuffer)
     throws IllegalClassFormatException {
   try {
     InstrumentClass target = context.getInstrumentClass(classLoader, className, classfileBuffer);
     recipe.edit(classLoader, target);
     return target.toBytecode();
   } catch (PinpointException e) {
     throw e;
   } catch (Throwable e) {
     String msg = "Fail to invoke plugin class recipe: " + toString();
     throw new PinpointException(msg, e);
   }
 }
Ejemplo n.º 2
0
  /* (non-Javadoc)
   * @see com.navercorp.pinpoint.bootstrap.plugin.transformer.PinpointClassFileTransformer#transform(com.navercorp.pinpoint.bootstrap.plugin.PinpointInstrument, java.lang.ClassLoader, java.lang.String, java.lang.Class, java.security.ProtectionDomain, byte[])
   */
  @Override
  public byte[] transform(
      Instrumentor instrumentContext,
      ClassLoader loader,
      String className,
      Class<?> classBeingRedefined,
      ProtectionDomain protectionDomain,
      byte[] classfileBuffer)
      throws InstrumentException {
    if (logger.isInfoEnabled()) {
      logger.info("Modify {}", className);
    }

    try {
      InstrumentClass target =
          instrumentContext.getInstrumentClass(loader, className, classfileBuffer);

      if (!target.isInterceptable()) {
        return null;
      }

      List<InstrumentMethod> methodList = target.getDeclaredMethods(METHOD_FILTER);
      for (InstrumentMethod method : methodList) {
        if (logger.isTraceEnabled()) {
          logger.trace(
              "### c={}, m={}, params={}",
              new Object[] {
                className, method.getName(), Arrays.toString(method.getParameterTypes())
              });
        }

        method.addInterceptor(
            BasicMethodInterceptor.class.getName(), va(SpringBeansConstants.SERVICE_TYPE));
      }

      return target.toBytecode();
    } catch (Exception e) {
      logger.warn("modify fail. Cause:{}", e.getMessage(), e);
      return null;
    }
  }
  @Override
  public byte[] doInTransform(
      Instrumentor instrumentor,
      ClassLoader classLoader,
      String className,
      Class<?> classBeingRedefined,
      ProtectionDomain protectionDomain,
      byte[] classfileBuffer)
      throws InstrumentException {
    InstrumentClass target =
        instrumentor.getInstrumentClass(classLoader, className, classfileBuffer);

    target.addGetter(
        "com.navercorp.pinpoint.plugin.sample._13_RPC_Client.ServerAddressGetter", "serverAddress");
    target.addGetter(
        "com.navercorp.pinpoint.plugin.sample._13_RPC_Client.ServerPortGetter", "serverPort");
    target
        .getDeclaredMethod(
            "sendRequest", "com.navercorp.plugin.sample.target.TargetClass13_Request")
        .addInterceptor(
            "com.navercorp.pinpoint.plugin.sample._13_RPC_Client.SendRequestInterceptor");

    return target.toBytecode();
  }