下面列出了org.apache.commons.lang3.ArrayUtils#isNotEmpty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 初始化
*/
public static void init() {
// 获取到 @Controller 注解的类列表
List<Class<?>> controllerClassList = ClassUtil.getClassListByAnnotation(scanPackage, Controller.class);
if (CollectionUtils.isNotEmpty(controllerClassList)) {
for (Class<?> controllerClass : controllerClassList) {
// 获取并遍历所有 Controller 类中的所有方法
Method[] controllerMethods = controllerClass.getMethods();
if (ArrayUtils.isNotEmpty(controllerMethods)) {
for (Method controllerMethod : controllerMethods) {
handlerControllerMethod(controllerMethod, controllerClass);
}
}
}
}
}
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
if (metadata.isAnnotated(Bean.class.getName())) {
Map<String, Object> map = metadata.getAnnotationAttributes(Bean.class.getName());
if(!CollectionUtils.isEmpty(map)) {
String[] names = (String[]) map.get("name");
if(ArrayUtils.isNotEmpty(names)) {
for(String name : names) {
if(StringUtils.isNotBlank(name) && name.endsWith("ConfigBean")) {
return true;
}
}
}
}
}
return false;
}
@Override
public ServiceConfig retrieveService(String interfaze, ApplicationEntity applicationEntity) throws Exception {
String application = applicationEntity.getApplication();
String group = applicationEntity.getGroup();
StringBuilder builder = createServiceInterfacePath(interfaze, application, group);
String path = builder.toString();
byte[] data = invoker.getData(path);
if (ArrayUtils.isNotEmpty(data)) {
LOG.info("Retrieved service config [{}]", path);
ServiceConfig serviceConfig = invoker.getObject(data, ServiceConfig.class);
return serviceConfig;
}
return null;
}
/**
* Build content content.
*
* @param components the components
* @param annotations the annotations
* @param methodProduces the method produces
* @param jsonView the json view
* @param returnType the return type
* @return the content
*/
public Content buildContent(Components components, Annotation[] annotations, String[] methodProduces, JsonView jsonView, Type returnType) {
Content content = new Content();
// if void, no content
if (isVoid(returnType))
return null;
if (ArrayUtils.isNotEmpty(methodProduces)) {
Schema<?> schemaN = calculateSchema(components, returnType, jsonView, annotations);
if (schemaN != null) {
io.swagger.v3.oas.models.media.MediaType mediaType = new io.swagger.v3.oas.models.media.MediaType();
mediaType.setSchema(schemaN);
// Fill the content
setContent(methodProduces, content, mediaType);
}
}
return content;
}
@Override
public void run(String... args) throws Exception {
String port = env.getProperty("server.port", "8080");
String contextPath = env.getProperty("server.servlet.context-path", "/");
String applicationName = env.getProperty("spring.application.name", "");
String profiles = "";
if (ArrayUtils.isNotEmpty(env.getActiveProfiles())) {
profiles = Arrays.stream(env.getActiveProfiles()).collect(Collectors.joining(","));
}
StringBuilder sb = new StringBuilder();
sb.append("\n----------------------------------------------------------\n")
.append("\t应用【").append(applicationName).append("】已经启动!\n")
.append("\t激活profile:\t").append(profiles).append("\n")
.append("\t访问路径:\n")
.append("\t本地: \thttp://localhost:").append(port).append(contextPath).append("\n")
.append("\t外部: \thttp://").append(IpUtil.getLocalIp()).append(":").append(port).append(contextPath).append("\n");
if (swaggerEnabled) {
sb.append("\t文档:\thttp://").append(IpUtil.getLocalIp()).append(":").append(port).append(contextPath).append("swagger-ui.html");
}
sb.append("\n----------------------------------------------------------");
LOG.info(sb.toString());
}
@Override
public List<BrokerMessageInfo> getPartitionMessage(String topic, String app, short partition, long index, int count) {
try {
List<BrokerMessage> brokerMessages = Lists.newArrayListWithCapacity(count);
List<BrokerMessageInfo> result = Lists.newArrayListWithCapacity(count);
byte[][] bytes = storeManagementService.readMessages(topic, partition, index, count);
if (ArrayUtils.isNotEmpty(bytes)) {
for (byte[] message : bytes) {
brokerMessages.add(Serializer.readBrokerMessage(ByteBuffer.wrap(message)));
}
}
brokerMessages = messageConvertSupport.convert(brokerMessages, SourceType.INTERNAL.getValue());
for (BrokerMessage brokerMessage : brokerMessages) {
result.add(new BrokerMessageInfo(brokerMessage));
}
return result;
} catch (Exception e) {
throw new ManageException(e);
}
}
/**
* Construct the Java command lines based on the given launch arguments.
* @param launchArguments - The launch arguments
* @param serverMode - whether to enable the debug port with server mode
* @param address - the debug port
* @return the command arrays
*/
public static String[] constructLaunchCommands(LaunchArguments launchArguments, boolean serverMode, String address) {
List<String> launchCmds = new ArrayList<>();
if (launchArguments.launcherScript != null) {
launchCmds.add(launchArguments.launcherScript);
}
if (StringUtils.isNotBlank(launchArguments.javaExec)) {
launchCmds.add(launchArguments.javaExec);
} else {
final String javaHome = StringUtils.isNotEmpty(DebugSettings.getCurrent().javaHome) ? DebugSettings.getCurrent().javaHome
: System.getProperty("java.home");
launchCmds.add(Paths.get(javaHome, "bin", "java").toString());
}
if (StringUtils.isNotEmpty(address)) {
launchCmds.add(String.format("-agentlib:jdwp=transport=dt_socket,server=%s,suspend=y,address=%s", serverMode ? "y" : "n", address));
}
if (StringUtils.isNotBlank(launchArguments.vmArgs)) {
launchCmds.addAll(DebugUtility.parseArguments(launchArguments.vmArgs));
}
if (ArrayUtils.isNotEmpty(launchArguments.modulePaths)) {
launchCmds.add("--module-path");
launchCmds.add(String.join(File.pathSeparator, launchArguments.modulePaths));
}
if (ArrayUtils.isNotEmpty(launchArguments.classPaths)) {
launchCmds.add("-cp");
launchCmds.add(String.join(File.pathSeparator, launchArguments.classPaths));
}
// For java 9 project, should specify "-m $MainClass".
String[] mainClasses = launchArguments.mainClass.split("/");
if (mainClasses.length == 2) {
launchCmds.add("-m");
}
launchCmds.add(launchArguments.mainClass);
if (StringUtils.isNotBlank(launchArguments.args)) {
launchCmds.addAll(DebugUtility.parseArguments(launchArguments.args));
}
return launchCmds.toArray(new String[0]);
}
@Override
protected RemediationTO resolveReference(final Method method, final Object... args)
throws UnresolvedReferenceException {
String key = null;
if (ArrayUtils.isNotEmpty(args)) {
for (int i = 0; key == null && i < args.length; i++) {
if (args[i] instanceof String) {
key = (String) args[i];
} else if (args[i] instanceof RemediationTO) {
key = ((RemediationTO) args[i]).getKey();
}
}
}
if (StringUtils.isNotBlank(key)) {
try {
return binder.getRemediationTO(remediationDAO.find(key));
} catch (Throwable ignore) {
LOG.debug("Unresolved reference", ignore);
throw new UnresolvedReferenceException(ignore);
}
}
throw new UnresolvedReferenceException();
}
public static ClassStructureCollectionAsserter buildJavaClassNameArrayAsserter(final String... javaClassNameArray) {
final ClassStructureCollectionAsserter classStructureCollectionAsserter = new ClassStructureCollectionAsserter(Mode.FULL);
if (ArrayUtils.isNotEmpty(javaClassNameArray)) {
for (final String javaClassName : javaClassNameArray) {
classStructureCollectionAsserter.assertTargetByKey(
javaClassName,
new ClassStructureAsserter().assertJavaClassNameEquals(javaClassName)
);
}
}
return classStructureCollectionAsserter;
}
/**
* Returns true if the path should be excluded or ignored for targeting.
*
* @param path the path
*
* @return true if the path should be excluded
*/
public static boolean excludePath(String path) {
String[] excludePatterns = SiteProperties.getExcludePatterns();
if (ArrayUtils.isNotEmpty(excludePatterns)) {
return RegexUtils.matchesAny(path, excludePatterns);
} else {
return false;
}
}
/**
* {@inheritDoc}
*/
public List<String> getStringList(String name, List<String> dflt) {
String[] values = getStrings(name);
if (ArrayUtils.isNotEmpty(values)) {
return Arrays.asList(values);
} else {
return dflt != null ? dflt : new ArrayList<>();
}
}
@Override
protected ClientAppTO resolveReference(final Method method, final Object... args)
throws UnresolvedReferenceException {
String key = null;
if (ArrayUtils.isNotEmpty(args)) {
for (int i = 0; key == null && i < args.length; i++) {
if (args[i] instanceof String) {
key = (String) args[i];
} else if (args[i] instanceof ClientAppTO) {
key = ((ClientAppTO) args[i]).getKey();
}
}
}
if (key != null) {
try {
ClientApp clientApp = saml2spDAO.find(key);
if (clientApp == null) {
clientApp = oidcrpDAO.find(key);
}
return binder.getClientAppTO(clientApp);
} catch (Throwable ignore) {
LOG.debug("Unresolved reference", ignore);
throw new UnresolvedReferenceException(ignore);
}
}
throw new UnresolvedReferenceException();
}
@Override
protected void calculateUiRootPath(StringBuilder... sbUrls) {
StringBuilder sbUrl = new StringBuilder();
if (StringUtils.isNotBlank(mvcServletPath))
sbUrl.append(mvcServletPath);
if (ArrayUtils.isNotEmpty(sbUrls))
sbUrl = sbUrls[0];
String swaggerPath = swaggerUiConfigParameters.getPath();
if (swaggerPath.contains(DEFAULT_PATH_SEPARATOR))
sbUrl.append(swaggerPath, 0, swaggerPath.lastIndexOf(DEFAULT_PATH_SEPARATOR));
swaggerUiConfigParameters.setUiRootPath(sbUrl.toString());
}
@Override
protected PolicyTO resolveReference(final Method method, final Object... args)
throws UnresolvedReferenceException {
String key = null;
if (ArrayUtils.isNotEmpty(args)) {
for (int i = 0; key == null && i < args.length; i++) {
if (args[i] instanceof String) {
key = (String) args[i];
} else if (args[i] instanceof PolicyTO) {
key = ((PolicyTO) args[i]).getKey();
}
}
}
if (key != null) {
try {
return binder.getPolicyTO(policyDAO.find(key));
} catch (Throwable ignore) {
LOG.debug("Unresolved reference", ignore);
throw new UnresolvedReferenceException(ignore);
}
}
throw new UnresolvedReferenceException();
}
@Override
public Object generate(Object target, Method method, Object... params) {
Class<?> cls = target.getClass();
String cachePrefix = Constant.Cache.CLASSKEY_MAP.get(cls);
if (StringUtils.isBlank(cachePrefix)) {
CacheConfig cacheConfig = cls.getAnnotation(CacheConfig.class);
if (cacheConfig == null || ArrayUtils.isEmpty(cacheConfig.cacheNames())) {
cachePrefix = cls.getName();
} else {
cachePrefix = cacheConfig.cacheNames()[0];
}
Constant.Cache.CLASSKEY_MAP.put(cls, cachePrefix);
}
String cacheName;
Cacheable cacheable = method.getAnnotation(Cacheable.class);
CachePut cachePut = method.getAnnotation(CachePut.class);
CacheEvict cacheEvict = method.getAnnotation(CacheEvict.class);
if (cacheable != null && ArrayUtils.isNotEmpty(cacheable.value())) {
cacheName = cacheable.value()[0];
} else if (cachePut != null && ArrayUtils.isNotEmpty(cachePut.value())) {
cacheName = cachePut.value()[0];
} else if (cacheEvict != null && ArrayUtils.isNotEmpty(cacheEvict.value())) {
cacheName = cacheEvict.value()[0];
} else {
cacheName = method.getName();
}
return cachePrefix + ":" + cacheName + ":" + generateKey(params);
}
@Override
protected TaskTO resolveReference(final Method method, final Object... args)
throws UnresolvedReferenceException {
String key = null;
if (ArrayUtils.isNotEmpty(args)
&& !"deleteExecution".equals(method.getName()) && !"readExecution".equals(method.getName())) {
for (int i = 0; key == null && i < args.length; i++) {
if (args[i] instanceof String) {
key = (String) args[i];
} else if (args[i] instanceof TaskTO) {
key = ((TaskTO) args[i]).getKey();
}
}
}
if (key != null) {
try {
final Task task = taskDAO.find(key);
return binder.getTaskTO(task, taskUtilsFactory.getInstance(task), false);
} catch (Throwable ignore) {
LOG.debug("Unresolved reference", ignore);
throw new UnresolvedReferenceException(ignore);
}
}
throw new UnresolvedReferenceException();
}
@Override
public boolean isArrayNotEmpty(Object[] array) {
return ArrayUtils.isNotEmpty(array);
}
/**
* Shiro路径权限配置
*
* @return
*/
private Map<String, String> getFilterChainDefinitionMap(ShiroProperties shiroProperties) {
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
// 获取排除的路径
List<String[]> anonList = shiroProperties.getAnon();
log.debug("anonList:{}", JSON.toJSONString(anonList));
if (CollectionUtils.isNotEmpty(anonList)) {
anonList.forEach(anonArray -> {
if (ArrayUtils.isNotEmpty(anonArray)) {
for (String anonPath : anonArray) {
filterChainDefinitionMap.put(anonPath, ANON);
}
}
});
}
// 获取ini格式配置
String definitions = shiroProperties.getFilterChainDefinitions();
if (StringUtils.isNotBlank(definitions)) {
Map<String, String> section = IniUtil.parseIni(definitions);
log.debug("definitions:{}", JSON.toJSONString(section));
for (Map.Entry<String, String> entry : section.entrySet()) {
filterChainDefinitionMap.put(entry.getKey(), entry.getValue());
}
}
// 获取自定义权限路径配置集合
List<ShiroPermissionProperties> permissionConfigs = shiroProperties.getPermission();
log.debug("permissionConfigs:{}", JSON.toJSONString(permissionConfigs));
if (CollectionUtils.isNotEmpty(permissionConfigs)) {
for (ShiroPermissionProperties permissionConfig : permissionConfigs) {
String url = permissionConfig.getUrl();
String[] urls = permissionConfig.getUrls();
String permission = permissionConfig.getPermission();
if (StringUtils.isBlank(url) && ArrayUtils.isEmpty(urls)) {
throw new ShiroConfigException("shiro permission config 路径配置不能为空");
}
if (StringUtils.isBlank(permission)) {
throw new ShiroConfigException("shiro permission config permission不能为空");
}
if (StringUtils.isNotBlank(url)) {
filterChainDefinitionMap.put(url, permission);
}
if (ArrayUtils.isNotEmpty(urls)) {
for (String string : urls) {
filterChainDefinitionMap.put(string, permission);
}
}
}
}
// 如果启用shiro,则设置最后一个设置为JWTFilter,否则全部路径放行
if (shiroProperties.isEnable()) {
filterChainDefinitionMap.put("/**", JWT_FILTER_NAME);
} else {
filterChainDefinitionMap.put("/**", ANON);
}
log.debug("filterChainMap:{}", JSON.toJSONString(filterChainDefinitionMap));
// 添加默认的filter
Map<String, String> newFilterChainDefinitionMap = addDefaultFilterDefinition(filterChainDefinitionMap);
return newFilterChainDefinitionMap;
}
/**
* Message dispatcher logic.
*
* @param msg the msg
*/
public void dispatch(NotificationMessage msg) {
if (msg.getNsPath() == null) {
String nsPath = getNsPath(msg);
if (nsPath != null) {
msg.setNsPath(nsPath);
} else {
logger.error("Can not figure out nsPath for msg " + gson.toJson(msg));
return;
}
}
List<BasicSubscriber> subscribers = sbrService.getSubscribersForNs(msg.getNsPath());
try {
for (BasicSubscriber sub : subscribers) {
NotificationMessage nMsg = msg;
if (sub.hasFilter() && !sub.getFilter().accept(nMsg)) {
continue;
}
if (sub.hasTransformer()) {
nMsg = sub.getTransformer().transform(nMsg);
}
if (sub instanceof EmailSubscriber) {
eSender.postMessage(nMsg, sub);
} else if (sub instanceof SNSSubscriber) {
snsSender.postMessage(nMsg, sub);
} else if (sub instanceof URLSubscriber) {
if (sub.getFilter() instanceof NotificationFilter) {
NotificationFilter nFilter = NotificationFilter.class.cast(sub.getFilter());
if (nFilter.isIncludeCi() && ArrayUtils.isNotEmpty(nFilter.getClassNames())) {
final List<Long> ciIds = dpmtMapper
.getDeploymentRfcCIs(msg.getCmsId(), null, null, nFilter.getClassNames(),
nFilter.getActions())
.stream()
.map(rfc -> rfc.getCiId())
.collect(Collectors.toList());
if(ciIds.isEmpty()){
// There are no ci's which sink is subscribed to , skip notifications.
continue;
}
final List<CmsCISimple> cis = cmProcessor.getCiByIdList(ciIds).stream()
.map(ci -> cmsUtil.custCI2CISimple(ci, "df")).collect(
Collectors.toList());
nMsg.setCis(cis);
}
}
if(logger.isDebugEnabled()){
logger.debug("nMsg " + gson.toJson(nMsg));
}
urlSender.postMessage(nMsg, sub);
} else if (sub instanceof XMPPSubscriber) {
xmppSender.postMessage(nMsg, sub);
} else if (sub instanceof SlackSubscriber) {
slackSender.postMessage(nMsg, sub);
}
}
} catch (Exception e) {
logger.error("Message dispatching failed.", e);
}
}
public PluginClassLoader(URL[] urls, ClassLoader parent, Routing... routingArray) {
super(urls, parent);
if (ArrayUtils.isNotEmpty(routingArray)) {
this.routingArray.addAll(Arrays.asList(routingArray));
}
}