ReZero's Utopia.

Arthas

Word count: 810Reading time: 4 min
2021/10/19 Share

下载启动

curl -L https://arthas.aliyun.com/install.sh | sh && ./as.sh

如何查看一个map里指定的key

getstatic com.bj58.bic.ep.rankreview.web.common.Constant MAP_EMP_INFO 'entrySet().iterator.{? #this.key=="userName"}'

坑: ognl '@com.envisioniot.enos.iot_log_sdk.core.ESClient@defaultESClient' 不生效

ognl命令默认只会去 SystemClassLoader 里找类。 getstatic 命令会直接找所有JVM里加载的类,而tomcat的classloader是自己的, 所以只有 getstatic 命令能找到。 ognl 命令要显式指定classloader 。

获取 context 的 classloader

getstatic com.bj58.bic.ep.rankreview.web.component.SpringContextConfig applicationContext

翻到最下面可以看到是 org.apache.catalina.loader.ParallelWebappClassLoader

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
$ getstatic com.bj58.bic.ep.rankreview.web.component.SpringContextConfig applicationContext
field: applicationContext
@FileSystemXmlApplicationContext[
validating=@Boolean[true],
configLocations=@String[][isEmpty=false;size=1],
setIdCalled=@Boolean[false],
allowBeanDefinitionOverriding=null, allowCircularReferences=null,
beanFactory=@DefaultListableBeanFactory[org.springframework.beans.factory.support.DefaultListableBeanFactory@4b599b1a: defining beans [caffeineLocalCacheClient,initParams,operateLogAspect,appConfig,kmsClient,springContextConfig,wosClient,synEmployeeLocalCacheJob,judgeHRLeaderReviewsEmailServiceImpl,matchRuleTryCalcMatchServiceImpl,matchRuleTryCalcServiceImpl,ruleLimitCountMatchService,ruleLimitGroupMatchService,reviewsAllocService,AbstractReviewsAutoAllocP,AbstractReviewsAutoAllocT,agentServiceImpl,basicAttendSettingServiceImpl,basicConfigServiceImpl,basicJudgeGroupServiceImpl,constantValServiceImpl,contributionServiceImpl,departmentServiceImpl,directionAdminServiceImpl,emailNoticeTimingServiceImpl,evaluationJudgeServiceImpl,evaluationStatusServiceImpl,eventTriggerServiceImpl,finalResultServiceImpl,HRBPAuthServiceImpl,judgeGroupDirectionServiceImpl,judgeGroupMetaServiceImpl,judgePlacementServiceImpl,matchRuleServiceImpl,myTourServiceImpl,OAProcessServiceImpl,participantOperateServiceImpl,participantScheduleServiceImpl,plusParticipantServiceImpl,rankInfoServiceImpl,rankMetaServiceImpl,reportContentServiceImpl,reportReceiverServiceImpl,reportServiceImpl,reviewCalendarServiceImpl,reviewSessionHrServiceImpl,reviewsDirectionServiceImpl,reviewsEvaluateServiceImpl,reviewsJudgeManageServiceImpl,reviewsJudgeServiceImpl,reviewsJudgeStatementVersionServiceImpl,reviewsLessonServiceImpl,reviewsRuleServiceImpl,reviewsSessionAllocConfigServiceImpl,reviewsSessionCheckServiceImpl,reviewsSessionJudgeRelServiceImpl,reviewsSessionParticipantRelServiceImpl,reviewsSessionServiceImpl,reviewsSessionV2ServiceImpl,reviewsSessionWaiterServiceImpl,reviewsVersionServiceImpl,ruleDictServiceImpl,scoreBakServiceImpl,scoreCriteriaServiceImpl,scoreDescServiceImpl,sendEmailServiceImpl,siteMessageServiceImpl,staffEncryptDecryptServiceImpl,staffEvaluationServiceImpl,staffManageServiceimpl,staffStatisticsServiceImpl,staffStatusServiceImpl,syncInfoServiceImpl,sysPermissionServiceImpl,sysRolePermissionServiceImpl,sysRoleServiceImpl,sysUserRoleServiceImpl,userOccupiedBlockServiceImpl,userSiteMessageServiceImpl,valueObjectService,versionAuthRangeImpl,versionRuleServiceImpl,exportTemplate,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,org.springframework.context.annotation.internalAsyncAnnotationProcessor,org.springframework.context.annotation.internalScheduledAnnotationProcessor,placeholderConfigurer,beatContext,validator,bindAndValidate,org.springframework.aop.config.internalAutoProxyCreator,jedisPoolConfig,jedisPool,jedisHelper,org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration,org.springframework.transaction.config.internalTransactionAdvisor,transactionAttributeSource,transactionInterceptor,org.springframework.transaction.config.internalTransactionalEventListenerFactory,sqlSessionFactory,transactionManager,getDataSource,agentMapper,baseMapper,basicAttendSettingMapper,basicConfigJudgeGroupMapper,basicConfigJudgeParticipantMapper,basicConfigJudgeSchemaMapper,basicConfigOrgSubjectMapper,basicConfigReviewTimeMapper,basicConfigRoomMapper,basicConfigSpecialApplyMapper,contributionMapper,departmentMapper,directionAdminMapper,emailNoticeTimingMapper,evaluationJudgeMapper,evaluationStatusMapper,eventTriggerMapper,finalResultMapper,HRBPAuthMapper,judgeGroupDirectionMapper,judgeGroupMetaMapper,languageMapper,matchRuleGroupMapper,matchRuleMetaMapper,participantFlowMapper,participantMapper,plusParticipantMapper,rankInfoMapper,rankMetaMapper,rankReviewYearsRuleMapper,reportContentMapper,reportReceiverMapper,reviewCalendarMapper,reviewDirectionMapper,reviewRuleMapper,reviewSessionHrMapper,reviewsJudgeManageMapper,reviewsJudgeMapper,reviewsJudgeStatementVersionMapper,reviewsLessonMapper,reviewsSessionAllocConfigMapper,reviewsSessionJudgeRelMapper,reviewsSessionMapper,reviewsSessionParticipantRelMapper,reviewsVersionMapper,ruleDictMapper,scoreBakMapper,scoreDescriptionMapper,scoreElementMapper,siteMessageMapper,staffCountMapper,staffEvaluationMapper,staffStatisticsMapper,staffStatusMapper,syncInfoMapper,sysPermissionMapper,sysRoleMapper,sysRolePermissionMapper,sysUserRoleMapper,userOccupiedBlockMapper,userSiteMessageMapper,valueObjectMapper,versionAuthRangeMapper,versionRuleMapper,org.springframework.scheduling.annotation.SchedulingConfiguration]; root of factory hierarchy],
beanFactoryMonitor=@Object[java.lang.Object@2d19c93f],
MESSAGE_SOURCE_BEAN_NAME=@String[messageSource],
LIFECYCLE_PROCESSOR_BEAN_NAME=@String[lifecycleProcessor],
APPLICATION_EVENT_MULTICASTER_BEAN_NAME=@String[applicationEventMulticaster],
logger=@Log4JLogger[org.apache.commons.logging.impl.Log4JLogger@52743f1f],
id=@String[org.springframework.context.support.FileSystemXmlApplicationContext@48ed680],
displayName=@String[org.springframework.context.support.FileSystemXmlApplicationContext@48ed680],
parent=null,
environment=@StandardEnvironment[StandardEnvironment {activeProfiles=[], defaultProfiles=[default], propertySources=[MapPropertySource {name='systemProperties'}, SystemEnvironmentPropertySource {name='systemEnvironment'}]}],
beanFactoryPostProcessors=@ArrayList[isEmpty=true;size=0],
startupDate=@Long[1636450003372],
active=@AtomicBoolean[true],
closed=@AtomicBoolean[false],
startupShutdownMonitor=@Object[java.lang.Object@4838b5cd],
shutdownHook=null,
resourcePatternResolver=@PathMatchingResourcePatternResolver[org.springframework.core.io.support.PathMatchingResourcePatternResolver@7adbd17c],
lifecycleProcessor=@DefaultLifecycleProcessor[org.springframework.context.support.DefaultLifecycleProcessor@19e8bf29],
messageSource=@DelegatingMessageSource[org.springframework.context.support.DelegatingMessageSource@6a97f7cc],
applicationEventMulticaster=@SimpleApplicationEventMulticaster[org.springframework.context.event.SimpleApplicationEventMulticaster@678ca18e],
applicationListeners=@LinkedHashSet[isEmpty=false;size=1],
earlyApplicationEvents=null,
classLoader=@ParallelWebappClassLoader[ParallelWebappClassLoader
context: ROOT
delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@5b2133b1
],
protocolResolvers=@LinkedHashSet[isEmpty=true;size=0],
resourceCaches=@ConcurrentHashMap[isEmpty=true;size=0],
]
Affect(row-cnt:1) cost in 9 ms.

