1

我可以像这样使用治理 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 访问属性列表(不是属性)我很难弄清楚这些是如何相互关联的。

4

1 回答 1

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));
                }
        }

有关完整代码,请参阅此示例博客文章

----稍后添加---

这更符合您的代码。

 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());
        }
于 2013-03-28T00:18:56.070 回答