How do I access properties of a Service using an API in WSO2 GREG?

∥☆過路亽.° 提交于 2019-12-24 12:31:09

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!