2012-08-22 120 views
1
得到服務的路徑

我的代碼是這樣的:WSO2治理註冊表無法通過註冊表API

public static void main(String[] args) throws MalformedURLException, RegistryException{ 
    System.setProperty("javax.net.ssl.trustStore", "D:/Program Files (x86)/keystores/MyCompany.jks"); 
    System.setProperty("javax.net.ssl.trustStorePassword", "4362976"); 
    System.setProperty("javax.net.ssl.trustStoreType","JKS"); 
    RemoteRegistry registry = new RemoteRegistry(new URL("https://localhost:9443/registry"), "admin", "admin"); 
    ServiceManager serviceManager = new ServiceManager(registry); 
    Service[] services = serviceManager.findServices(new ServiceFilter() { 
     public boolean matches(Service service) throws GovernanceException { 
      String attributeVal = service.getAttribute("interface_transportProtocols"); 

      return (attributeVal != null && attributeVal.equals("HTTPS")); 
     } 
    }); 


    System.out.println(services[0].isActive()); 

} 

併發生異常:

Exception in thread "main" org.wso2.carbon.governance.api.exception.GovernanceException: **A path is not associated with the artifact.** 
    at org.wso2.carbon.governance.api.common.dataobjects.GovernanceArtifact.checkRegistryResourceAssociation(GovernanceArtifact.java:570) 
    at org.wso2.carbon.governance.api.services.dataobjects.Service.isActive(Service.java:186) 
    at org.wso2.carbon.registry.ws.client.sample.RemoteReg.main(RemoteReg.java:36) 

誰能幫助?多謝。

回答

0

您用來初始化ServiceManager的註冊表實例應該是治理註冊表的實例。

如:

RemoteRegistry registry = new RemoteRegistry(new URL("https://localhost:9443/registry"), "admin", "admin"); 

Registry govRegistry = GovernanceUtils.getGovernanceUserRegistry(registry,"admin"); 

ServiceManager serviceManager = new ServiceManager(govRegistry); 
+0

THX了很多。這就是答案 – user1450233