mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-05 13:17:58 +08:00
add test
This commit is contained in:
parent
09ae727b81
commit
e784e1fcd4
@ -6,6 +6,7 @@ import cn.hutool.core.map.MapUtil;
|
||||
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attributes;
|
||||
import javax.naming.directory.InitialDirContext;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
@ -15,6 +16,10 @@ import java.util.Map;
|
||||
* JNDI是Java Naming and Directory Interface(JAVA命名和目录接口)的英文简写,<br>
|
||||
* 它是为JAVA应用程序提供命名和目录访问服务的API(Application Programing Interface,应用程序编程接口)。
|
||||
*
|
||||
* <p>
|
||||
* 见:https://blog.csdn.net/u010430304/article/details/54601302
|
||||
* </p>
|
||||
*
|
||||
* @author loolY
|
||||
* @since 5.7.7
|
||||
*/
|
||||
@ -53,4 +58,20 @@ public class JNDIUtil {
|
||||
throw new UtilException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定容器环境的对象的属性<br>
|
||||
* 如获取DNS属性,则URI为类似:dns:hutool.cn
|
||||
*
|
||||
* @param uri URI字符串,格式为[scheme:][name]/[domain]
|
||||
* @param attrIds 需要获取的属性ID名称
|
||||
* @return {@link Attributes}
|
||||
*/
|
||||
public static Attributes getAttributes(String uri, String... attrIds) {
|
||||
try {
|
||||
return createInitialDirContext(null).getAttributes(uri, attrIds);
|
||||
} catch (NamingException e) {
|
||||
throw new UtilException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
21
hutool-core/src/test/java/cn/hutool/core/util/JNDIUtilTest.java
Executable file
21
hutool-core/src/test/java/cn/hutool/core/util/JNDIUtilTest.java
Executable file
@ -0,0 +1,21 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.collection.EnumerationIter;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.naming.directory.Attribute;
|
||||
import javax.naming.directory.Attributes;
|
||||
|
||||
public class JNDIUtilTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void getDnsTest(){
|
||||
final Attributes attributes = JNDIUtil.getAttributes("dns:hutool.cn", "TXT");
|
||||
for (Attribute attribute: new EnumerationIter<>(attributes.getAll())){
|
||||
Console.log(attribute);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user