Search in sources :

Example 16 with SimpleHttpLocation

use of org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation in project galley by Commonjava.

the class HttpListTest method simpleNexusListing_Missing.

@Test
public void simpleNexusListing_Missing() throws Exception {
    final String dir = "nexus-missing/";
    final String fname = dir + "index.html";
    final String listingFname = dir + ".listing.txt";
    final String url = fixture.formatUrl(fname);
    final SimpleHttpLocation location = new SimpleHttpLocation("test", url, true, true, true, true, null);
    final Transfer transfer = fixture.getTransfer(new ConcreteResource(location, listingFname));
    final HttpListing listing = new HttpListing(url, new ConcreteResource(location, fname), fixture.getHttp());
    final ListingResult result = listing.call();
    assertThat(listing.getError(), nullValue());
    assertThat(result, nullValue());
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ListingResult(org.commonjava.maven.galley.model.ListingResult) Test(org.junit.Test)

Example 17 with SimpleHttpLocation

use of org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation in project galley by Commonjava.

the class HttpListTest method simpleNexusListing_Error.

@Test
public void simpleNexusListing_Error() throws Exception {
    final String dir = "nexus-error/";
    final String fname = dir + "index.html";
    final String listingFname = dir + ".listing.txt";
    final String url = fixture.formatUrl(fname);
    final SimpleHttpLocation location = new SimpleHttpLocation("test", url, true, true, true, true, null);
    fixture.registerException(fixture.getUrlPath(url), "Test Error");
    final Transfer transfer = fixture.getTransfer(new ConcreteResource(location, listingFname));
    final HttpListing listing = new HttpListing(url, new ConcreteResource(location, fname), fixture.getHttp());
    final ListingResult result = listing.call();
    assertThat(result, nullValue());
    assertThat(listing.getError(), notNullValue());
    assertTrue(listing.getError().getMessage().contains("Test Error"));
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ListingResult(org.commonjava.maven.galley.model.ListingResult) Test(org.junit.Test)

Example 18 with SimpleHttpLocation

use of org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation in project pom-manipulation-ext by release-engineering.

the class MavenLocationExpander method addRequestRepositoriesTo.

private void addRequestRepositoriesTo(final Set<Location> locs, final List<ArtifactRepository> artifactRepositories, final Settings settings, final MirrorSelector mirrorSelector) throws MalformedURLException {
    if (artifactRepositories != null) {
        for (final ArtifactRepository repo : artifactRepositories) {
            // TODO: Authentication via memory password manager.
            String id = repo.getId();
            String url = repo.getUrl();
            if (url.startsWith("file:")) {
                locs.add(new SimpleLocation(id, url));
            } else {
                final List<Mirror> mirrors = settings.getMirrors();
                if (mirrors != null) {
                    final Mirror mirror = mirrorSelector == null ? null : mirrorSelector.getMirror(repo, mirrors);
                    if (mirror != null) {
                        id = mirror.getId();
                        url = mirror.getUrl();
                    }
                }
                final ArtifactRepositoryPolicy releases = repo.getReleases();
                final ArtifactRepositoryPolicy snapshots = repo.getSnapshots();
                SimpleHttpLocation addition = new SimpleHttpLocation(id, url, snapshots != null && snapshots.isEnabled(), releases == null || releases.isEnabled(), true, false, null);
                addition.setAttribute(Location.CONNECTION_TIMEOUT_SECONDS, 60);
                locs.add(addition);
            }
        }
    }
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) Mirror(org.apache.maven.settings.Mirror)

Example 19 with SimpleHttpLocation

use of org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation in project galley by Commonjava.

the class HttpDownloadTest method simpleRetrieveOfUrlWithError.

@Test
public void simpleRetrieveOfUrlWithError() throws Exception {
    final String fname = "simple-error.html";
    final String baseUri = fixture.getBaseUri();
    final SimpleHttpLocation location = new SimpleHttpLocation("test", baseUri, true, true, true, true, null);
    final Transfer transfer = fixture.getTransfer(new ConcreteResource(location, fname));
    final String url = fixture.formatUrl(fname);
    final String error = "Test Error.";
    final String path = fixture.getUrlPath(url);
    fixture.registerException(path, error);
    Map<Transfer, Long> transferSizes = new HashMap<Transfer, Long>();
    assertThat(transfer.exists(), equalTo(false));
    final HttpDownload dl = new HttpDownload(url, location, transfer, transferSizes, new EventMetadata(), fixture.getHttp(), new ObjectMapper());
    final DownloadJob resultJob = dl.call();
    final TransferException err = dl.getError();
    assertThat(err, notNullValue());
    assertThat(err.getMessage().contains(error), equalTo(true));
    assertThat(resultJob, notNullValue());
    final Transfer result = resultJob.getTransfer();
    assertThat(result, notNullValue());
    assertThat(transfer.exists(), equalTo(false));
    assertThat(fixture.getAccessesFor(path), equalTo(1));
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) TransferException(org.commonjava.maven.galley.TransferException) HashMap(java.util.HashMap) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) DownloadJob(org.commonjava.maven.galley.spi.transport.DownloadJob) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 20 with SimpleHttpLocation

use of org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation in project galley by Commonjava.

the class HttpDownloadTest method simpleRetrieveOfMissingUrl.

@Test
public void simpleRetrieveOfMissingUrl() throws Exception {
    final String fname = "simple-missing.html";
    final String baseUri = fixture.getBaseUri();
    final SimpleHttpLocation location = new SimpleHttpLocation("test", baseUri, true, true, true, true, null);
    final Transfer transfer = fixture.getTransfer(new ConcreteResource(location, fname));
    final String url = fixture.formatUrl(fname);
    Map<Transfer, Long> transferSizes = new HashMap<Transfer, Long>();
    assertThat(transfer.exists(), equalTo(false));
    final HttpDownload dl = new HttpDownload(url, location, transfer, transferSizes, new EventMetadata(), fixture.getHttp(), new ObjectMapper());
    final DownloadJob resultJob = dl.call();
    final TransferException error = dl.getError();
    assertThat(error, nullValue());
    assertThat(resultJob, notNullValue());
    final Transfer result = resultJob.getTransfer();
    assertThat(result, notNullValue());
    assertThat(result.exists(), equalTo(false));
    assertThat(transfer.exists(), equalTo(false));
    final String path = fixture.getUrlPath(url);
    assertThat(fixture.getAccessesFor(path), equalTo(1));
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) TransferException(org.commonjava.maven.galley.TransferException) HashMap(java.util.HashMap) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) DownloadJob(org.commonjava.maven.galley.spi.transport.DownloadJob) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Aggregations

SimpleHttpLocation (org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation)24 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)22 Test (org.junit.Test)21 Transfer (org.commonjava.maven.galley.model.Transfer)19 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)10 TransferException (org.commonjava.maven.galley.TransferException)9 ListingResult (org.commonjava.maven.galley.model.ListingResult)7 HashMap (java.util.HashMap)6 DownloadJob (org.commonjava.maven.galley.spi.transport.DownloadJob)6 IOException (java.io.IOException)3 ServletException (javax.servlet.ServletException)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 ExpectationHandler (org.commonjava.test.http.expect.ExpectationHandler)3 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 PrintWriter (java.io.PrintWriter)2 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)2 ArtifactRepositoryPolicy (org.apache.maven.artifact.repository.ArtifactRepositoryPolicy)2