2012-02-09 4 views
7

이 API가 documentation 인 경우 HTTPBuilder와 Groovy를 사용하여 쿼리를 구성하는 방법은 무엇입니까? 나는 여러 가지를 시도했지만 올바르게 못하고있다.Artifactory의 REST API를 사용하여 jar 파일을 배포

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 파일을 업로드합니다. 시체가 완전히 무시 된 것 같습니다. 제거하면 동일한 결과가 생성됩니다. 이것이 어떻게 행해지는지에 대한 좋은 참고 자료를 찾을 수없는 것 같습니다.

답변

13

언급 된 설명서의 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' 
) 
+0

이 일! 고맙습니다! 설명서가 약간 혼란 스럽습니다. 그들 중 일부는 "샘플 출력"이라고 말하면서 "샘플 사용"이라고 말합니다. 배포 API는 "샘플 사용"을 가지고있었습니다 ... 나는 API 호출 방법이 될 것이라고 생각했습니다. – stuff22

관련 문제