I have a set of requirements that require a Jersey/JAX-RS client to publish ZIP files to repos living on Artifactory. Specifically, I need to publish ZIPs to:
http://artifactory01.example.org/artifactory/simple/libs-release-local/ourorg/somelib/1.0.0/
It looks like Artifactory exposes a PUT endpoint :
PUT /libs-release-local/my/jar/1.0/jar-1.0.jar {
"uri": "http://localhost:8080/artifactory/libs-release-local/my/jar/1.0/jar-1.0.jar",
"downloadUri": "http://localhost:8080/artifactory/libs-release-local/my/jar/1.0/jar-1.0.jar",
"repo": "libs-release-local",
"path": "/my/jar/1.0/jar-1.0.jar",
"created": ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ),
"createdBy": "userY",
"size": "1024", //bytes
"mimeType": "application/java-archive",
"checksums": {
"md5" : string,
"sha1" : string
},
"originalChecksums": {
"md5" : string,
"sha1" : string
}
}
Hence it looks like I need to PUT somelib-1.0.0.zip
to the URL I identified above. My proposal to do this is as follows:
// Groovy pseudo-code for the PUT entity:
class Publication {
@JsonProperty
String uri
@JsonProperty
String downloadUri
@JsonProperty
String repo
@JsonProperty
String path
@JsonProperty
Date created
@JsonProperty
String createdBy
@JsonProperty
Integer size
@JsonProperty
String mimeType
@JsonProperty
Map<String,String> checksums
@JsonProperty
Map<String,String> originalChecksums
}
However, 2 problems:
The security constraint on this endpoint requires a user with 'deploy' permissions. I have such a user, however I'm not sure how to implement this auth on the client-side. Does Artifactory use basic auth for its endpoints? If so, would something like this work (?):
Client client = Client.create();
WebResource resource = client.resource(BASE_URI);
client.addFilter(new HTTPBasicAuthFilter("deployuser", "12345")); // dummy credentials, obviously
Most importantly , I'm not understanding what the PUT
entity should be. Using Jersey/JAX-RS style POJOs, I might do something like:
// Again, Groovy pseudo-code
Publication publication = getSomehow() // Ideally ZIP is read into portable format by this point
webResource.path("libs-release-local").path("ourorg").path("somelib").path("1.0.0").path("somelib-1.0.0.zip")
.type(MediaType.???).entity(publication).put(???)
However, I still don't see how/where I send the actual ZIP file. There is the path
field, which seems to specify the local (client-side) path to the binary, but that's just a string/reference, not the actual binary to publish!
Also, according to Wikipedia, ZIP media type is application\\zip
, but there is no such MediaType
defined in JAX-RS.
Any ideas here?
Basic Auth is good. Re the entity, you don't need any. The JSON you see in the docs is the result of the PUT call.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.