Search in sources :

Example 6 with SimpleHttpLocation

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

the class HttpDownloadTest method simpleRetriveOfRedirectUrl.

@Test
public void simpleRetriveOfRedirectUrl() throws Exception {
    final String content = "This is some content " + System.currentTimeMillis() + "." + System.nanoTime();
    final String redirectPath = "/path/to/file";
    final String path = "/redirect/to/file";
    fixture.getServer().expect("GET", fixture.formatUrl(path), new ExpectationHandler() {

        @Override
        public void handle(final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse) throws ServletException, IOException {
            httpServletResponse.setStatus(302);
            httpServletResponse.setHeader("Location", fixture.formatUrl(redirectPath));
        }
    });
    fixture.getServer().expect("GET", fixture.formatUrl(redirectPath), 200, content);
    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, path));
    final String url = fixture.formatUrl(path);
    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(true));
    assertThat(transfer.exists(), equalTo(true));
    final String postPath = fixture.getUrlPath(url);
    assertThat(fixture.getAccessesFor(postPath), equalTo(1));
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) HashMap(java.util.HashMap) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) DownloadJob(org.commonjava.maven.galley.spi.transport.DownloadJob) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) TransferException(org.commonjava.maven.galley.TransferException) ExpectationHandler(org.commonjava.test.http.expect.ExpectationHandler) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 7 with SimpleHttpLocation

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

the class MavenLocationExpander method addSettingsProfileRepositoriesTo.

