在WSO2 apim 1.10.0中,我创建了一个域名为ofer.com的租户,管理员用户名为ofer,密码为admin
我可以使用凭证ofer@ofer.com,密码:admin来登录此租户的碳管理控制台UI。
现在我正在尝试使用RemoteRegistry来导出该租户的tiers.xml。
以下是代码:
import java.io.File;
import java.net.URL;
import org.wso2.carbon.registry.app.RemoteRegistry;
import org.wso2.carbon.registry.core.utils.RegistryClientUtils;
public class test {
private static String serverHostname = "...";
public static void main(String[] args) throws Exception {
System.setProperty("javax.net.ssl.trustStore", "p:/main/test/wso2carbon.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
System.setProperty("javax.net.ssl.trustStoreType","JKS");
System.setProperty("carbon.repo.write.mode", "true");
RemoteRegistry remote_registry = new RemoteRegistry(new URL("https://" + serverHostname + ":9443/registry"), "ofer@ofer.com", "admin");
File toFile = new File("e:/tiers.xml");
RegistryClientUtils.exportFromRegistry( toFile, "/_system/governance/apimgt/applicationdata/tiers.xml" ,remote_registry);
}
}
当我使用凭据admin / admin:
运行此代码时 RemoteRegistry remote_registry = new RemoteRegistry(new URL("https://" + serverHostname + ":9443/registry"), "admin", "admin");
它成功运行,但是
RemoteRegistry remote_registry = new RemoteRegistry(new URL("https://" + serverHostname + ":9443/registry"), "ofer@ofer.com", "admin");
我得到了一个“未经宣传的”例外:
Exception in thread "main" org.wso2.carbon.registry.core.exceptions.RegistryException: Failed to export from registry
at org.wso2.carbon.registry.core.utils.RegistryClientUtils.exportFromRegistry(RegistryClientUtils.java:89)
at test.main(test.java:26)
Caused by: org.wso2.carbon.registry.core.exceptions.RegistryException: Unauthorized
at org.wso2.carbon.registry.app.RemoteRegistry.get(RemoteRegistry.java:174)
at org.wso2.carbon.registry.core.utils.RegistryClientUtils.processExport(RegistryClientUtils.java:123)
at org.wso2.carbon.registry.core.utils.RegistryClientUtils.exportFromRegistry(RegistryClientUtils.java:86)
... 1 more
知道我错过了什么吗?我是否应该允许访问ofer@ofer.com进行导出?
///已编辑///
我现在看到有另一个类RemoteRegistryService用于获取用户注册表。我在尝试:
RemoteRegistryService registryService = new RemoteRegistryService("http://" + serverHostname + ":9763/registry", "admin", "admin");
UserRegistry ur = registryService.getSystemRegistry(...)
为此,我发现它需要领域服务。我该如何掌握它?
答案 0 :(得分:1)
找到它。 URL应包括租户域,即代替 http://localhost:9443/registry http://localhost:9443/t/ /注册表
更新的代码:
import java.io.File;
import java.net.URL;
import org.wso2.carbon.registry.app.RemoteRegistry;
import org.wso2.carbon.registry.core.utils.RegistryClientUtils;
public class test {
private static String serverHostname = "...";
public static void main(String[] args) throws Exception {
System.setProperty("javax.net.ssl.trustStore", "p:/main/test/wso2carbon.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
System.setProperty("javax.net.ssl.trustStoreType","JKS");
System.setProperty("carbon.repo.write.mode", "true");
RemoteRegistry remote_registry = new RemoteRegistry(new URL("https://" + serverHostname + ":9443/t/ofer.com/registry"), "ofer@ofer.com", "admin");
File toFile = new File("e:/tiers.xml");
RegistryClientUtils.exportFromRegistry( toFile, "/_system/governance/apimgt/applicationdata/tiers.xml" ,remote_registry);
}
}