2012-02-09 24 views
7

Với api documentation này, làm cách nào để sử dụng HTTPBuilder và Groovy để tạo truy vấn của tôi? Tôi đã thử nhiều thứ nhưng tôi không hiểu đúng.Sử dụng REST API của Artifactory để triển khai tệp 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 -> 


    } 

    } 

Điều này dường như giúp tôi có được một phần, nhưng nó tải lên tệp jar trống. Có vẻ như cơ thể hoàn toàn bị bỏ qua. Loại bỏ nó tạo ra kết quả tương tự. Tôi dường như không thể tìm thấy một tài liệu tham khảo tốt về cách này được thực hiện.

Trả lời

13

JSON trong tài liệu được đề cập thực tế là số của Artifactory cho yêu cầu triển khai.
Để triển khai, Artifactroy chỉ yêu cầu một yêu cầu PUT đơn giản, ví dụ:

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

Làm việc này! Cảm ơn bạn! Tài liệu này hơi khó hiểu. Một số người trong số họ nói "đầu ra mẫu" và một số nói "Sử dụng mẫu". Triển khai api đã "sử dụng mẫu" .... mà tôi nghĩ sẽ là làm thế nào để gọi api. – stuff22

Các vấn đề liên quan