|
3 | 3 | import com.jfrog.bintray.client.api.BintrayCallException; |
4 | 4 | import com.jfrog.bintray.client.api.MultipleBintrayCallException; |
5 | 5 | import com.jfrog.bintray.client.api.handle.*; |
| 6 | +import com.jfrog.bintray.client.impl.util.URIUtil; |
6 | 7 | import org.apache.commons.io.IOUtils; |
7 | 8 | import org.apache.http.*; |
8 | 9 | import org.apache.http.client.ResponseHandler; |
|
20 | 21 |
|
21 | 22 | import java.io.IOException; |
22 | 23 | import java.io.InputStream; |
23 | | -import java.io.UnsupportedEncodingException; |
24 | | -import java.net.URLEncoder; |
25 | 24 | import java.nio.charset.Charset; |
26 | 25 | import java.util.*; |
27 | 26 | import java.util.concurrent.Callable; |
@@ -111,7 +110,6 @@ public HttpResponse head(String uri, Map<String, String> headers) throws Bintray |
111 | 110 | public HttpResponse sign(String uri, Map<String, String> headers, int fileCount) throws BintrayCallException { |
112 | 111 | HttpPost signRequest = new HttpPost(createUrl(uri)); |
113 | 112 | setHeaders(signRequest, headers); |
114 | | - //Set signRequestTimeoutPerFile * fileCount timeout on request |
115 | 113 | signRequest.setConfig(RequestConfig.custom().setSocketTimeout(signRequestTimeoutPerFile * fileCount) |
116 | 114 | .setConnectionRequestTimeout(signRequestTimeoutPerFile * fileCount) |
117 | 115 | .setConnectTimeout(signRequestTimeoutPerFile * fileCount).build()); |
@@ -218,15 +216,15 @@ private List<RequestRunner> createPutRequestRunners(Map<String, InputStream> uri |
218 | 216 | List<RequestRunner> runners = new ArrayList<>(); |
219 | 217 | List<HttpPut> requests = new ArrayList<>(); |
220 | 218 | log.debug("Creating PUT requests and RequestRunners for execution"); |
221 | | - for (String uri : uriAndStreamMap.keySet()) { |
| 219 | + for (String apiPath : uriAndStreamMap.keySet()) { |
222 | 220 | HttpPut putRequest; |
223 | 221 | try { |
224 | | - putRequest = new HttpPut(createUrl(uri)); |
| 222 | + putRequest = new HttpPut(createUrl(apiPath)); |
225 | 223 | } catch (BintrayCallException bce) { |
226 | 224 | errors.add(bce); |
227 | 225 | continue; |
228 | 226 | } |
229 | | - HttpEntity requestEntity = new InputStreamEntity(uriAndStreamMap.get(uri)); |
| 227 | + HttpEntity requestEntity = new InputStreamEntity(uriAndStreamMap.get(apiPath)); |
230 | 228 | putRequest.setEntity(requestEntity); |
231 | 229 | setHeaders(putRequest, headers); |
232 | 230 | requests.add(putRequest); |
@@ -268,12 +266,12 @@ private void collectResults(List<Future<String>> executions, List<BintrayCallExc |
268 | 266 | } |
269 | 267 | } |
270 | 268 |
|
271 | | - private String createUrl(String uri) throws BintrayCallException { |
| 269 | + private String createUrl(String queryPath) throws BintrayCallException { |
| 270 | + log.debug("Trying to encode uri: '{}' with base url: {}", queryPath, baseUrl); |
272 | 271 | try { |
273 | | - log.debug("Trying to encode uri: {}", uri); |
274 | | - return baseUrl + "/" + URLEncoder.encode(uri, "UTF-8"); |
275 | | - } catch (UnsupportedEncodingException e) { |
276 | | - throw new BintrayCallException(HttpStatus.SC_BAD_REQUEST, "Malformed url, request will not be executed: ", |
| 272 | + return URIUtil.encodeQuery(baseUrl + "/" + queryPath); |
| 273 | + } catch (HttpException e) { |
| 274 | + throw new BintrayCallException(HttpStatus.SC_BAD_REQUEST, "Malformed url, request will not be sent: ", |
277 | 275 | e.getMessage()); |
278 | 276 | } |
279 | 277 | } |
|
0 commit comments