use of org.jfrog.build.client.PreemptiveHttpClient in project build-info by JFrogDev.
the class ArtifactoryDependenciesClient method searchArtifactsByAql.
public AqlSearchResult searchArtifactsByAql(String aql) throws IOException {
PreemptiveHttpClient client = httpClient.getHttpClient();
String url = artifactoryUrl + "/api/search/aql";
HttpPost httpPost = new HttpPost(url);
StringEntity entity = new StringEntity(aql);
httpPost.setEntity(entity);
AqlSearchResult result = readResponse(client.execute(httpPost), new TypeReference<AqlSearchResult>() {
}, "Failed to search artifact by the aql '" + aql + "'", true);
return result;
}
use of org.jfrog.build.client.PreemptiveHttpClient in project build-info by JFrogDev.
the class ArtifactoryDependenciesClient method searchArtifactsByProperties.
public PropertySearchResult searchArtifactsByProperties(String properties) throws IOException {
PreemptiveHttpClient client = httpClient.getHttpClient();
String replacedProperties = StringUtils.replaceEach(properties, new String[] { ";", "+" }, new String[] { "&", "" });
String url = artifactoryUrl + "/api/search/prop?" + replacedProperties;
PropertySearchResult result = readResponse(client.execute(new HttpGet(url)), new TypeReference<PropertySearchResult>() {
}, "Failed to search artifact by the properties '" + properties + "'", false);
return result;
}
use of org.jfrog.build.client.PreemptiveHttpClient in project build-info by JFrogDev.
the class ArtifactoryDependenciesClient method execute.
private HttpResponse execute(String artifactUrl, boolean isHead, Map<String, String> headers) throws IOException {
PreemptiveHttpClient client = httpClient.getHttpClient();
artifactUrl = ArtifactoryHttpClient.encodeUrl(artifactUrl);
HttpRequestBase httpRequest = isHead ? new HttpHead(artifactUrl) : new HttpGet(artifactUrl);
// Explicitly force keep alive
httpRequest.setHeader("Connection", "Keep-Alive");
// Add all required headers to the request
if (headers != null) {
for (Map.Entry<String, String> entry : headers.entrySet()) {
httpRequest.setHeader(entry.getKey(), entry.getValue());
}
}
HttpResponse response = client.execute(httpRequest);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == HttpStatus.SC_NOT_FOUND) {
throw new FileNotFoundException("Unable to find " + artifactUrl);
}
if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_PARTIAL_CONTENT) {
EntityUtils.consume(response.getEntity());
throw new IOException("Error downloading " + artifactUrl + ". Code: " + statusCode + " Message: " + statusLine.getReasonPhrase());
}
return response;
}
use of org.jfrog.build.client.PreemptiveHttpClient in project build-info by JFrogDev.
the class ArtifactoryXrayClient method execute.
private ArtifactoryXrayResponse execute(HttpRequestBase httpRequest) throws InterruptedException, IOException {
PreemptiveHttpClient client = httpClient.getHttpClient(XRAY_SCAN_CONNECTION_TIMEOUT_SECS);
int retryNum = 0;
long lastConnectionAttemptMillis = 0;
HttpResponse response = null;
while (true) {
try {
lastConnectionAttemptMillis = System.currentTimeMillis();
retryNum++;
response = client.execute(httpRequest);
return parseXrayScanResponse(response);
} catch (IOException e) {
if (isStableConnection(lastConnectionAttemptMillis)) {
retryNum = 0;
continue;
}
if (XRAY_SCAN_RETRY_CONSECUTIVE_RETRIES <= retryNum) {
throw e;
}
log.warn("Xray scan connection lost: " + e.getMessage() + ", attempting to reconnect...");
// Sleeping before trying to reconnect.
Thread.sleep(XRAY_SCAN_SLEEP_BETWEEN_RETRIES_MILLIS);
} finally {
if (response != null) {
try {
EntityUtils.consume(response.getEntity());
} catch (IOException e) {
// Ignore
}
}
httpRequest.releaseConnection();
}
}
}
use of org.jfrog.build.client.PreemptiveHttpClient in project build-info by JFrogDev.
the class ArtifactoryDependenciesClient method searchArtifactsByPattern.
public PatternResultFileSet searchArtifactsByPattern(String pattern) throws IOException {
PreemptiveHttpClient client = httpClient.getHttpClient();
String url = artifactoryUrl + "/api/search/pattern?pattern=" + pattern;
PatternResultFileSet result = readResponse(client.execute(new HttpGet(url)), new TypeReference<PatternResultFileSet>() {
}, "Failed to search artifact by the pattern '" + pattern + "'", false);
return result;
}
Aggregations