问题
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));
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.
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.
回答1:
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---
This is more aligned with your code.
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());
}
来源:https://stackoverflow.com/questions/15669564/how-do-i-access-properties-of-a-service-using-an-api-in-wso2-greg