Finally got the request to work. For others reading this, it's important to not copy an artifact that already exist in the repository you are trying to copy the artifact to. The response code is not giving any clues that this is the actual problem. Would be good if there was a better response code for this.
The next problem, and weird behavior is that the rest service copyArtifact is not fixing the metadata for the new files. Something I expected it to do. I guess this is a bug. So to fix the metadata you actually have to run scanRepositoryDirectoriesNow ... before you can use the artifact with for example mvn versions:use-latest-versions. If your repository is large, like for example 200gig then scanRepositoryDirectoriesNow takes more than 60mins. This leads to not being able to use the artifact until the directory have been scanned. Really bad. Suggestions to fix this is to either fix a rest request where its possible to scan a specific artifact and fix for example the metadata, checksum or whatever stuff you want to fix with the consumers. Would be really handy. Another solution is if the copyArtifact does this, something I expected it to do. Regards Anders On Mon, 4 Nov 2019 at 10:35, Anders Nyström <an...@thermocalc.se> wrote: > Hi Olivier, > > I did not get your reply for some reason on mail, but saw it here > http://mail-archives.apache.org/mod_mbox/archiva-users/201911.mbox/browser. > > > I can't see any trace of it in the logs. The logs is completely empty for > this request. > > Regards Anders > > On Fri, 1 Nov 2019 at 09:10, Anders Nyström <an...@thermocalc.se> wrote: > >> Hi, >> >> I am trying to use the rest service copyArtifact, but I can't get it to >> work. Feels like I have tried everything. I am trying to do this with >> groovy and this is how my code looks at the moment. The info in >> artifactTransferRequest is from the response of searchArtifacts >> >> def copyArtifact() { >> def baseUrl = "..." >> def request = new RESTClient(baseUrl + "/restServices/archivaServices/") >> request.headers['Authorization'] = "Basic " + >> ("username:pass".bytes.encodeBase64().toString()) >> request.handler.failure = { response -> >> println "Unexpected failure: ${response.status}" >> } >> def copyArtifactResponse = request.post( >> path: "repositoriesService/copyArtifact", >> contentType: JSON, >> requestContentType: XML, >> body: { >> artifactTransferRequest { >> targetRepositoryId "tagged-releases" >> packaging "dll" >> fileExtension "dll" >> type "dll" >> artifactId "bla4" >> groupId "se..." >> version "2020.1" >> repositoryId "release" >> context "release" >> url "..." >> } >> } >> ) >> >> println "Status: " + copyArtifactResponse.status >> if (copyArtifactResponse.data) { >> println("Content Type: " + copyArtifactResponse.contentType) >> println("Headers: " + copyArtifactResponse.getAllHeaders()) >> println("Body:\n" + >> JsonOutput.prettyPrint(JsonOutput.toJson(copyArtifactResponse.data))) >> } >> } >> >> >> Here is the response I get: >> Unexpected failure: 500 >> Caught: java.lang.NullPointerException: Cannot get property 'status' on >> null object >> java.lang.NullPointerException: Cannot get property 'status' on null >> object >> >> Regards >> Anders >> >