7

鉴于此 api文档,我将如何使用 HTTPBuilder 和 Groovy 来构建我的查询?我已经尝试了很多事情,但我没有做对。

def http = new HTTPBuilder()
http.request('http://artifactory:8888/libs-snapshot-local/my/jar/1.0/test-jar-1.0.jar', PUT, JSON ) { req ->

        body = [
            uri: "http://artifactory:8888/libs-snapshot-local/my/jar/1.0/test-jar-1.0.jar",
            downloadUri: "http://artifactory:8888/libs-snapshot-local/my/jar/1.0/test-jar-1.0.jar",
            repo: "libs-snapshot-local",
            path: "c:\\pathtojarfile\\test.jar",
            created: "2012-02-03T08:37:12.599-0800",
            createdBy: "someuser",
            size: "1024",
            mimeType: "application/java-archive"

        ]

    response.success = { resp, json ->


    }

  }

这似乎让我走到了那里,但它上传了一个空的 jar 文件。似乎身体被完全忽略了。删除它会产生相同的结果。我似乎无法找到有关如何完成此操作的良好参考。

4

1 回答 1

14

上述文档中的 JSON 实际上是 Artifactory对部署请求的响应。
对于部署,Artifactroy 只需要一个简单的 PUT 请求,例如:

def restClient = new RESTClient('http://localhost:8080/artifactory/libs-release-local/')
restClient.auth.basic 'username', 'password'
restClient.encoder.'application/zip' = this.&encodeZipFile
def encodeZipFile(Object data) throws UnsupportedEncodingException {
    def entity = new FileEntity((File) data, 'application/zip');
    entity.setContentType('application/zip');
    return entity
}
def response = restClient.put(path: 'org/artifact/1.0/artifact-1.0.jar',
      body: new File('/path/to/local/artifact.jar'),
      requestContentType: 'application/zip'
) 
于 2012-02-10T07:51:42.423 回答