如何使用 WSO2 GREG 中的 API 访问服务的属性? [英] How do I access properties of a Service using an API in WSO2 GREG?
问题描述
我可以像这样使用治理 API 添加和读取属性:
I can add and read attributes using the governance API like this:
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 列表中没有看到它.
However, when I use the WSO2 Governance Registry Management Console and open the service I just added the parameter/value "what"/"isthis", I dont see it in the list of Properties.
如何使用 API 访问属性(而非属性)列表?我很难弄清楚这些是如何相互关联的.
How do I access the list of properties (not attributes) using an API? I have a hard time figuring out how these relate to each other.
推荐答案
您可以使用以下代码检索它.
You can retrieve it using following code.
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));
}
}
请参阅此示例博客文章以获取完整代码.
Refer this sample blog post for complete code.
----稍后添加---
----Added later---
这更符合您的代码.
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());
}
这篇关于如何使用 WSO2 GREG 中的 API 访问服务的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!