Search in sources :

Example 81 with HttpHead

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);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreKey(org.commonjava.indy.model.core.StoreKey) HttpHead(org.apache.http.client.methods.HttpHead) Test(org.junit.Test)

Example 82 with HttpHead

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));
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Group(org.commonjava.indy.model.core.Group) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreKey(org.commonjava.indy.model.core.StoreKey) HttpHead(org.apache.http.client.methods.HttpHead) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test)

Example 83 with HttpHead

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();
    }
}
Also used : IndyClientHttp(org.commonjava.indy.client.core.IndyClientHttp) HttpResources(org.commonjava.indy.client.core.helper.HttpResources) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) IndyClientException(org.commonjava.indy.client.core.IndyClientException) HttpHead(org.apache.http.client.methods.HttpHead) AbstractIndyFunctionalTest(org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest) Test(org.junit.Test)

Example 84 with HttpHead

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;
}
Also used : HttpHead(org.apache.http.client.methods.HttpHead)

Example 85 with HttpHead

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));
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpHead(org.apache.http.client.methods.HttpHead)

Aggregations

HttpHead (org.apache.http.client.methods.HttpHead)104 HttpResponse (org.apache.http.HttpResponse)42 HttpGet (org.apache.http.client.methods.HttpGet)30 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)27 IOException (java.io.IOException)26 HttpPut (org.apache.http.client.methods.HttpPut)24 Test (org.junit.Test)24 HttpPost (org.apache.http.client.methods.HttpPost)23 URI (java.net.URI)22 Header (org.apache.http.Header)21 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)19 HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)16 HttpDelete (org.apache.http.client.methods.HttpDelete)14 InputStream (java.io.InputStream)13 HttpEntity (org.apache.http.HttpEntity)11 File (java.io.File)9 HttpOptions (org.apache.http.client.methods.HttpOptions)9 StringEntity (org.apache.http.entity.StringEntity)9 HttpPatch (org.apache.http.client.methods.HttpPatch)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6