public static Registry getRegistry() {
Registry governanceRegistry = null;
String url = "https://localhost:9443/registry";
String username = "admin";
String password = "admin";
System.setProperty("carbon.repo.write.mode", "true");
try {
RemoteRegistry rootRegistry = new RemoteRegistry(new URL(url), username,
password);
governanceRegistry = GovernanceUtils.getGovernanceUserRegistry(
rootRegistry, username);
} catch (RegistryException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
}
return governanceRegistry;
}
public static void main(String[] args) {
try {
Registry registry = WSRegistryClient.getRegistry();
GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry);
GenericArtifactManager artifactManager = new GenericArtifactManager(
registry, "endpoint");
GenericArtifact artifact = artifactManager
.newGovernanceArtifact(new QName("http://www.example.com/", "endpoint_1"));
artifact.setAttribute("Name", "endpoint");
artifact.setAttribute("Version", "1.0.0");
artifact.setAttribute("Address", "http://www.google.com");
artifactManager.addGenericArtifact(artifact);
} catch (Exception e) {
e.printStackTrace();
}
}
<artifactType type="application/vnd.wso2-endpoint+xml" shortName="endpoint" singularLabel="Endpoint"
pluralLabel="Endpoints" hasNamespace="false" iconSet="2">
<storagePath>/trunk/endpoints/@{overview_name}</storagePath>
<nameAttribute>overview_name</nameAttribute>
<lifecycle>EndpointLifeCycle</lifecycle>
<ui>
<list>
<column name="Name">
<data type="path" value="overview_name" href="@{storagePath}"/>
</column>
<column name="Version">
<data type="path" value="overview_version" href="@{storagePath}"/>
</column>
</list>
</ui>
<content>
<table name="Overview">
<field type="text" required="true" readonly="true">
<name>Name</name>
</field>
<field type="text" required="true">
<name>Version</name>
</field>
<field type="text" required="true">
<name>Address</name>
</field>
<field type="text">
<name>Environment</name>
</field>
</table>
</content>
</artifactType>
org.wso2.carbon.governance.api.exception.GovernanceException: Version is a required field, Please provide a value for this parameter.
at org.wso2.carbon.governance.api.common.GovernanceArtifactManager.validateArtifact(GovernanceArtifactManager.java:940)
at org.wso2.carbon.governance.api.common.GovernanceArtifactManager.addGovernanceArtifact(GovernanceArtifactManager.java:184)
at org.wso2.carbon.governance.api.generic.GenericArtifactManager.addGenericArtifact(GenericArtifactManager.java:217)
at cn.oge.kkm.alg.template.AlgTemplateHandler.put(AlgTemplateHandler.java:66)
at org.wso2.carbon.registry.core.jdbc.handlers.HandlerManager.put(HandlerManager.java:2503)
at org.wso2.carbon.registry.core.jdbc.handlers.HandlerLifecycleManager.put(HandlerLifecycleManager.java:945)
at org.wso2.carbon.registry.core.jdbc.EmbeddedRegistry.put(EmbeddedRegistry.java:697)
at org.wso2.carbon.registry.core.caching.CacheBackedRegistry.put(CacheBackedRegistry.java:550)
at org.wso2.carbon.registry.core.session.UserRegistry.putInternal(UserRegistry.java:827)
at org.wso2.carbon.registry.core.session.UserRegistry.access$1000(UserRegistry.java:60)
at org.wso2.carbon.registry.core.session.UserRegistry$11.run(UserRegistry.java:803)
at org.wso2.carbon.registry.core.session.UserRegistry$11.run(UserRegistry.java:800)
at java.security.AccessController.doPrivileged(Native Method)
at org.wso2.carbon.registry.core.session.UserRegistry.put(UserRegistry.java:800)
at org.wso2.carbon.registry.resource.services.utils.AddResourceUtil.addResource(AddResourceUtil.java:88)
at org.wso2.carbon.registry.resource.services.ResourceService.addResource(ResourceService.java:292)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:212)
答案 0 :(得分:0)
通过查看你的代码,我认为你犯了一个小错误。请更改以下代码
artifact.setAttribute("overview_name", "endpoint");
artifact.setAttribute("overview_version", "1.0.0");
artifact.setAttribute("overview_address", "http://www.google.com");
除了不使用快照版本之外,请尽可能使用发行版本。
有一种更简单的方法,您可以使用Governance REST API添加工件。