【发布时间】:2018-01-26 10:07:36
【问题描述】:
我遇到了一个问题。我有一个用于 osgi 配置的 org.osgi.service.cm.ManagedService impl 客户端。配置是键值对的集合。
这些属性中的键,当作为java.util.Dictionary 对象传递给ManagedService 的更新方法(ManagedService.updated) 时似乎不区分大小写,即props.get("HellO") 有效,即使配置中的键是“Hello”。
当我通过迭代其条目将该字典转换为Hashmap 时,映射中的键会按预期区分大小写。这是否期望Dictionary 中的键不区分大小写?
这是在 AEM 6.2 实例上测试的。
这是我的ManagedService impl 课程。
public class ConfigService implements ManagedService {
public void updated(final Dictionary props) throws ConfigurationException {
// props.get("HellO") returns value
if (props != null) {
String pid = (String) props.get(Constants.SERVICE_PID);
// convert to map
Map map = map(props);
// map.get("HellO") returns null
// map.get("Hello") returns value
}
}
private static Map map(Dictionary dict) {
Map map = new ConcurrentHashMap();
for (Enumeration keys = dict.keys(); keys.hasMoreElements();) {
Object key = keys.nextElement();
map.put(key, dict.get(key));
}
return map;
}
ManagedService impl 使用以下代码注册为服务。
final Dictionary props = new Hashtable();
props.put(Constants.SERVICE_PID, "pid.of.the.osgi.configuration" );
ServiceRegistration configSvc = context.registerService(ManagedService.class.getName(),
new ConfigService(), props);
【问题讨论】:
标签: osgi aem apache-felix