Skip to content

Commit 6642290

Browse files
author
danf
committed
Add generic HTTP methods to Bintray interface
1 parent bea7012 commit 6642290

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

api/src/main/java/com/jfrog/bintray/client/api/handle/Bintray.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
package com.jfrog.bintray.client.api.handle;
22

3+
import com.jfrog.bintray.client.api.BintrayCallException;
4+
import com.jfrog.bintray.client.api.MultipleBintrayCallException;
5+
import org.apache.http.HttpResponse;
6+
37
import java.io.Closeable;
8+
import java.io.InputStream;
9+
import java.util.Map;
410

511
/**
612
* @author Noam Y. Tenne
@@ -15,8 +21,32 @@ public interface Bintray extends Closeable {
1521

1622
VersionHandle version(String versionPath);
1723

24+
/**
25+
* Following are generic HTTP requests you can perform against Bintray's API, as defined in your created client
26+
* (so the uri parameter should be the required path after api.bintray.com).
27+
* You can also optionally add your own headers to the requests.
28+
*/
29+
30+
HttpResponse get(String uri, Map<String, String> headers) throws BintrayCallException;
31+
32+
HttpResponse head(String uri, Map<String, String> headers) throws BintrayCallException;
33+
34+
HttpResponse post(String uri, Map<String, String> headers, InputStream elementInputStream) throws BintrayCallException;
35+
36+
HttpResponse patch(String uri, Map<String, String> headers, InputStream elementInputStream) throws BintrayCallException;
37+
38+
HttpResponse delete(String uri, Map<String, String> headers) throws BintrayCallException;
39+
40+
/**
41+
* PUT single item
42+
*/
43+
HttpResponse put(String uri, Map<String, String> headers, InputStream elementInputStream) throws BintrayCallException;
44+
45+
/**
46+
* PUT multiple items, executes requests concurrently.
47+
*/
48+
HttpResponse put(Map<String, InputStream> uriAndStreamMap, Map<String, String> headers) throws MultipleBintrayCallException;
49+
1850
@Override
1951
void close();
20-
21-
// Search search();
2252
}

impl/src/main/java/com/jfrog/bintray/client/impl/handle/BintrayImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ private HttpResponse setHeadersAndExecute(HttpUriRequest request, Map<String, St
276276
}
277277

278278
private HttpResponse execute(HttpUriRequest request, HttpClientContext context) throws BintrayCallException {
279+
log.debug("Executing {} request to path '{}', with headers: {}", request.getMethod(), request.getURI(),
280+
Arrays.toString(request.getAllHeaders()));
279281
try {
280282
if (context != null) {
281283
return client.execute(request, responseHandler, context);
@@ -312,6 +314,8 @@ public RequestRunner(HttpRequestBase request, CloseableHttpClient client, Respon
312314

313315
@Override
314316
public String call() throws BintrayCallException {
317+
log.debug("Executing {} request to path '{}', with headers: {}", request.getMethod(), request.getURI(),
318+
Arrays.toString(request.getAllHeaders()));
315319
StringBuilder errorResultBuilder;
316320
if (request instanceof HttpPut) {
317321
String pushPath = request.getURI().getPath().substring(9); //Substring cuts the '/content/' part from the URI
@@ -329,7 +333,7 @@ public String call() throws BintrayCallException {
329333
bce.setMessage(errorResultBuilder.toString());
330334
throw bce;
331335
} catch (IOException ioe) {
332-
log.debug("IOException occured: '{}'", ioe.getMessage(), ioe);
336+
log.debug("IOException occurred: '{}'", ioe.getMessage(), ioe);
333337
String cause = (ioe.getCause() != null) ? (", caused by: " + ioe.getCause().toString() + " : "
334338
+ ioe.getCause().getMessage()) : "";
335339
errorResultBuilder.append(ioe.toString()).append(" : ").append(ioe.getMessage()).append(cause);

0 commit comments

Comments
 (0)