我可以使用治理API添加和读取属性,如下所示:
registry = Util.initialize();
governanceRegistry = Util.getGovernanceRegistry(registry);
serviceManager = new ServiceManager(governanceRegistry);
services = Arrays.asList(serviceManager.getAllServices());
services.get(2).addAttribute("what", "isthis");
serviceManager.updateService(services.get(2));
但是,当我使用WSO2 Governance Registry Management Console并打开服务时,我刚刚添加了参数/值“what”/“isthis”,我没有在 Properties 列表中看到它。
如何使用API访问属性(非属性)列表?我很难弄清楚这些是如何相互关联的。
答案 0 :(得分:1)
您可以使用以下代码检索它。
List<Resource> paths = getServicePath(registry, "/_system/governance/trunk/services");
for (Resource service : paths) {
// we've got all the services here
Properties props = service.getProperties();
for (Object prop : props.keySet()) {
System.out.println(prop + " - " + props.get(prop));
}
}
请参阅此示例blog post以获取完整代码。
----后来添加---
这与您的代码更加一致。
Registry governanceRegistry = GovernanceUtils.getGovernanceUserRegistry(registry, "admin");
ServiceManager serviceManager = new ServiceManager(governanceRegistry);
Service[] services = serviceManager.getAllServices();
for(int i =0 ; i<services.length ; i++){
Service service = services[i];
Resource resource = governanceRegistry.get(service.getPath());
System.out.println(resource.getProperties());
}