I am unable to get the list of services with in the applicaton i.e.; wso2 governance registry? I am working with binary code

牧云@^-^@ 提交于 2020-01-14 05:34:53

问题


I am trying to get the list of services which are in the resource path /_system/governance/trunk/services. So initially I am trying to get the resource using registry api. I tried in two ways. one way is

         `CarbonContext cCtx = CarbonContext.getCurrentContext();

          Registry registry = cCtx.getRegistry(RegistryType.SYSTEM_CONFIGURATION);
          String registryType = request.getParameter("registryType");
          if(registryType != null) {
          registry = cCtx.getRegistry(RegistryType.valueOf(registryType));
          }
          String resourcePath = "/_system/governance/trunk/services";
          try{
      if(registry.resourceExits(resourcePath)){
        Resource resource = registry.get(resourcePath);
      }
      }catch(Exception e){
       out.print(e.getMessage());
      }` 

Another way using ServiceManager and I am failing at the first step to initialize ServiceManager

            'CarbonContext cCtx = CarbonContext.getCurrentContext();

             Registry registry = cCtx.getRegistry(RegistryType.SYSTEM_CONFIGURATION);
             String registryType = request.getParameter("registryType");
             if(registryType != null) {
                   registry = cCtx.getRegistry(RegistryType.valueOf(registryType));
               out.print(" Registry got Initialised ! ");
             }
        java.util.List<Resource> result = new java.util.ArrayList<Resource>();
        String resourcePath = "/_system/governance/trunk/services";
        ServiceManager serviceManager = new ServiceManager(registry);'   

So what's the exact thing I need to do get list of all service in index.jsp and I am working with the binary code ?


回答1:


You should use the governance registry to initialize the ServiceManager.

ServiceManager serviceManager = new ServiceManager(governanceRegistry);

Service[] services = serviceManager.getAllServices();

[1]http://docs.wso2.org/wiki/display/Governance453/Services+with+Governance+API

-Ajith




回答2:


In my case I am working in the Identity Server 4.1.0. I added a Resource in the registry from the Management-Console (Web-Frontend) in this path: /_system/local/repository The resource is called apacheInfo. Inside the resource I added a Property with
key = com.xxx.identity.Apache
value = www.domain.com:8998
my code:

CarbonContext cCtx = CarbonContext.getCurrentContext();
//this implies the path /_system/local/
Registry registry = cCtx.getRegistry(RegistryType.LOCAL_REPOSITORY);
Resource resource;
String apacheUrl;
            try {
                resource = registry.get("repository/apacheInfo");
                apacheUrl = resource.getProperty("com.xxx.identity.Apache");
            } catch (RegistryException e) {
                LOG.error("RegistryException looking up path repository/apacheInfo", e);
            }

I never found an example in the WSO2 documentation, but I saw this conversation:
http://wso2-oxygen-tank.10903.n7.nabble.com/Generic-Resource-Registry-Management-in-App-Factory-td79279.html
and then I understood the way how they read the repositories... Hope this helps



来源:https://stackoverflow.com/questions/16091482/i-am-unable-to-get-the-list-of-services-with-in-the-applicaton-i-e-wso2-govern

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