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));
}
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);
}
}
}
}
}
}
}
}
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));
}
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));
}
}
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();
}
Aggregations