Sonatype Nexus添加代理存储库与REST API



我正在尝试使用REST API和curl向本地Sonatype Nexus™OSS 2.8.1-01添加代理存储库,但它不起作用

curl命令:

 curl -i -H "Accept: application/xml" -H "Content-Type: application/xml" -f -X POST  -v -d "@/tmp/input.xml" -u
 "admin:admin123" "http://localhost:8081/nexus/service/local/repositories"
当我添加在input.xml中定义的托管存储库,但不添加代理存储库

时,它可以正常工作。使用代理存储库,我将得到以下响应:
 upload completely sent off: 445 out of 445 bytes
 The requested URL returned error: 400 Bad Request
 Closing connection 0

Nexus日志文件:

2014-08-12 09:57:44,189+0200 TRACE [qtp531741605-42] admin com.thoughtworks.xstream.whitelist.TypeWhitelist - All types allowed: remoteUri
2014-08-12 09:57:44,201+0200 WARN  [qtp531741605-42] admin org.sonatype.nexus.rest.NexusRestletResource - Invalid XML, unable to parse using XStream class org.sonatype.nexus.rest.repositories.RepositoryListPlexusResource
com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$UnknownFieldException: No such field org.sonatype.nexus.rest.model.RepositoryProxyResource.remoteUri
---- Debugging information ----
field               : remoteUri
class               : org.sonatype.nexus.rest.model.RepositoryBaseResource
required-type       : org.sonatype.nexus.rest.model.RepositoryBaseResource
converter-type      : org.sonatype.nexus.rest.repositories.RepositoryBaseResourceConverter
path                : /repository/data/remoteUri
line number         : 1
class[1]            : org.sonatype.nexus.rest.model.RepositoryResourceResponse
converter-type[1]   : org.sonatype.nexus.rest.repositories.RepositoryResourceResponseConverter
version             : 1.4.6-SONATYPE-03

他将remotUri识别为未知字段,但它是配置新代理存储库所需的字段

input.xml:

<?xml version="1.0" encoding="UTF-8"?>
<repository>
  <data>
    <id>maven.jenkins-ci.org</id>
    <name>Jenkins CI</name>
    <repoType>proxy</repoType>
    <repoPolicy>RELEASE</repoPolicy>
    <provider>maven2</provider>
    <providerRole>org.sonatype.nexus.proxy.repository.Repository</providerRole>
    <format>maven2</format>
    <exposed>true</exposed>
    <remoteUri>http://repo.jenkins-ci.org/public/</remoteUri>
  </data>
</repository>

为防止出现type not allowed错误,我放了

com.thoughtworks.xstream.whitelist.TypeWhitelist.allowAll=true
属性 中的

我做错了什么?希望有人能帮助我

把亚历克斯

我建议使用JSON而不是XML作为有效负载类型。如果您这样做,您可以在创建存储库时仅观察从UI到服务器的HTTP流量,UI会发出所需的REST API调用。

查看更多信息:

http://blog.sonatype.com/2012/07/learning-the-nexus-rest-api-read-the-docs-or-fire-up-a-browser

最新更新