private void addSettingsProfileRepositoriesTo(final Set<Location> locs, final Settings settings, final List<String> activeProfiles, final MirrorSelector mirrorSelector) throws MalformedURLException {
    if (settings != null) {
        final Map<String, Profile> profiles = settings.getProfilesAsMap();
        if (profiles != null && activeProfiles != null && !activeProfiles.isEmpty()) {
            final LinkedHashSet<String> active = new LinkedHashSet<>(activeProfiles);
            final List<String> settingsActiveProfiles = settings.getActiveProfiles();
            if (settingsActiveProfiles != null && !settingsActiveProfiles.isEmpty()) {
                active.addAll(settingsActiveProfiles);
            }
            for (final String profileId : active) {
                final Profile profile = profiles.get(profileId);
                if (profile != null) {
                    final List<Repository> repositories = profile.getRepositories();
                    if (repositories != null) {
                        final List<Mirror> mirrors = settings.getMirrors();
                        final ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();
                        for (final Repository repo : repositories) {
                            String id = repo.getId();
                            String url = repo.getUrl();
                            if (mirrors != null) {
                                final ArtifactRepositoryPolicy snapshots = convertPolicy(repo.getSnapshots());
                                final ArtifactRepositoryPolicy releases = convertPolicy(repo.getReleases());
                                final MavenArtifactRepository arepo = new MavenArtifactRepository(id, url, layout, snapshots, releases);
                                final Mirror mirror = mirrorSelector == null ? null : mirrorSelector.getMirror(arepo, mirrors);
                                if (mirror != null) {
                                    id = mirror.getId();
                                    url = mirror.getUrl();
                                }
                                SimpleHttpLocation addition = new SimpleHttpLocation(id, url, snapshots.isEnabled(), releases.isEnabled(), true, false, null);
                                addition.setAttribute(Location.CONNECTION_TIMEOUT_SECONDS, 60);
                                locs.add(addition);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArtifactRepositoryLayout(org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout) SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) Profile(org.apache.maven.settings.Profile) Repository(org.apache.maven.settings.Repository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) Mirror(org.apache.maven.settings.Mirror)

Example 8 with SimpleHttpLocation

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

the class MavenContentFilteringTransferDecoratorTest method snapshotListingNotInWhenSnapshotsNotAllowedWithNoVersionPath.

@Test
public void snapshotListingNotInWhenSnapshotsNotAllowedWithNoVersionPath() throws Exception {
    final String fname = "commons-codec/commons-codec/";
    final SimpleHttpLocation location = new SimpleHttpLocation("test", "http://test", false, true, false, false, null);
    final ConcreteResource resource = new ConcreteResource(location, fname);
    final Transfer transfer = new Transfer(resource, null, null, null);
    String[] listing = Arrays.asList("1.0/", "1.0-SNAPSHOT/", "1.1/", "1.1-SNAPSHOT/").toArray(new String[4]);
    MavenContentsFilteringTransferDecorator decorator = new MavenContentsFilteringTransferDecorator();
    listing = decorator.decorateListing(transfer, listing, new EventMetadata());
    System.out.println(Arrays.asList(listing));
    assertThat(listing, CoreMatchers.notNullValue());
    assertThat(listing.length, equalTo(2));
    assertThat(Arrays.asList(listing).contains("1.0-SNAPSHOT/"), equalTo(false));
    assertThat(Arrays.asList(listing).contains("1.1-SNAPSHOT/"), equalTo(false));
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 9 with SimpleHttpLocation

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

the class MavenContentFilteringTransferDecoratorTest method metadataFilteringWhenSnapshotsNotAllowed.

@Test
public void metadataFilteringWhenSnapshotsNotAllowed() throws Exception {
    final String fname = "/commons-codec/commons-codec/maven-metadata.xml";
    // @formatter:off
    final String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<metadata modelVersion=\"1.1.0\">" + "  <groupId>commons-codec</groupId>" + "  <artifactId>commons-codec</artifactId>" + "  <versioning>" + "    <latest>1.2</latest>" + "    <release>1.2</release>" + "    <versions>" + "      <version>1.1</version>" + "      <version>1.1-SNAPSHOT</version>" + "      <version>1.2</version>" + "    </versions>" + "    <lastUpdated>20171020231327</lastUpdated>" + "  </versioning>" + "</metadata>";
    // @formatter:on
    final String baseUri = fixture.getBaseUri();
    final SimpleHttpLocation location = new SimpleHttpLocation("test", baseUri, false, true, true, true, null);
    final Transfer transfer = fixture.getTransfer(new ConcreteResource(location, fname));
    final String url = fixture.formatUrl(fname);
    assertThat(transfer.exists(), equalTo(false));
    try (OutputStream stream = transfer.openOutputStream(TransferOperation.UPLOAD)) {
        IOUtils.write(content, stream);
    }
    try (InputStream in = transfer.openInputStream()) {
        List<String> filtered = IOUtils.readLines(in);
        assertThat(filtered, notNullValue());
        StringBuilder builder = new StringBuilder();
        filtered.forEach(builder::append);
        String result = builder.toString();
        assertThat(result.contains("1.1"), equalTo(true));
        assertThat(result.contains("1.2"), equalTo(true));
        assertThat(result.contains("1.1-SNAPTHOT"), equalTo(false));
    }
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Test(org.junit.Test)

Example 10 with SimpleHttpLocation

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

the class MavenContentFilteringTransferDecoratorTest method getTestHttpTransfer.

private Transfer getTestHttpTransfer(final String path, final String content) throws Exception {
    fixture.expect("GET", fixture.formatUrl(path), 200, content);
    final String baseUri = fixture.getBaseUri();
    final SimpleHttpLocation location = new SimpleHttpLocation("test", baseUri, false, true, true, true, null);
    final Transfer transfer = fixture.getTransfer(new ConcreteResource(location, path));
    final String url = fixture.formatUrl(path);
    assertThat(transfer.exists(), equalTo(false));
    HttpDownload dl = new HttpDownload(url, location, transfer, new HashMap<>(), new EventMetadata(), fixture.getHttp().getHttp(), new ObjectMapper(), true, metricRegistry, metricConfig);
    return dl.call().getTransfer();
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) HttpDownload(org.commonjava.maven.galley.transport.htcli.internal.HttpDownload) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

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