使用RESTAPI创建Sonatype Nexus存储库会导致HTTP/1.1 400错误请求
在尝试使用RESTAPI创建新的Sonatype Nexus托管存储库时,我得到了一个“HTTP/1.1 400错误请求”。我使用的是Sonatype Nexus™ 2.10.0-02,本地运行 根据RESTAPI文档,可在使用RESTAPI创建Sonatype Nexus存储库会导致HTTP/1.1 400错误请求,rest,post,repository,nexus,sonatype,Rest,Post,Repository,Nexus,Sonatype,在尝试使用RESTAPI创建新的Sonatype Nexus托管存储库时,我得到了一个“HTTP/1.1 400错误请求”。我使用的是Sonatype Nexus™ 2.10.0-02,本地运行 根据RESTAPI文档,可在 http://localhost:8081/nexus/nexus-restlet1x-plugin/default/docs/path__repositories.html 要创建新存储库,POST请求必须如下所示: <?xml version="1.0" enc
http://localhost:8081/nexus/nexus-restlet1x-plugin/default/docs/path__repositories.html
要创建新存储库,POST请求必须如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<repository>
<data>
<format>...</format>
<providerRole>...</providerRole>
<exposed>...</exposed>
<id>...</id>
<name>...</name>
<contentResourceURI>...</contentResourceURI>
<repoType>...</repoType>
<provider>...</provider>
</data>
</repository>
<?xml version="1.0" encoding="UTF-8"?>
<repository>
<data>
<format>maven2</format>
<providerRole>org.sonatype.nexus.proxy.repository.Repository</providerRole>
<exposed>true</exposed>
<id>my-releases</id>
<name>MyReleases</name>
<contentResourceURI>http://localhost:8081/nexus/content/repositories/my-releases</contentResourceURI>
<repoType>hosted</repoType>
<provider>maven2</provider>
</data>
</repository>
此命令的完整日志如下所示:
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8081 (#0)
* Server auth using Basic with user 'admin'
> POST /nexus/service/local/repositories HTTP/1.1
> Authorization: Basic YWRtaW46YWRtaW4xMjM=
> User-Agent: curl/7.35.0
> Host: localhost:8081
> Accept: */*
> Content-Type:application/xml
> Content-Length: 327
>
* upload completely sent off: 327 out of 327 bytes
< HTTP/1.1 400 Bad Request
< Date: Mon, 20 Oct 2014 19:19:21 GMT
* Server Nexus/2.10.0-02 is not blacklisted
< Server: Nexus/2.10.0-02
< X-Frame-Options: SAMEORIGIN
< X-Content-Type-Options: nosniff
< Set-Cookie: rememberMe=deleteMe; Path=/nexus; Max-Age=0; Expires=Sun, 19-Oct-2014 19:19:21 GMT
< Content-Type: application/xml; charset=UTF-8
< Date: Mon, 20 Oct 2014 19:19:21 GMT
* Server Noelios-Restlet-Engine/1.1.6-SONATYPE-5348-V8 is not blacklisted
< Server: Noelios-Restlet-Engine/1.1.6-SONATYPE-5348-V8
< Content-Length: 183
<
<nexus-error>
<errors>
<error>
<id>*</id>
<msg>No enum const class org.sonatype.nexus.proxy.maven.RepositoryPolicy.null</msg>
</error>
</errors>
* Connection #0 to host localhost left intact
</nexus-error>
在DNS缓存中找不到主机名
*正在尝试127.0.0.1。。。
*已连接到本地主机(127.0.0.1)端口8081(#0)
*使用用户“admin”的Basic进行服务器身份验证
>POST/nexus/service/local/repositories HTTP/1.1
>授权:基本YWRtaW46YWRtaW4xMjM=
>用户代理:curl/7.35.0
>主机:本地主机:8081
>接受:*/*
>内容类型:application/xml
>内容长度:327
>
*上传已完全发送:327字节中的327字节
首先,我将阅读您关于我的POST请求的XML负载的评论。其次,如果他们花时间创建一种文档,为什么不提供一个工作示例呢?第三,如果他们提供了这个RESTAPI,为什么他们不以一个人类可读的答案来响应呢?看起来文档中可能有一个bug,您还需要提供“repoPolicy”元素。下面是一个有效负载示例:
<repository>
<data>
<id>my-releases-xml</id>
<name>MyReleasesXml</name>
<exposed>true</exposed>
<repoType>hosted</repoType>
<repoPolicy>RELEASE</repoPolicy>
<providerRole>org.sonatype.nexus.proxy.repository.Repository</providerRole>
<provider>maven2</provider>
<format>maven2</format>
</data>
</repository>
我的博客发布了xml
MyReleasesXml
真的
主持
释放
org.sonatype.nexus.proxy.repository.repository
马文2
马文2
通常,与Nexus和REST一起使用的最佳方法是使用JSON有效负载,这些负载很容易发现,因为UI通过REST层调用并发送JSON。有关更多信息,请参见此处:
这是成功的关键。然后,他们应该生成RESTAPI文档,指出必需的文件。谢谢。还有一件事,那么存储库和所有_存储库的GET操作应该生成这个元素。
<repository>
<data>
<id>my-releases-xml</id>
<name>MyReleasesXml</name>
<exposed>true</exposed>
<repoType>hosted</repoType>
<repoPolicy>RELEASE</repoPolicy>
<providerRole>org.sonatype.nexus.proxy.repository.Repository</providerRole>
<provider>maven2</provider>
<format>maven2</format>
</data>
</repository>