mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-22 11:16:25 +10:00
[강운덕] [LUCYSUS-1744] bytecode 조작 api 단일화.
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@880 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
@@ -2,16 +2,19 @@ package com.profiler.interceptor.bci;
|
||||
|
||||
import java.security.ProtectionDomain;
|
||||
|
||||
import com.profiler.interceptor.Interceptor;
|
||||
import javassist.ClassPool;
|
||||
|
||||
public interface ByteCodeInstrumentor {
|
||||
|
||||
// 임시로 만들자.
|
||||
ClassPool getClassPool();
|
||||
// 임시로 만들자.
|
||||
ClassPool getClassPool();
|
||||
|
||||
void checkLibrary(ClassLoader classLoader, String javassistClassName);
|
||||
void checkLibrary(ClassLoader classLoader, String javassistClassName);
|
||||
|
||||
InstrumentClass getClass(String javassistClassName) throws InstrumentException;
|
||||
InstrumentClass getClass(String javassistClassName) throws InstrumentException;
|
||||
|
||||
Class<?> defineClass(ClassLoader classLoader, String defineClass, ProtectionDomain protectedDomain) throws InstrumentException;
|
||||
Class<?> defineClass(ClassLoader classLoader, String defineClass, ProtectionDomain protectedDomain) throws InstrumentException;
|
||||
|
||||
Interceptor newInterceptor(ClassLoader classLoader, ProtectionDomain protectedDomain, String interceptorFQCN) throws InstrumentException;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.security.ProtectionDomain;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.profiler.interceptor.Interceptor;
|
||||
import javassist.CannotCompileException;
|
||||
import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
@@ -121,6 +122,18 @@ public class JavaAssistByteCodeInstrumentor implements ByteCodeInstrumentor {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Interceptor newInterceptor(ClassLoader classLoader, ProtectionDomain protectedDomain, String interceptorFQCN) throws InstrumentException {
|
||||
Class<?> aClass = this.defineClass(classLoader, interceptorFQCN, protectedDomain);
|
||||
try {
|
||||
return (Interceptor) aClass.newInstance();
|
||||
} catch (InstantiationException e) {
|
||||
throw new InstrumentException(aClass + " instance create fail Cause:" + e.getMessage(), e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new InstrumentException(aClass + " instance create fail Cause:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadClassLoaderLibraries(ClassLoader classLoader) {
|
||||
if (classLoader instanceof URLClassLoader) {
|
||||
URLClassLoader urlClassLoader = (URLClassLoader) classLoader;
|
||||
|
||||
@@ -12,34 +12,20 @@ import com.profiler.interceptor.bci.ByteCodeInstrumentor;
|
||||
|
||||
public abstract class AbstractModifier implements Modifier {
|
||||
|
||||
private final Logger logger = Logger.getLogger(AbstractModifier.class.getName());
|
||||
private final Logger logger = Logger.getLogger(AbstractModifier.class.getName());
|
||||
|
||||
protected final ClassPool classPool;
|
||||
protected ByteCodeInstrumentor byteCodeInstrumentor;
|
||||
protected final ClassPool classPool;
|
||||
protected ByteCodeInstrumentor byteCodeInstrumentor;
|
||||
|
||||
public AbstractModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
this.byteCodeInstrumentor = byteCodeInstrumentor;
|
||||
this.classPool = byteCodeInstrumentor.getClassPool();
|
||||
}
|
||||
public AbstractModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
this.byteCodeInstrumentor = byteCodeInstrumentor;
|
||||
this.classPool = byteCodeInstrumentor.getClassPool();
|
||||
}
|
||||
|
||||
public void printClassConvertComplete(String javassistClassName) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info(javassistClassName + " class is converted.");
|
||||
}
|
||||
}
|
||||
public void printClassConvertComplete(String javassistClassName) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info(javassistClassName + " class is converted.");
|
||||
}
|
||||
}
|
||||
|
||||
public void checkLibrary(ClassLoader classLoader, String javassistClassName) {
|
||||
this.byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
|
||||
}
|
||||
|
||||
protected Interceptor newInterceptor(ClassLoader classLoader, ProtectionDomain protectedDomain, String interceptorFQCN) throws InstrumentException {
|
||||
Class<?> aClass = this.byteCodeInstrumentor.defineClass(classLoader, interceptorFQCN, protectedDomain);
|
||||
try {
|
||||
return (Interceptor) aClass.newInstance();
|
||||
} catch (InstantiationException e) {
|
||||
throw new InstrumentException(aClass + " instance create fail Cause:" + e.getMessage(), e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new InstrumentException(aClass + " instance create fail Cause:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,9 +36,9 @@ public class ArcusClientModifier extends AbstractModifier {
|
||||
aClass.addTraceVariable("__asyncTrace", "__setAsyncTrace", "__getAsyncTrace", "java.lang.Object");
|
||||
aClass.addConstructorInterceptor(null, new ConstructInterceptor());
|
||||
|
||||
Interceptor transitionStateInterceptor = newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.arcus.interceptors.BaseOperationTransitionStateInterceptor");
|
||||
Interceptor transitionStateInterceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.arcus.interceptors.BaseOperationTransitionStateInterceptor");
|
||||
aClass.addInterceptor("transitionState", new String[]{"net.spy.memcached.ops.OperationState"}, transitionStateInterceptor);
|
||||
Interceptor cancelInterceptor = newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.arcus.interceptors.BaseOperationCancelInterceptor");
|
||||
Interceptor cancelInterceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.arcus.interceptors.BaseOperationCancelInterceptor");
|
||||
aClass.addInterceptor("cancel", null, cancelInterceptor);
|
||||
|
||||
return aClass.toBytecode();
|
||||
|
||||
@@ -49,7 +49,7 @@ public class HTTPClientModifier extends AbstractModifier {
|
||||
|
||||
byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
|
||||
try {
|
||||
Interceptor interceptor = newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.connector.interceptors.ExecuteMethodInterceptor");
|
||||
Interceptor interceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.connector.interceptors.ExecuteMethodInterceptor");
|
||||
InstrumentClass aClass = byteCodeInstrumentor.getClass(javassistClassName);
|
||||
aClass.addInterceptor("execute", new String[]{"org.apache.http.HttpHost", "org.apache.http.HttpRequest", "org.apache.http.client.ResponseHandler", "org.apache.http.protocol.HttpContext"}, interceptor);
|
||||
return aClass.toBytecode();
|
||||
|
||||
+45
-45
@@ -14,62 +14,62 @@ import java.util.logging.Logger;
|
||||
|
||||
public class CubridPreparedStatementModifier extends AbstractModifier {
|
||||
|
||||
private final Logger logger = Logger.getLogger(CubridPreparedStatementModifier.class.getName());
|
||||
private final Logger logger = Logger.getLogger(CubridPreparedStatementModifier.class.getName());
|
||||
|
||||
public CubridPreparedStatementModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public String getTargetClass() {
|
||||
return "cubrid/jdbc/driver/CUBRIDPreparedStatement";
|
||||
}
|
||||
public CubridPreparedStatementModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)){
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
public String getTargetClass() {
|
||||
return "cubrid/jdbc/driver/CUBRIDPreparedStatement";
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
}
|
||||
checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
this.byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
|
||||
updateExecuteQueryMethod(cc);
|
||||
updateConstructor(cc);
|
||||
updateExecuteQueryMethod(cc);
|
||||
updateConstructor(cc);
|
||||
|
||||
printClassConvertComplete(javassistClassName);
|
||||
printClassConvertComplete(javassistClassName);
|
||||
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
if(logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateConstructor(CtClass cc) throws Exception {
|
||||
CtConstructor[] constructorList = cc.getConstructors();
|
||||
private void updateConstructor(CtClass cc) throws Exception {
|
||||
CtConstructor[] constructorList = cc.getConstructors();
|
||||
|
||||
for (CtConstructor constructor : constructorList) {
|
||||
CtClass params[] = constructor.getParameterTypes();
|
||||
for (CtConstructor constructor : constructorList) {
|
||||
CtClass params[] = constructor.getParameterTypes();
|
||||
|
||||
if (params.length > 2) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{");
|
||||
sb.append("if($2 instanceof cubrid.jdbc.jci.UStatement) { ");
|
||||
sb.append(DatabaseRequestTracer.FQCN + ".putSqlQuery(" + ProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$2.getQuery());");
|
||||
sb.append("}}");
|
||||
if (params.length > 2) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{");
|
||||
sb.append("if($2 instanceof cubrid.jdbc.jci.UStatement) { ");
|
||||
sb.append(DatabaseRequestTracer.FQCN + ".putSqlQuery(" + ProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$2.getQuery());");
|
||||
sb.append("}}");
|
||||
|
||||
constructor.insertBefore(sb.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
constructor.insertBefore(sb.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateExecuteQueryMethod(CtClass cc) throws Exception {
|
||||
CtMethod serviceMethod = cc.getDeclaredMethod("execute", null);
|
||||
serviceMethod.insertAfter("{" + DatabaseRequestTracer.FQCN + ".put(" + ProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + "); }");
|
||||
}
|
||||
private void updateExecuteQueryMethod(CtClass cc) throws Exception {
|
||||
CtMethod serviceMethod = cc.getDeclaredMethod("execute", null);
|
||||
serviceMethod.insertAfter("{" + DatabaseRequestTracer.FQCN + ".put(" + ProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + "); }");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,49 +13,49 @@ import java.util.logging.Logger;
|
||||
|
||||
public class CubridResultSetModifier extends AbstractModifier {
|
||||
|
||||
private final Logger logger = Logger.getLogger(CubridResultSetModifier.class.getName());
|
||||
private final Logger logger = Logger.getLogger(CubridResultSetModifier.class.getName());
|
||||
|
||||
public CubridResultSetModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public String getTargetClass() {
|
||||
return "cubrid/jdbc/driver/CUBRIDResultSet";
|
||||
}
|
||||
public CubridResultSetModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
public String getTargetClass() {
|
||||
return "cubrid/jdbc/driver/CUBRIDResultSet";
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
}
|
||||
checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
this.byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
|
||||
updateNextMethod(cc);
|
||||
updateCloseMethod(cc);
|
||||
updateNextMethod(cc);
|
||||
updateCloseMethod(cc);
|
||||
|
||||
printClassConvertComplete(javassistClassName);
|
||||
printClassConvertComplete(javassistClassName);
|
||||
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
if(logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateNextMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("next", null);
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".updateFetchCount(); }");
|
||||
}
|
||||
private void updateNextMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("next", null);
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".updateFetchCount(); }");
|
||||
}
|
||||
|
||||
private void updateCloseMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("close", null);
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".addResultSetData(); } ");
|
||||
}
|
||||
private void updateCloseMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("close", null);
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".addResultSetData(); } ");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,25 +15,25 @@ import java.util.logging.Logger;
|
||||
|
||||
public class CubridStatementModifier extends AbstractModifier {
|
||||
|
||||
private final Logger logger = Logger.getLogger(CubridStatementModifier.class.getName());
|
||||
private final Logger logger = Logger.getLogger(CubridStatementModifier.class.getName());
|
||||
|
||||
public CubridStatementModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public String getTargetClass() {
|
||||
return "cubrid/jdbc/driver/CUBRIDStatement";
|
||||
}
|
||||
public CubridStatementModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
public String getTargetClass() {
|
||||
return "cubrid/jdbc/driver/CUBRIDStatement";
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
}
|
||||
checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
this.byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
|
||||
StaticAroundInterceptor interceptor = new StaticAroundInterceptor() {
|
||||
@Override
|
||||
@@ -43,41 +43,41 @@ public class CubridStatementModifier extends AbstractModifier {
|
||||
|
||||
@Override
|
||||
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
DatabaseRequestTracer.put(ProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY);;
|
||||
DatabaseRequestTracer.put(ProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY);
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
// TODO 추가로 고쳐야 될듯.
|
||||
InstrumentClass aClass = this.byteCodeInstrumentor.getClass(javassistClassName);
|
||||
aClass.addInterceptor("executeQuery", new String[] {"java.lang.String"}, interceptor);
|
||||
aClass.addInterceptor("executeQuery", new String[]{"java.lang.String"}, interceptor);
|
||||
printClassConvertComplete(javassistClassName);
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
|
||||
updateExecuteQueryMethod(cc);
|
||||
updateExecuteQueryMethod(cc);
|
||||
|
||||
|
||||
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
if(logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateExecuteQueryMethod(CtClass cc) throws Exception {
|
||||
CtClass[] params = new CtClass[1];
|
||||
params[0] = classPool.getCtClass("java.lang.String");
|
||||
CtMethod method = cc.getDeclaredMethod("executeQuery", params);
|
||||
private void updateExecuteQueryMethod(CtClass cc) throws Exception {
|
||||
CtClass[] params = new CtClass[1];
|
||||
params[0] = classPool.getCtClass("java.lang.String");
|
||||
CtMethod method = cc.getDeclaredMethod("executeQuery", params);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{");
|
||||
sb.append(DatabaseRequestTracer.FQCN + ".putSqlQuery(" + ProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$1);");
|
||||
sb.append(DatabaseRequestTracer.FQCN + ".put(" + ProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + ");");
|
||||
sb.append("}");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{");
|
||||
sb.append(DatabaseRequestTracer.FQCN + ".putSqlQuery(" + ProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$1);");
|
||||
sb.append(DatabaseRequestTracer.FQCN + ".put(" + ProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + ");");
|
||||
sb.append("}");
|
||||
|
||||
method.insertAfter(sb.toString());
|
||||
}
|
||||
method.insertAfter(sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,48 +13,48 @@ import java.util.logging.Logger;
|
||||
|
||||
public class CubridUStatementModifier extends AbstractModifier {
|
||||
|
||||
private final Logger logger = Logger.getLogger(CubridUStatementModifier.class.getName());
|
||||
private final Logger logger = Logger.getLogger(CubridUStatementModifier.class.getName());
|
||||
|
||||
public CubridUStatementModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public String getTargetClass() {
|
||||
return "cubrid/jdbc/jci/UStatement";
|
||||
}
|
||||
public CubridUStatementModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)){
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
public String getTargetClass() {
|
||||
return "cubrid/jdbc/jci/UStatement";
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
}
|
||||
checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
this.byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
|
||||
updateBindValueMethod(cc);
|
||||
updateBindValueMethod(cc);
|
||||
|
||||
printClassConvertComplete(javassistClassName);
|
||||
printClassConvertComplete(javassistClassName);
|
||||
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateBindValueMethod(CtClass cc) throws Exception {
|
||||
CtClass[] params1 = new CtClass[3];
|
||||
params1[0] = classPool.getCtClass("int");
|
||||
params1[1] = classPool.getCtClass("byte");
|
||||
params1[2] = classPool.getCtClass("java.lang.Object");
|
||||
CtMethod method = cc.getDeclaredMethod("bindValue", params1);
|
||||
private void updateBindValueMethod(CtClass cc) throws Exception {
|
||||
CtClass[] params1 = new CtClass[3];
|
||||
params1[0] = classPool.getCtClass("int");
|
||||
params1[1] = classPool.getCtClass("byte");
|
||||
params1[2] = classPool.getCtClass("java.lang.Object");
|
||||
CtMethod method = cc.getDeclaredMethod("bindValue", params1);
|
||||
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".putSqlParam($1,$3); }");
|
||||
}
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".putSqlParam($1,$3); }");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,43 +13,43 @@ import java.util.logging.Logger;
|
||||
|
||||
public class DBCPBasicDataSourceModifier extends AbstractModifier {
|
||||
|
||||
private final Logger logger = Logger.getLogger(DBCPBasicDataSourceModifier.class.getName());
|
||||
private final Logger logger = Logger.getLogger(DBCPBasicDataSourceModifier.class.getName());
|
||||
|
||||
public DBCPBasicDataSourceModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
public DBCPBasicDataSourceModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public String getTargetClass() {
|
||||
return "org/apache/commons/dbcp/BasicDataSource";
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)){
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
public String getTargetClass() {
|
||||
return "org/apache/commons/dbcp/BasicDataSource";
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
}
|
||||
checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
this.byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
|
||||
updateGetConnectionMethod(cc);
|
||||
updateGetConnectionMethod(cc);
|
||||
|
||||
printClassConvertComplete(javassistClassName);
|
||||
printClassConvertComplete(javassistClassName);
|
||||
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateGetConnectionMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("getConnection", null);
|
||||
method.insertAfter("{" + DatabaseRequestTracer.FQCN + ".putConnection(" + ProfilerConstant.REQ_DATA_TYPE_DB_GET_CONNECTION + ",$0.getUrl()); }");
|
||||
}
|
||||
private void updateGetConnectionMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("getConnection", null);
|
||||
method.insertAfter("{" + DatabaseRequestTracer.FQCN + ".putConnection(" + ProfilerConstant.REQ_DATA_TYPE_DB_GET_CONNECTION + ",$0.getUrl()); }");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,43 +13,43 @@ import java.util.logging.Logger;
|
||||
|
||||
public class DBCPPoolModifier extends AbstractModifier {
|
||||
|
||||
private final Logger logger = Logger.getLogger(DBCPPoolModifier.class.getName());
|
||||
private final Logger logger = Logger.getLogger(DBCPPoolModifier.class.getName());
|
||||
|
||||
public DBCPPoolModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public String getTargetClass() {
|
||||
return "org/apache/commons/dbcp/PoolingDataSource$PoolGuardConnectionWrapper";
|
||||
}
|
||||
public DBCPPoolModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)){
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
public String getTargetClass() {
|
||||
return "org/apache/commons/dbcp/PoolingDataSource$PoolGuardConnectionWrapper";
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
}
|
||||
checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
this.byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
|
||||
updateCloseMethod(cc);
|
||||
updateCloseMethod(cc);
|
||||
|
||||
printClassConvertComplete(javassistClassName);
|
||||
printClassConvertComplete(javassistClassName);
|
||||
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateCloseMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("close", null);
|
||||
method.insertAfter("{" + DatabaseRequestTracer.FQCN + ".put(" + ProfilerConstant.REQ_DATA_TYPE_DB_CLOSE_CONNECTION + "); }");
|
||||
}
|
||||
private void updateCloseMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("close", null);
|
||||
method.insertAfter("{" + DatabaseRequestTracer.FQCN + ".put(" + ProfilerConstant.REQ_DATA_TYPE_DB_CLOSE_CONNECTION + "); }");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,53 +13,53 @@ import java.util.logging.Logger;
|
||||
|
||||
public class MSSQLConnectionModifier extends AbstractModifier {
|
||||
|
||||
private final Logger logger = Logger.getLogger(MSSQLConnectionModifier.class.getName());
|
||||
private final Logger logger = Logger.getLogger(MSSQLConnectionModifier.class.getName());
|
||||
|
||||
public MSSQLConnectionModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public String getTargetClass() {
|
||||
return "net/sourceforge/jtds/jdbc/ConnectionJDBC2";
|
||||
}
|
||||
public MSSQLConnectionModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)){
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
public String getTargetClass() {
|
||||
return "net/sourceforge/jtds/jdbc/ConnectionJDBC2";
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
}
|
||||
checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethods(javassistClassName, classFileBuffer);
|
||||
}
|
||||
this.byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethods(javassistClassName, classFileBuffer);
|
||||
}
|
||||
|
||||
private byte[] changeMethods(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
private byte[] changeMethods(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
|
||||
updateCreateStatementMethod(cc);
|
||||
updateCloseMethod(cc);
|
||||
updateCreateStatementMethod(cc);
|
||||
updateCloseMethod(cc);
|
||||
|
||||
printClassConvertComplete(javassistClassName);
|
||||
printClassConvertComplete(javassistClassName);
|
||||
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateCreateStatementMethod(CtClass cc) throws Exception {
|
||||
CtClass[] params = new CtClass[2];
|
||||
params[0] = classPool.getCtClass("int");
|
||||
params[1] = classPool.getCtClass("int");
|
||||
CtMethod method = cc.getDeclaredMethod("createStatement", params);
|
||||
private void updateCreateStatementMethod(CtClass cc) throws Exception {
|
||||
CtClass[] params = new CtClass[2];
|
||||
params[0] = classPool.getCtClass("int");
|
||||
params[1] = classPool.getCtClass("int");
|
||||
CtMethod method = cc.getDeclaredMethod("createStatement", params);
|
||||
|
||||
method.insertAfter("{" + DatabaseRequestTracer.FQCN + ".put(" + ProfilerConstant.REQ_DATA_TYPE_DB_CREATE_STATEMENT + "); }");
|
||||
}
|
||||
method.insertAfter("{" + DatabaseRequestTracer.FQCN + ".put(" + ProfilerConstant.REQ_DATA_TYPE_DB_CREATE_STATEMENT + "); }");
|
||||
}
|
||||
|
||||
private void updateCloseMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("close", null);
|
||||
method.insertAfter("{" + DatabaseRequestTracer.FQCN + ".put(" + ProfilerConstant.REQ_DATA_TYPE_DB_CLOSE_CONNECTION + "); }");
|
||||
}
|
||||
private void updateCloseMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("close", null);
|
||||
method.insertAfter("{" + DatabaseRequestTracer.FQCN + ".put(" + ProfilerConstant.REQ_DATA_TYPE_DB_CLOSE_CONNECTION + "); }");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,66 +14,66 @@ import java.util.logging.Logger;
|
||||
|
||||
public class MSSQLPreparedStatementModifier extends AbstractModifier {
|
||||
|
||||
private final Logger logger = Logger.getLogger(MSSQLPreparedStatementModifier.class.getName());
|
||||
private final Logger logger = Logger.getLogger(MSSQLPreparedStatementModifier.class.getName());
|
||||
|
||||
public MSSQLPreparedStatementModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
public MSSQLPreparedStatementModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public String getTargetClass() {
|
||||
return "net/sourceforge/jtds/jdbc/JtdsPreparedStatement";
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)){
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
public String getTargetClass() {
|
||||
return "net/sourceforge/jtds/jdbc/JtdsPreparedStatement";
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
}
|
||||
checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
this.byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
|
||||
updateSetParameterMethod(cc);
|
||||
updateExecuteQueryMethod(cc);
|
||||
updateConstructor(cc);
|
||||
updateSetParameterMethod(cc);
|
||||
updateExecuteQueryMethod(cc);
|
||||
updateConstructor(cc);
|
||||
|
||||
printClassConvertComplete(javassistClassName);
|
||||
printClassConvertComplete(javassistClassName);
|
||||
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateSetParameterMethod(CtClass cc) throws Exception {
|
||||
CtClass[] params1 = new CtClass[5];
|
||||
params1[0] = classPool.getCtClass("int");
|
||||
params1[1] = classPool.getCtClass("java.lang.Object");
|
||||
params1[2] = classPool.getCtClass("int");
|
||||
params1[3] = classPool.getCtClass("int");
|
||||
params1[4] = classPool.getCtClass("int");
|
||||
CtMethod method = cc.getDeclaredMethod("setParameter", params1);
|
||||
private void updateSetParameterMethod(CtClass cc) throws Exception {
|
||||
CtClass[] params1 = new CtClass[5];
|
||||
params1[0] = classPool.getCtClass("int");
|
||||
params1[1] = classPool.getCtClass("java.lang.Object");
|
||||
params1[2] = classPool.getCtClass("int");
|
||||
params1[3] = classPool.getCtClass("int");
|
||||
params1[4] = classPool.getCtClass("int");
|
||||
CtMethod method = cc.getDeclaredMethod("setParameter", params1);
|
||||
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".putSqlParam($1,$2);} ");
|
||||
}
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".putSqlParam($1,$2);} ");
|
||||
}
|
||||
|
||||
private void updateConstructor(CtClass cc) throws Exception {
|
||||
CtConstructor[] constructorList = cc.getConstructors();
|
||||
|
||||
if (constructorList.length == 1) {
|
||||
CtConstructor constructor = constructorList[0];
|
||||
constructor.insertAfter("{" + DatabaseRequestTracer.FQCN + ".putSqlQuery(" + ProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$2); }");
|
||||
}
|
||||
}
|
||||
private void updateConstructor(CtClass cc) throws Exception {
|
||||
CtConstructor[] constructorList = cc.getConstructors();
|
||||
|
||||
private void updateExecuteQueryMethod(CtClass cc) throws Exception {
|
||||
CtMethod serviceMethod = cc.getDeclaredMethod("execute", null);
|
||||
serviceMethod.insertAfter("{" + DatabaseRequestTracer.FQCN + ".put(" + ProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + "); }");
|
||||
}
|
||||
if (constructorList.length == 1) {
|
||||
CtConstructor constructor = constructorList[0];
|
||||
constructor.insertAfter("{" + DatabaseRequestTracer.FQCN + ".putSqlQuery(" + ProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$2); }");
|
||||
}
|
||||
}
|
||||
|
||||
private void updateExecuteQueryMethod(CtClass cc) throws Exception {
|
||||
CtMethod serviceMethod = cc.getDeclaredMethod("execute", null);
|
||||
serviceMethod.insertAfter("{" + DatabaseRequestTracer.FQCN + ".put(" + ProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + "); }");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,49 +14,49 @@ import java.util.logging.Logger;
|
||||
|
||||
public class MSSQLResultSetModifier extends AbstractModifier {
|
||||
|
||||
private final Logger logger = Logger.getLogger(MSSQLResultSetModifier.class.getName());
|
||||
private final Logger logger = Logger.getLogger(MSSQLResultSetModifier.class.getName());
|
||||
|
||||
public MSSQLResultSetModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public String getTargetClass() {
|
||||
return "net/sourceforge/jtds/jdbc/JtdsResultSet";
|
||||
}
|
||||
public MSSQLResultSetModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)){
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
public String getTargetClass() {
|
||||
return "net/sourceforge/jtds/jdbc/JtdsResultSet";
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
}
|
||||
checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
this.byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
|
||||
updateNextMethod(cc);
|
||||
updateCloseMethod(cc);
|
||||
updateNextMethod(cc);
|
||||
updateCloseMethod(cc);
|
||||
|
||||
printClassConvertComplete(javassistClassName);
|
||||
printClassConvertComplete(javassistClassName);
|
||||
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateNextMethod(CtClass cc) throws Exception {
|
||||
CtMethod serviceMethod1 = cc.getDeclaredMethod("next", null);
|
||||
serviceMethod1.insertBefore("{" + DatabaseRequestTracer.FQCN + ".updateFetchCount(); }");
|
||||
}
|
||||
private void updateNextMethod(CtClass cc) throws Exception {
|
||||
CtMethod serviceMethod1 = cc.getDeclaredMethod("next", null);
|
||||
serviceMethod1.insertBefore("{" + DatabaseRequestTracer.FQCN + ".updateFetchCount(); }");
|
||||
}
|
||||
|
||||
private void updateCloseMethod(CtClass cc) throws Exception {
|
||||
CtMethod serviceMethod1 = cc.getDeclaredMethod("close", null);
|
||||
serviceMethod1.insertBefore("{" + DatabaseRequestTracer.FQCN + ".addResultSetData(); }");
|
||||
}
|
||||
private void updateCloseMethod(CtClass cc) throws Exception {
|
||||
CtMethod serviceMethod1 = cc.getDeclaredMethod("close", null);
|
||||
serviceMethod1.insertBefore("{" + DatabaseRequestTracer.FQCN + ".addResultSetData(); }");
|
||||
}
|
||||
}
|
||||
@@ -12,52 +12,52 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class MSSQLStatementModifier extends AbstractModifier {
|
||||
private static final Logger logger = Logger.getLogger(MSSQLStatementModifier.class.getName());
|
||||
private static final Logger logger = Logger.getLogger(MSSQLStatementModifier.class.getName());
|
||||
|
||||
public MSSQLStatementModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
public MSSQLStatementModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public String getTargetClass() {
|
||||
return "net/sourceforge/jtds/jdbc/JtdsStatement";
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)){
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
public String getTargetClass() {
|
||||
return "net/sourceforge/jtds/jdbc/JtdsStatement";
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
}
|
||||
checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
this.byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
|
||||
updateExecuteQueryMethod(cc);
|
||||
updateExecuteQueryMethod(cc);
|
||||
|
||||
printClassConvertComplete(javassistClassName);
|
||||
printClassConvertComplete(javassistClassName);
|
||||
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateExecuteQueryMethod(CtClass cc) throws Exception {
|
||||
CtClass[] params = new CtClass[1];
|
||||
params[0] = classPool.getCtClass("java.lang.String");
|
||||
CtMethod serviceMethod = cc.getDeclaredMethod("executeQuery", params);
|
||||
private void updateExecuteQueryMethod(CtClass cc) throws Exception {
|
||||
CtClass[] params = new CtClass[1];
|
||||
params[0] = classPool.getCtClass("java.lang.String");
|
||||
CtMethod serviceMethod = cc.getDeclaredMethod("executeQuery", params);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{");
|
||||
sb.append(DatabaseRequestTracer.FQCN + ".putSqlQuery(" + ProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$1);");
|
||||
sb.append(DatabaseRequestTracer.FQCN + ".put(" + ProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + ");");
|
||||
sb.append("}");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{");
|
||||
sb.append(DatabaseRequestTracer.FQCN + ".putSqlQuery(" + ProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$1);");
|
||||
sb.append(DatabaseRequestTracer.FQCN + ".put(" + ProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + ");");
|
||||
sb.append("}");
|
||||
|
||||
serviceMethod.insertAfter(sb.toString());
|
||||
}
|
||||
serviceMethod.insertAfter(sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class MySQLConnectionImplModifier extends AbstractModifier {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
}
|
||||
checkLibrary(classLoader, javassistClassName);
|
||||
this.byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
|
||||
try {
|
||||
InstrumentClass mysqlConnection = byteCodeInstrumentor.getClass(javassistClassName);
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class MySQLNonRegisteringDriverModifier extends AbstractModifier {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
}
|
||||
checkLibrary(classLoader, javassistClassName);
|
||||
this.byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
|
||||
try {
|
||||
InstrumentClass mysqlConnection = byteCodeInstrumentor.getClass(javassistClassName);
|
||||
|
||||
|
||||
+11
-11
@@ -15,25 +15,25 @@ import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class MySQLPreparedStatementJDBC4Modifier extends AbstractModifier {
|
||||
public class MySQLPreparedStatementJDBC4Modifier extends AbstractModifier {
|
||||
|
||||
private final Logger logger = Logger.getLogger(MySQLPreparedStatementJDBC4Modifier.class.getName());
|
||||
private final String[] includes = new String[] { "setRowId", "setNClob", "setSQLXML" };
|
||||
private final Logger logger = Logger.getLogger(MySQLPreparedStatementJDBC4Modifier.class.getName());
|
||||
private final String[] includes = new String[]{"setRowId", "setNClob", "setSQLXML"};
|
||||
|
||||
public MySQLPreparedStatementJDBC4Modifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
public MySQLPreparedStatementJDBC4Modifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public String getTargetClass() {
|
||||
return "com/mysql/jdbc/JDBC4PreparedStatement";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] modify(ClassLoader classLoader, String className, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("Modifing. " + className);
|
||||
}
|
||||
checkLibrary(classLoader, className);
|
||||
logger.info("Modifing. " + className);
|
||||
}
|
||||
this.byteCodeInstrumentor.checkLibrary(classLoader, className);
|
||||
try {
|
||||
InstrumentClass preparedStatement = byteCodeInstrumentor.getClass(className);
|
||||
|
||||
@@ -42,7 +42,7 @@ public class MySQLPreparedStatementJDBC4Modifier extends AbstractModifier {
|
||||
return preparedStatement.toBytecode();
|
||||
} catch (InstrumentException e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, this.getClass().getSimpleName() + " modify fail. Cause:" + e.getMessage(), e);
|
||||
logger.log(Level.WARNING, this.getClass().getSimpleName() + " modify fail. Cause:" + e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class MySQLPreparedStatementModifier extends AbstractModifier {
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
}
|
||||
|
||||
checkLibrary(classLoader, javassistClassName);
|
||||
this.byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
|
||||
try {
|
||||
InstrumentClass preparedStatement = byteCodeInstrumentor.getClass(javassistClassName);
|
||||
|
||||
|
||||
@@ -10,52 +10,53 @@ import com.profiler.trace.DatabaseRequestTracer;
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
// TODO 추가 개발해야 될듯.
|
||||
public class MySQLResultSetModifier extends AbstractModifier {
|
||||
|
||||
private final Logger logger = Logger.getLogger(MySQLResultSetModifier.class.getName());
|
||||
private final Logger logger = Logger.getLogger(MySQLResultSetModifier.class.getName());
|
||||
|
||||
public MySQLResultSetModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public String getTargetClass() {
|
||||
return "com/mysql/jdbc/ResultSetImpl";
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)){
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
|
||||
public String getTargetClass() {
|
||||
return "com/mysql/jdbc/ResultSetImpl";
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
}
|
||||
checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
this.byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
|
||||
updateNextMethod(cc);
|
||||
updateCloseMethod(cc);
|
||||
updateNextMethod(cc);
|
||||
updateCloseMethod(cc);
|
||||
|
||||
printClassConvertComplete(javassistClassName);
|
||||
printClassConvertComplete(javassistClassName);
|
||||
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateNextMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("next", null);
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".updateFetchCount(); }");
|
||||
}
|
||||
private void updateNextMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("next", null);
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".updateFetchCount(); }");
|
||||
}
|
||||
|
||||
private void updateCloseMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("close", null);
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".addResultSetData(); }");
|
||||
}
|
||||
private void updateCloseMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("close", null);
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".addResultSetData(); }");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class MySQLStatementModifier extends AbstractModifier {
|
||||
statementClass.addInterceptor("executeQuery", new String[]{"java.lang.String"}, interceptor);
|
||||
|
||||
// TODO 이거 고쳐야 됨.
|
||||
Interceptor executeUpdate = newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.db.interceptor.StatementExecuteUpdateInterceptor");
|
||||
Interceptor executeUpdate = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.db.interceptor.StatementExecuteUpdateInterceptor");
|
||||
statementClass.addInterceptor("executeUpdate", new String[]{"java.lang.String", "boolean", "boolean"}, executeUpdate);
|
||||
|
||||
statementClass.addTraceVariable("__url", "__setUrl", "__getUrl", "java.lang.Object");
|
||||
|
||||
+58
-58
@@ -14,75 +14,75 @@ import java.util.logging.Logger;
|
||||
|
||||
public class OraclePreparedStatementModifier extends AbstractModifier {
|
||||
|
||||
private final Logger logger = Logger.getLogger(OraclePreparedStatementModifier.class.getName());
|
||||
private final Logger logger = Logger.getLogger(OraclePreparedStatementModifier.class.getName());
|
||||
|
||||
public OraclePreparedStatementModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public String getTargetClass() {
|
||||
return "oracle/jdbc/driver/OraclePreparedStatement";
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)){
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
public OraclePreparedStatementModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public String getTargetClass() {
|
||||
return "oracle/jdbc/driver/OraclePreparedStatement";
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
}
|
||||
checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
this.byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
|
||||
updateSetInternalMethod(cc);
|
||||
updateExecuteMethod(cc);
|
||||
updateConstructor(cc);
|
||||
updateSetInternalMethod(cc);
|
||||
updateExecuteMethod(cc);
|
||||
updateConstructor(cc);
|
||||
|
||||
printClassConvertComplete(javassistClassName);
|
||||
printClassConvertComplete(javassistClassName);
|
||||
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateSetInternalMethod(CtClass cc) throws Exception {
|
||||
CtClass[] params1 = new CtClass[2];
|
||||
params1[0] = classPool.getCtClass("int");
|
||||
params1[1] = classPool.getCtClass("java.lang.String");
|
||||
CtMethod serviceMethod1 = cc.getDeclaredMethod("setStringInternal", params1);
|
||||
private void updateSetInternalMethod(CtClass cc) throws Exception {
|
||||
CtClass[] params1 = new CtClass[2];
|
||||
params1[0] = classPool.getCtClass("int");
|
||||
params1[1] = classPool.getCtClass("java.lang.String");
|
||||
CtMethod serviceMethod1 = cc.getDeclaredMethod("setStringInternal", params1);
|
||||
|
||||
serviceMethod1.insertBefore("{" + DatabaseRequestTracer.FQCN + ".putSqlParam($1,$2); }");
|
||||
serviceMethod1.insertBefore("{" + DatabaseRequestTracer.FQCN + ".putSqlParam($1,$2); }");
|
||||
|
||||
// CtClass[] params2 = new CtClass[2];
|
||||
// params2[0] = classPool.getCtClass("int");
|
||||
// params2[1] = classPool.getCtClass("byte[]");
|
||||
// CtMethod serviceMethod2 = cc.getDeclaredMethod("setInternal",
|
||||
// params2);
|
||||
//
|
||||
// serviceMethod2.insertBefore("{" +
|
||||
// RequestDataTracer.FQCN +
|
||||
// ".putSqlParam($1,$2); {");
|
||||
}
|
||||
// CtClass[] params2 = new CtClass[2];
|
||||
// params2[0] = classPool.getCtClass("int");
|
||||
// params2[1] = classPool.getCtClass("byte[]");
|
||||
// CtMethod serviceMethod2 = cc.getDeclaredMethod("setInternal",
|
||||
// params2);
|
||||
//
|
||||
// serviceMethod2.insertBefore("{" +
|
||||
// RequestDataTracer.FQCN +
|
||||
// ".putSqlParam($1,$2); {");
|
||||
}
|
||||
|
||||
private void updateConstructor(CtClass cc) throws Exception {
|
||||
CtConstructor[] constructorList = cc.getConstructors();
|
||||
private void updateConstructor(CtClass cc) throws Exception {
|
||||
CtConstructor[] constructorList = cc.getConstructors();
|
||||
|
||||
for (CtConstructor constructor : constructorList) {
|
||||
CtClass params[] = constructor.getParameterTypes();
|
||||
if (params.length == 6) {
|
||||
constructor.insertBefore("{" + DatabaseRequestTracer.FQCN + ".putSqlQuery(" + ProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$2); }");
|
||||
}
|
||||
}
|
||||
}
|
||||
for (CtConstructor constructor : constructorList) {
|
||||
CtClass params[] = constructor.getParameterTypes();
|
||||
if (params.length == 6) {
|
||||
constructor.insertBefore("{" + DatabaseRequestTracer.FQCN + ".putSqlQuery(" + ProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$2); }");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateExecuteMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("execute", null);
|
||||
method.insertAfter("{" + DatabaseRequestTracer.FQCN + ".put(" + ProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + "); }");
|
||||
}
|
||||
private void updateExecuteMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("execute", null);
|
||||
method.insertAfter("{" + DatabaseRequestTracer.FQCN + ".put(" + ProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + "); }");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,49 +13,49 @@ import java.util.logging.Logger;
|
||||
|
||||
public class OracleResultSetModifier extends AbstractModifier {
|
||||
|
||||
private final Logger logger = Logger.getLogger(OracleResultSetModifier.class.getName());
|
||||
private final Logger logger = Logger.getLogger(OracleResultSetModifier.class.getName());
|
||||
|
||||
public OracleResultSetModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
public OracleResultSetModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public String getTargetClass() {
|
||||
return "oracle/jdbc/driver/OracleResultSetImpl";
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)){
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
public String getTargetClass() {
|
||||
return "oracle/jdbc/driver/OracleResultSetImpl";
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
}
|
||||
checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
this.byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
|
||||
updateNextMethod(cc);
|
||||
updateCloseMethod(cc);
|
||||
updateNextMethod(cc);
|
||||
updateCloseMethod(cc);
|
||||
|
||||
printClassConvertComplete(javassistClassName);
|
||||
printClassConvertComplete(javassistClassName);
|
||||
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateNextMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("next", null);
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".updateFetchCount(); }");
|
||||
}
|
||||
private void updateNextMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("next", null);
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".updateFetchCount(); }");
|
||||
}
|
||||
|
||||
private void updateCloseMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("close", null);
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".addResultSetData(); }");
|
||||
}
|
||||
private void updateCloseMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("close", null);
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".addResultSetData(); }");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,53 +12,53 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class OracleStatementModifier extends AbstractModifier {
|
||||
private final Logger logger = Logger.getLogger(OracleStatementModifier.class.getName());
|
||||
private final Logger logger = Logger.getLogger(OracleStatementModifier.class.getName());
|
||||
|
||||
public OracleStatementModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public String getTargetClass() {
|
||||
return "oracle/jdbc/driver/OracleStatement";
|
||||
}
|
||||
public OracleStatementModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)){
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
public String getTargetClass() {
|
||||
return "oracle/jdbc/driver/OracleStatement";
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
}
|
||||
checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
this.byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
|
||||
return changeMethod(javassistClassName, classFileBuffer);
|
||||
}
|
||||
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
private byte[] changeMethod(String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
|
||||
updateExecuteQueryMethod(cc);
|
||||
updateExecuteQueryMethod(cc);
|
||||
|
||||
printClassConvertComplete(javassistClassName);
|
||||
printClassConvertComplete(javassistClassName);
|
||||
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateExecuteQueryMethod(CtClass cc) throws Exception {
|
||||
CtClass[] params = new CtClass[1];
|
||||
params[0] = classPool.getCtClass("java.lang.String");
|
||||
// CtMethod serviceMethod=cc.getDeclaredMethod("executeQuery", params);
|
||||
CtMethod serviceMethod = cc.getDeclaredMethod("execute", params);
|
||||
private void updateExecuteQueryMethod(CtClass cc) throws Exception {
|
||||
CtClass[] params = new CtClass[1];
|
||||
params[0] = classPool.getCtClass("java.lang.String");
|
||||
// CtMethod serviceMethod=cc.getDeclaredMethod("executeQuery", params);
|
||||
CtMethod serviceMethod = cc.getDeclaredMethod("execute", params);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{");
|
||||
sb.append(DatabaseRequestTracer.FQCN + ".putSqlQuery(" + ProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$1);");
|
||||
sb.append(DatabaseRequestTracer.FQCN + ".put(" + ProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + ");");
|
||||
sb.append("}");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{");
|
||||
sb.append(DatabaseRequestTracer.FQCN + ".putSqlQuery(" + ProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$1);");
|
||||
sb.append(DatabaseRequestTracer.FQCN + ".put(" + ProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + ");");
|
||||
sb.append("}");
|
||||
|
||||
serviceMethod.insertAfter(sb.toString());
|
||||
}
|
||||
serviceMethod.insertAfter(sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class StandardHostValveInvokeModifier extends AbstractModifier {
|
||||
byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
|
||||
|
||||
try {
|
||||
Interceptor interceptor = newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.tomcat.interceptors.StandardHostValveInvokeInterceptor");
|
||||
Interceptor interceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.tomcat.interceptors.StandardHostValveInvokeInterceptor");
|
||||
InstrumentClass standardHostValve = byteCodeInstrumentor.getClass(javassistClassName);
|
||||
standardHostValve.addInterceptor("invoke", new String[]{"org.apache.catalina.connector.Request", "org.apache.catalina.connector.Response"}, interceptor);
|
||||
return standardHostValve.toBytecode();
|
||||
|
||||
Reference in New Issue
Block a user