2014-10-20 40 views
3

在嘗試使用REST API創建新的Sonatype Nexus託管存儲庫時,出現「HTTP/1.1 400錯誤請求」。我正在使用Sonatype Nexus™2.10.0-02,在本地運行。使用REST API創建Sonatype Nexus存儲庫導致HTTP/1.1 400錯誤請求

按照REST API文檔,可在

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負載看起來是這樣的:

<?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> 

和到這裏(我希望)是可以的。

我使用捲曲發佈此XML內容:

curl -i -H "Accept: application/xml" -H "Content-Type: application/xml" -f -X POST -v -d "@$(pwd)/insert_oss_repository.xml" -u admin:admin123 http://localhost:8081/service/local/repositories 

完整的日誌這個命令是這樣的:

* 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> 

首先,我會讀關於XML負載的評論我的POST請求。其次,如果他們花時間創建一種文檔,爲什麼他們不提供一個工作示例?第三,如果他們使這個REST API可用,爲什麼他們不回答人類可讀的答案?

回答

3

它看起來像文檔中可能存在一個錯誤,您還需要提供「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> 

一般來說,最好的辦法適用於Nexus使用和REST是使用JSON有效載荷,這些都是很容易被發現,因爲UI呼籲通過REST層和發送JSON。在這裏看到更多的信息:

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

+0

這是能否成功的關鍵。然後他們應該生成指向強制文件的REST API文檔。謝謝。 – grafl 2014-10-21 17:37:45

+0

還有一件事,那麼存儲庫和all_repositories的GET操作應該生成這個元素。 – grafl 2014-10-21 18:02:55

相關問題