调用context 执行方法

1
2
ognl '#context=@com.bj58.bic.ep.rankreview.web.component.SpringContextConfig@applicationContext,
#context.getBean(@com.bj58.bic.ep.rankreview.web.service.IParticipantOperateService@class).queryByOA(2021110416094610850L, "lijie78")' --classLoaderClass org.apache.catalina.loader.ParallelWebappClassLoader

调用 静态方法

x 参数指定返回值的可见深度

1
ognl -x 3 '@com.bj58.bic.ep.rankreview.web.utils.BspHelper@getOrgByOrgId("201905291539077271da5c")'  --classLoaderClass   org.apache.catalina.loader.ParallelWebappClassLoader

监控方法调用 可加条件过滤

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
$ watch com.bj58.bic.ep.rankreview.web.utils.BspHelper getOrgByOrgId '{params,returnObj,throwExp}' 'throwExp != null'  -n 5  -x 3 
2021-11-16 14:34:36; [cost=5.313401ms] result=@ArrayList[
@Object[][
@String[201706021923030c1a0853],
],
@Organization[
serialVersionUID=@Long[1],
id=@String[201706021923030c1a0853],
orgName=@String[华北一区直销部],
parentId=null,
status=@String[1],
description=@String[华北一区直销部(LongyuLi(李龙雨))],
creater=null,
city=@String[,1],
parentPath=null,
orderseq=null,
orgtype=null,
orglevel=null,
hrorgid=null,
issync=null,
lastUpdateTime=@Date[2021-05-14 12:31:56,000],
parentId201408=@String[201712052142005d9e2ab7],
parentPath201408=@String[2011010814223073b228a5,2014071618493421273d30,201712052142002cb3daad,201712052142005d9e2ab7,201706021923030c1a0853],
bizArea=null,
bizLine=null,
branchCode=@String[],
lockStatus=null,
wdOrgId=@String[WD_ORG_2177],
wdOrgPid=@String[WD_ORG_3492],
location=@String[北京-东升科技园-58],
orgSubtype=null,
managerIdList=null,
],
null,
]
CATALOG
  1. 1. 下载启动
  2. 2. 如何查看一个map里指定的key
  3. 3. 获取 context 的 classloader
  4. 4. 调用context 执行方法
  5. 5. 调用 静态方法
  6. 6. 监控方法调用 可加条件过滤