Skip to content

Commit

Permalink
Merge pull request #55 from noob-noob/yangminglang
Browse files Browse the repository at this point in the history
springboot's hook modify&&defect  repair
  • Loading branch information
uavstack authored Nov 2, 2017
2 parents 4edb0e9 + 6ec5bca commit d7a7880
Show file tree
Hide file tree
Showing 31 changed files with 370 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void start(HookContext context, ClassLoader webapploader) {
Event evt = context.get(Event.class);

switch (evt) {
case SPRING_BEAN_REGIST:
case WEBCONTAINER_INIT:
InsertInterceptToClients(context, webapploader);
break;
Expand All @@ -69,6 +70,9 @@ public void start(HookContext context, ClassLoader webapploader) {

private void InsertInterceptToClients(HookContext context, ClassLoader webapploader) {

if (isHookEventDone("InsertInterceptToClients")) {
return;
}
InterceptContext ic = (InterceptContext) context.get(HookConstants.INTERCEPTCONTEXT);

String contextPath = (String) ic.get(InterceptConstants.CONTEXTPATH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void start(HookContext context, ClassLoader webapploader) {
Event evt = context.get(Event.class);

switch (evt) {
case SPRING_BEAN_REGIST:
case WEBCONTAINER_INIT:
InsertInterceptToClients(context, webapploader);
break;
Expand All @@ -76,6 +77,10 @@ public void start(HookContext context, ClassLoader webapploader) {

public void InsertInterceptToClients(HookContext context, ClassLoader webapploader) {

if (isHookEventDone("InsertInterceptToClients")) {
return;
}

InterceptContext ic = (InterceptContext) context.get(HookConstants.INTERCEPTCONTEXT);

String contextPath = (String) ic.get(InterceptConstants.CONTEXTPATH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public void start(HookContext context, ClassLoader webapploader) {
Event evt = context.get(Event.class);

switch (evt) {
case SPRING_BEAN_REGIST:
case WEBCONTAINER_INIT:
InsertInterceptToClients(context, webapploader);
break;
Expand All @@ -76,6 +77,10 @@ public void start(HookContext context, ClassLoader webapploader) {

public void InsertInterceptToClients(HookContext context, ClassLoader webapploader) {

if (isHookEventDone("InsertInterceptToClients")) {
return;
}

InterceptContext ic = (InterceptContext) context.get(HookConstants.INTERCEPTCONTEXT);

String contextPath = (String) ic.get(InterceptConstants.CONTEXTPATH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public void start(HookContext context, ClassLoader webapploader) {
Event evt = context.get(Event.class);

switch (evt) {
case SPRING_BEAN_REGIST:
case WEBCONTAINER_RESOURCE_INIT:
break;
case WEBCONTAINER_INIT:
Expand All @@ -76,6 +77,10 @@ public void start(HookContext context, ClassLoader webapploader) {

public void InsertInterceptToClients(HookContext context, ClassLoader webapploader) {

if (isHookEventDone("InsertInterceptToClients")) {
return;
}

InterceptContext ic = (InterceptContext) context.get(HookConstants.INTERCEPTCONTEXT);
String contextPath = (String) ic.get(InterceptConstants.CONTEXTPATH);
String basePath = (String) ic.get(InterceptConstants.BASEPATH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void start(HookContext context, ClassLoader webapploader) {

Event event = context.get(Event.class);
switch (event) {
case SPRING_BEAN_REGIST:
case WEBCONTAINER_INIT:
insertIntercepter(context, webapploader);
break;
Expand All @@ -70,6 +71,10 @@ public void start(HookContext context, ClassLoader webapploader) {

private void insertIntercepter(HookContext context, ClassLoader webapploader) {

if (isHookEventDone("InsertInterceptToClients")) {
return;
}

InterceptContext ic = (InterceptContext) context.get(HookConstants.INTERCEPTCONTEXT);

String contextPath = (String) ic.get(InterceptConstants.CONTEXTPATH);
Expand All @@ -87,7 +92,7 @@ public void doInstallDProxy(ClassLoader webapploader, final String appid) {
dpInstall.setTargetClassLoader(webapploader);

/**
* install proxy to InternalHttpAsyncClient
* install proxy to javax.xml.ws.Service
*/
dpInstall.installProxy("javax.xml.ws.Service", new String[] { "com.creditease.uav.hook.jaxws.interceptors" },
new DynamicProxyProcessor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,9 @@ public class JdbcHookProxy extends HookProxy {

private final DynamicProxyInstaller dpInstall;

private boolean isInjectDrvMgr = false;
private boolean isInjectDruid = false;
private boolean isInjectDBCP2 = false;
private boolean isInjectTomcatDBCP2 = false;
private boolean isInjectHikari = false;
private boolean isInjectDataSource = false;

@SuppressWarnings("rawtypes")
public JdbcHookProxy(String id, Map config) {
super(id, config);

dpInstall = new DynamicProxyInstaller();
}

Expand All @@ -64,6 +56,7 @@ public void start(HookContext context, ClassLoader webapploader) {
Event event = context.get(Event.class);
InterceptContext ic = (InterceptContext) context.get(HookConstants.INTERCEPTCONTEXT);
switch (event) {
case SPRING_BEAN_REGIST:
case WEBCONTAINER_RESOURCE_INIT:
this.injectDriverManager(webapploader, ic);
this.injectDBCP2(webapploader, ic);
Expand Down Expand Up @@ -113,12 +106,10 @@ private String getAppID(InterceptContext ic) {
*/
private void injectDriverManager(ClassLoader webapploader, InterceptContext ic) {

if (this.isInjectDrvMgr == true) {
if (isHookEventDone("isInjectDrvMgr")) {
return;
}

this.isInjectDrvMgr = true;

JdbcDriverIT jdbcDriverIT = new JdbcDriverIT(this.getAppID(ic));

jdbcDriverIT.initSomeDrivers(webapploader);
Expand Down Expand Up @@ -149,12 +140,10 @@ private void injectDataSource(InterceptContext ic) {
return;
}

if (this.isInjectDataSource == true) {
if (isHookEventDone("isInjectDataSource")) {
return;
}

this.isInjectDataSource = true;

JdbcDriverIT jdbcDriverIT = new JdbcDriverIT(this.getAppID(ic));

ServerVendor vendor = (ServerVendor) this.getServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR);
Expand Down Expand Up @@ -188,12 +177,10 @@ private void injectTomcatDBCP2(ClassLoader webapploader, InterceptContext ic) {
return;
}

if (this.isInjectTomcatDBCP2 == true) {
if (isHookEventDone("isInjectTomcatDBCP2")) {
return;
}

this.isInjectTomcatDBCP2 = true;

final String appid = this.getAppID(ic);

/**
Expand Down Expand Up @@ -242,12 +229,10 @@ private void injectDBCP2(ClassLoader webapploader, InterceptContext ic) {
return;
}

if (this.isInjectDBCP2 == true) {
if (isHookEventDone("isInjectDBCP2")) {
return;
}

this.isInjectDBCP2 = true;

final String appid = this.getAppID(ic);

/**
Expand Down Expand Up @@ -294,12 +279,10 @@ private void injectHikari(ClassLoader webapploader, InterceptContext ic) {
return;
}

if (isInjectHikari == true) {
if (isHookEventDone("isInjectHikari")) {
return;
}

isInjectHikari = true;

final String appid = this.getAppID(ic);

final String contextPath = (String) ic.get(InterceptConstants.CONTEXTPATH);
Expand Down Expand Up @@ -357,12 +340,10 @@ private void injectDruid(ClassLoader webapploader, InterceptContext ic) {
return;
}

if (this.isInjectDruid == true) {
if (isHookEventDone("isInjectDruid")) {
return;
}

this.isInjectDruid = true;

final String appid = this.getAppID(ic);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public void start(HookContext context, ClassLoader webapploader) {
Event event = context.get(Event.class);
InterceptContext ic = (InterceptContext) context.get(HookConstants.INTERCEPTCONTEXT);
switch (event) {
case SPRING_BEAN_REGIST:
case WEBCONTAINER_INIT:
initHook(ic);
break;
Expand Down Expand Up @@ -89,6 +90,9 @@ public void start(HookContext context, ClassLoader webapploader) {
*/
private void initHook(InterceptContext ic) {

if (isHookEventDone("initHook")) {
return;
}
String contextPath = (String) ic.get(InterceptConstants.CONTEXTPATH);
String basePath = (String) ic.get(InterceptConstants.BASEPATH);
appid = MonitorServerUtil.getApplicationId(contextPath, basePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public class DBCPHookProxy extends AbsDBPoolHookProxy {

protected DynamicProxyInstaller dpInstall;

private boolean isInit = false;

@SuppressWarnings("rawtypes")
public DBCPHookProxy(String id, Map config) {
super(id, config);
Expand All @@ -62,6 +60,7 @@ public void start(HookContext context, ClassLoader webapploader) {

Event event = context.get(Event.class);
switch (event) {
case SPRING_BEAN_REGIST:
case WEBCONTAINER_RESOURCE_INIT:
case WEBCONTAINER_INIT:
InsertInterceptToClients(context, webapploader);
Expand Down Expand Up @@ -93,16 +92,15 @@ public void start(HookContext context, ClassLoader webapploader) {
*/
private void InsertInterceptToClients(HookContext context, ClassLoader webapploader) {

if (isHookEventDone("InsertInterceptToClients")) {
return;
}

InterceptContext ic = (InterceptContext) context.get(HookConstants.INTERCEPTCONTEXT);
String contextPath = (String) ic.get(InterceptConstants.CONTEXTPATH);
String basePath = (String) ic.get(InterceptConstants.BASEPATH);
appid = MonitorServerUtil.getApplicationId(contextPath, basePath);

if (isInit == true) {
return;
}

isInit = true;
/**
* set the webapploader is the target classloader
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public void start(HookContext context, ClassLoader webapploader) {

Event event = context.get(Event.class);
switch (event) {
case SPRING_BEAN_REGIST:
case WEBCONTAINER_RESOURCE_INIT:
case WEBCONTAINER_INIT:
InsertInterceptToClients(context, webapploader);
Expand Down Expand Up @@ -89,16 +90,15 @@ public void start(HookContext context, ClassLoader webapploader) {
*/
private void InsertInterceptToClients(HookContext context, ClassLoader webapploader) {

if (isHookEventDone("InsertInterceptToClients")) {
return;
}

InterceptContext ic = (InterceptContext) context.get(HookConstants.INTERCEPTCONTEXT);
String contextPath = (String) ic.get(InterceptConstants.CONTEXTPATH);
String basePath = (String) ic.get(InterceptConstants.BASEPATH);
appid = MonitorServerUtil.getApplicationId(contextPath, basePath);

if (isInit == true) {
return;
}

isInit = true;
// /**
// * set the webapploader is the target classloader
// */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public class MybatisHookProxy extends AbsDBPoolHookProxy {
protected DynamicProxyInstaller dpInstall;

private ClassLoader webapploaderForMybatis = null;
private boolean isInit = false;

@SuppressWarnings("rawtypes")
public MybatisHookProxy(String id, Map config) {
Expand All @@ -65,6 +64,7 @@ public void start(HookContext context, ClassLoader webapploader) {
webapploaderForMybatis = webapploader;
Event event = context.get(Event.class);
switch (event) {
case SPRING_BEAN_REGIST:
case WEBCONTAINER_RESOURCE_INIT:
case WEBCONTAINER_INIT:
InsertInterceptToClients(context, webapploader);
Expand Down Expand Up @@ -111,17 +111,15 @@ protected void collectDBPoolMetrics(MonitorElement clientElem) {

private void InsertInterceptToClients(HookContext context, ClassLoader webapploader) {

if (isHookEventDone("InsertInterceptToClients")) {
return;
}

InterceptContext ic = (InterceptContext) context.get(HookConstants.INTERCEPTCONTEXT);
String contextPath = (String) ic.get(InterceptConstants.CONTEXTPATH);
String basePath = (String) ic.get(InterceptConstants.BASEPATH);
appid = MonitorServerUtil.getApplicationId(contextPath, basePath);

if (isInit == true) {
return;
}

isInit = true;

dpInstall.setTargetClassLoader(webapploader);

dpInstall.installProxy("org.apache.ibatis.datasource.pooled.PooledDataSource",
Expand Down Expand Up @@ -157,7 +155,7 @@ private void collectDataSourceStat(MonitorElementInstance inst, DataSource pds,
ReflectHelper.invoke(className, pds, prefix + collectMtrx[i], null, null, webapploader));
}

Object poolState = ReflectHelper.invoke(className, pds, "getPoolState", null, null,webapploader);
Object poolState = ReflectHelper.invoke(className, pds, "getPoolState", null, null, webapploader);

for (; i < collectMtrx.length; i++) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@

import java.util.Map;

import com.creditease.monitor.UAVServer;
import com.creditease.monitor.appfra.hook.spi.HookConstants;
import com.creditease.monitor.appfra.hook.spi.HookContext;
import com.creditease.monitor.appfra.hook.spi.HookProxy;
import com.creditease.monitor.captureframework.spi.CaptureConstants;
import com.creditease.monitor.interceptframework.spi.InterceptConstants;
import com.creditease.monitor.interceptframework.spi.InterceptContext;
import com.creditease.monitor.interceptframework.spi.InterceptContext.Event;
Expand Down Expand Up @@ -59,6 +57,7 @@ public void start(HookContext context, ClassLoader webapploader) {
Event evt = context.get(Event.class);

switch (evt) {
case SPRING_BEAN_REGIST:
case WEBCONTAINER_INIT:
InsertInterceptToClients(context, webapploader);
break;
Expand All @@ -78,14 +77,9 @@ public void start(HookContext context, ClassLoader webapploader) {

public void InsertInterceptToClients(HookContext context, ClassLoader webapploader) {

/**
* NOTE: this is a special process for springboot, because the MongoClient hook happens in transform
*/
if (UAVServer.ServerVendor.SPRINGBOOT == UAVServer.instance()
.getServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR)) {
if (isHookEventDone("InsertInterceptToClients")) {
return;
}

InterceptContext ic = (InterceptContext) context.get(HookConstants.INTERCEPTCONTEXT);

String contextPath = (String) ic.get(InterceptConstants.CONTEXTPATH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void start(HookContext context, ClassLoader webapploader) {
Event evt = context.get(Event.class);

switch (evt) {
case SPRING_BEAN_REGIST:
case WEBCONTAINER_INIT:
InsertInterceptToClients(context, webapploader);
break;
Expand All @@ -76,6 +77,10 @@ public void start(HookContext context, ClassLoader webapploader) {

public void InsertInterceptToClients(HookContext context, ClassLoader webapploader) {

if (isHookEventDone("InsertInterceptToClients")) {
return;
}

InterceptContext ic = (InterceptContext) context.get(HookConstants.INTERCEPTCONTEXT);

String contextPath = (String) ic.get(InterceptConstants.CONTEXTPATH);
Expand Down
Loading

0 comments on commit d7a7880

Please sign in to comment.