Skip to content
Permalink
Browse files
Fix spring status check failed (#10534)
* fix spring status check failed

Signed-off-by: crazyhzm <crazyhzm@gmail.com>

* fix spring status check failed

Signed-off-by: crazyhzm <crazyhzm@gmail.com>

Signed-off-by: crazyhzm <crazyhzm@gmail.com>
CrazyHZM committed 21 days ago
1 parent f35c8d1 commit bb7f942c5dc1649ff8e0be939639280e44c731a7
Showing 1 changed file with 5 additions and 17 deletions.
}

@Override
public Status check() {
// TODO It seems to be ok with GenericWebApplicationContext, need further confirmation
// ApplicationContext context = null;
// for (ApplicationContext c : SpringExtensionInjector.getContexts()) {
// // [Issue] SpringStatusChecker execute errors on non-XML Spring configuration
// // issue : https://github.com/apache/dubbo/issues/3615
// if(c instanceof GenericWebApplicationContext) { // ignore GenericXmlApplicationContext
// continue;
// }
//
// if (c != null) {
// context = c;
// break;
// }
// }

if (applicationContext == null && applicationModel != null) {

COLLECTOR-SAHAB / covering test: SpringStatusCheckerTest

applicationContext=org.apache.dubbo.config.spring.status.SpringStatusCheckerTest$ApplicationLifeCycle$MockitoMock$991098312 only occurs in the patched version.

COLLECTOR-SAHAB / covering test: SpringStatusCheckerTest

applicationContext=org.apache.dubbo.config.spring.status.SpringStatusCheckerTest$ApplicationLifeCycle$MockitoMock$1542868289 only occurs in the original version.

SpringExtensionInjector springExtensionInjector = SpringExtensionInjector.get(applicationModel);
applicationContext = springExtensionInjector.getContext();
}
if (applicationContext == null) {
return new Status(Status.Level.UNKNOWN);
}
Status.Level level;
if (applicationContext instanceof Lifecycle) {
if (((Lifecycle) applicationContext).isRunning()) {
level = Status.Level.OK;
} else {
level = Status.Level.ERROR;
}
} else {
level = Status.Level.UNKNOWN;
}
StringBuilder buf = new StringBuilder();
try {
Class<?> cls = applicationContext.getClass();
Method method = null;
while (cls != null && method == null) {
try {
method = cls.getDeclaredMethod("getConfigLocations", new Class<?>[0]);
} catch (NoSuchMethodException t) {
cls = cls.getSuperclass();
}
}
if (method != null) {
if (!method.isAccessible()) {
method.setAccessible(true);
}
String[] configs = (String[]) method.invoke(applicationContext, new Object[0]);
if (configs != null && configs.length > 0) {
for (String config : configs) {
if (buf.length() > 0) {
buf.append(',');
}
buf.append(config);
}
}
}
} catch (UnsupportedOperationException t) {
logger.debug(t.getMessage(), t);
} catch (Throwable t) {
logger.warn(t.getMessage(), t);
if (t.getCause() instanceof UnsupportedOperationException){
logger.debug(t.getMessage(), t);
}else {
logger.warn(t.getMessage(), t);
}
}
return new Status(level, buf.toString());
}
}

0 comments on commit bb7f942

Please sign in to comment.