use of org.apache.http.client.methods.HttpHead in project indy by Commonjava.
the class AutoCreateRepoAndRetrieveNoCacheFileTest method run.
@Test
public void run() throws Exception {
final String path = "org/foo/bar/1.0/bar-1.0.nocache";
final String content = "This is a test: " + System.nanoTime();
final String testRepo = "test";
final String url = server.formatUrl(testRepo, path);
server.expect(url, 200, content);
final HttpGet get = new HttpGet(url);
CloseableHttpClient client = proxiedHttp();
CloseableHttpResponse response = null;
InputStream stream = null;
try {
response = client.execute(get, proxyContext(USER, PASS));
stream = response.getEntity().getContent();
final String resultingPom = IOUtils.toString(stream);
assertThat(resultingPom, notNullValue());
assertThat(resultingPom, equalTo(content));
} finally {
IOUtils.closeQuietly(stream);
HttpResources.cleanupResources(get, response, client);
}
final RemoteRepository remoteRepo = this.client.stores().load(new StoreKey(GENERIC_PKG_KEY, StoreType.remote, "httprox_127-0-0-1_" + server.getPort()), RemoteRepository.class);
assertThat(remoteRepo, notNullValue());
assertThat(remoteRepo.getUrl(), equalTo(server.getBaseUri()));
String pomUrl = this.client.content().contentUrl(remoteRepo.getKey(), testRepo, path) + "?cache-only=true";
System.out.println("pomUrl:: " + pomUrl);
HttpHead head = new HttpHead(pomUrl);
client = HttpClients.createDefault();
try {
response = client.execute(head);
assertThat(response.getStatusLine().getStatusCode(), equalTo(404));
} finally {
HttpResources.cleanupResources(head, response, client);
}
}
use of org.apache.http.client.methods.HttpHead in project indy by Commonjava.
the class AutoCreateRepoWithTrackingIdTest method run.
@Test
public void run() throws Exception {
final String testRepo = "test";
final PomRef pom = loadPom("simple.pom", Collections.<String, String>emptyMap());
final String url = server.formatUrl(testRepo, pom.path);
server.expect(url, 200, pom.pom);
final HttpGet get = new HttpGet(url);
CloseableHttpClient client = proxiedHttp(USER, PASS);
CloseableHttpResponse response = null;
InputStream stream = null;
try {
response = client.execute(get, proxyContext(USER, PASS));
stream = response.getEntity().getContent();
final String resultingPom = IOUtils.toString(stream);
assertThat(resultingPom, notNullValue());
assertThat(resultingPom, equalTo(pom.pom));
} finally {
IOUtils.closeQuietly(stream);
HttpResources.cleanupResources(get, response, client);
}
// Remote
String remote = creator.formatId(HOST, 0, 0, TRACKING_ID, StoreType.remote);
final RemoteRepository remoteRepo = this.client.stores().load(new StoreKey(GENERIC_PKG_KEY, StoreType.remote, remote), RemoteRepository.class);
assertThat(remoteRepo, notNullValue());
assertThat(remoteRepo.getUrl(), equalTo(server.getBaseUri()));
assertThat(remoteRepo.isPassthrough(), equalTo(false));
String pomUrl = this.client.content().contentUrl(remoteRepo.getKey(), testRepo, pom.path) + "?cache-only=true";
HttpHead head = new HttpHead(pomUrl);
client = HttpClients.createDefault();
try {
response = client.execute(head);
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
} finally {
HttpResources.cleanupResources(head, response, client);
}
// Hosted
String hosted = creator.formatId(HOST, 0, 0, TRACKING_ID, StoreType.hosted);
final HostedRepository hostedRepo = this.client.stores().load(new StoreKey(GENERIC_PKG_KEY, StoreType.hosted, hosted), HostedRepository.class);
assertThat(hostedRepo, notNullValue());
// Group
final Group group = this.client.stores().load(new StoreKey(GENERIC_PKG_KEY, StoreType.group, creator.formatId(HOST, 0, 0, TRACKING_ID, StoreType.group)), Group.class);
assertThat(group, notNullValue());
List<StoreKey> constituents = group.getConstituents();
assertThat(constituents.contains(remoteRepo.getKey()), equalTo(true));
assertThat(constituents.contains(hostedRepo.getKey()), equalTo(true));
}
use of org.apache.http.client.methods.HttpHead in project indy by Commonjava.
the class ContentBrowseHeadRequestTest method run.
@Test
public void run() {
final String changelog = "Create repo validation test structure";
try {
RemoteRepository mavenCentral = new RemoteRepository("maven", "m-central", REMOTE_MAVEN_CENTRAL_URL);
RemoteRepository npmCentral = new RemoteRepository("npm", "n-central", REMOTE_NPM_CENTRAL_URL);
client.stores().create(mavenCentral, changelog, RemoteRepository.class);
client.stores().create(npmCentral, changelog, RemoteRepository.class);
IndyClientHttp client = getHttp();
HttpHead httpMavenHeadReq = new HttpHead(REMOTE_MAVEN_CENTRAL);
HttpResources mavenResponse = client.execute(httpMavenHeadReq);
assertThat(200, is(mavenResponse.getStatusCode()));
HttpHead httpNpmHeadReq = new HttpHead(REMOTE_NPM_CENTRAL);
HttpResources npmResponse = client.execute(httpNpmHeadReq);
assertThat(200, is(npmResponse.getStatusCode()));
HttpHead httpMavenHeadSubReq = new HttpHead(REMOTE_MAVEN_TEST_SUB_URL);
HttpResources mavenSubResponse = client.execute(httpMavenHeadSubReq);
assertThat(200, is(mavenSubResponse.getStatusCode()));
HttpHead httpNpmHeadSubReq = new HttpHead(REMOTE_NPM_TEST_SUB_URL);
HttpResources npmSubResponse = client.execute(httpNpmHeadSubReq);
assertThat(200, is(npmSubResponse.getStatusCode()));
} catch (IndyClientException e) {
e.printStackTrace();
}
}
use of org.apache.http.client.methods.HttpHead in project indy by Commonjava.
the class IndyClientHttp method newJsonHead.
public HttpHead newJsonHead(final String url) {
final HttpHead req = new HttpHead(url);
addJsonHeaders(req);
return req;
}
use of org.apache.http.client.methods.HttpHead in project gocd by gocd.
the class ServerBinaryDownloader method fetchUpdateCheckHeaders.
void fetchUpdateCheckHeaders(DownloadableFile downloadableFile) throws Exception {
String url = downloadableFile.validatedUrl(urlGenerator);
final HttpRequestBase request = new HttpHead(url);
request.setConfig(RequestConfig.custom().setConnectTimeout(HTTP_TIMEOUT_IN_MILLISECONDS).build());
try (CloseableHttpClient httpClient = httpClientBuilder.build();
CloseableHttpResponse response = httpClient.execute(request)) {
handleInvalidResponse(response, url);
this.md5 = response.getFirstHeader(MD5_HEADER).getValue();
this.extraProperties = HeaderUtil.parseExtraProperties(response.getFirstHeader(AGENT_EXTRA_PROPERTIES_HEADER));
}
}
Aggregations