Reputation: 21
I'm trying to add a proxy repository to my local Sonatype Nexus™ OSS 2.8.1-01 using the REST API and curl, but it doesn't work
curl command:
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"
till there it works fine, when I'll add a hosted repository defined in the input.xml, but not with a proxy repository
with a proxy repository I'll get following response:
upload completely sent off: 445 out of 445 bytes
The requested URL returned error: 400 Bad Request
Closing connection 0
Nexus logfile:
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
He recognizes remotUri as a unknown field, but it is a required field for configure a new proxy repository
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>
to prevent a type not allowd error I put
com.thoughtworks.xstream.whitelist.TypeWhitelist.allowAll=true
in the nexus.properties
What am I doing wrong? Hope someone can help me
regards Alex
Upvotes: 2
Views: 2359
Reputation: 5328
I'd suggest using JSON rather than XML as the payload type. If you do this you can just watch the HTTP traffic from the UI to the server when creating the repository, the UI makes the REST API call you need.
See here for more information:
http://blog.sonatype.com/2012/07/learning-the-nexus-rest-api-read-the-docs-or-fire-up-a-browser
Upvotes: 2