use of org.commonjava.maven.galley.TransferException in project indy by Commonjava.
the class DefaultDownloadManager method list.
@Override
public List<StoreResource> list(final ArtifactStore store, final String path) throws IndyWorkflowException {
final List<StoreResource> result = new ArrayList<>();
if (store.getKey().getType() == StoreType.group) {
try {
final List<ListingResult> results = transfers.listAll(locationExpander.expand(new VirtualResource(LocationUtils.toLocations(store), path)));
for (final ListingResult lr : results) {
if (lr != null && lr.getListing() != null) {
for (final String file : lr.getListing()) {
result.add(new StoreResource((KeyedLocation) lr.getLocation(), path, file));
}
}
}
} catch (final BadGatewayException e) {
Location location = e.getLocation();
KeyedLocation kl = (KeyedLocation) location;
fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
logger.warn("Bad gateway: " + e.getMessage(), e);
} catch (final TransferTimeoutException e) {
Location location = e.getLocation();
KeyedLocation kl = (KeyedLocation) location;
fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
logger.warn("Timeout: " + e.getMessage(), e);
} catch (final TransferLocationException e) {
Location location = e.getLocation();
KeyedLocation kl = (KeyedLocation) location;
fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
logger.warn("Location Error: " + e.getMessage(), e);
} catch (final TransferException e) {
logger.error(e.getMessage(), e);
throw new IndyWorkflowException("Failed to list ALL paths: {} from: {}. Reason: {}", e, path, store.getKey(), e.getMessage());
}
} else {
final KeyedLocation loc = LocationUtils.toLocation(store);
final StoreResource res = new StoreResource(loc, path);
if (store instanceof RemoteRepository) {
try {
final ListingResult lr = transfers.list(res);
if (lr != null && lr.getListing() != null) {
for (final String file : lr.getListing()) {
result.add(new StoreResource(loc, path, file));
}
}
} catch (final BadGatewayException e) {
Location location = e.getLocation();
KeyedLocation kl = (KeyedLocation) location;
fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
logger.warn("Bad gateway: " + e.getMessage(), e);
} catch (final TransferTimeoutException e) {
Location location = e.getLocation();
KeyedLocation kl = (KeyedLocation) location;
fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
logger.warn("Timeout: " + e.getMessage(), e);
} catch (final TransferLocationException e) {
Location location = e.getLocation();
KeyedLocation kl = (KeyedLocation) location;
fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
logger.warn("Location Error: " + e.getMessage(), e);
} catch (final TransferException e) {
logger.error(e.getMessage(), e);
throw new IndyWorkflowException("Failed to list path: {} from: {}. Reason: {}", e, path, store.getKey(), e.getMessage());
}
} else {
try {
final ListingResult listing = transfers.list(res);
if (listing != null && listing.getListing() != null) {
for (final String child : listing.getListing()) {
result.add(new StoreResource(loc, path, child));
}
}
} catch (final TransferLocationException e) {
Location location = res.getLocation();
KeyedLocation kl = (KeyedLocation) location;
logger.warn("Timeout / bad gateway: " + e.getMessage(), e);
fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
} catch (final TransferException e) {
logger.error(e.getMessage(), e);
throw new IndyWorkflowException("Failed to list path: {} from: {}. Reason: {}", e, path, store.getKey(), e.getMessage());
}
}
}
return dedupeListing(result);
}
use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.
the class HttpDownload method writeTarget.
private void writeTarget() throws TransferException {
OutputStream out = null;
if (response != null) {
InputStream in = null;
try {
final HttpEntity entity = response.getEntity();
in = entity.getContent();
out = target.openOutputStream(TransferOperation.DOWNLOAD, true, eventMetadata);
copy(in, out);
logger.info("Ensuring all HTTP data is consumed...");
EntityUtils.consume(entity);
logger.info("All HTTP data was consumed.");
} catch (final IOException e) {
throw new TransferException("Failed to write to local proxy store: {}\nOriginal URL: {}. Reason: {}", e, target, url, e.getMessage());
} finally {
closeQuietly(in);
logger.info("Closing output stream: {}", out);
closeQuietly(out);
}
}
}
use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.
the class HttpDownload method call.
@Override
public DownloadJob call() {
request = new HttpGet(url);
try {
if (executeHttp()) {
transferSizes.put(target, HttpUtil.getContentLength(response));
writeTarget();
}
} catch (final TransferException e) {
this.error = e;
} finally {
cleanup();
}
logger.info("Download attempt done: {} Result:\n target: {}\n error: {}", url, target, error);
return this;
}
use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.
the class HttpPublish method call.
@Override
public HttpPublish call() {
// logger.info( "Trying: {}", url );
final HttpPut put = new HttpPut(url);
put.setEntity(new InputStreamEntity(stream, length, ContentType.create(contentType)));
request = put;
try {
success = executeHttp();
} catch (final TransferException e) {
this.error = e;
} finally {
cleanup();
}
return this;
}
use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.
the class HttpDownloadTest method simpleRetrieveOfAvailableUrl.
@Test
public void simpleRetrieveOfAvailableUrl() throws Exception {
final String fname = "simple-retrieval.html";
fixture.getServer().expect(fixture.formatUrl(fname), 200, fname);
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(true));
assertThat(transfer.exists(), equalTo(true));
final String path = fixture.getUrlPath(url);
assertThat(fixture.getAccessesFor(path), equalTo(1));
}
Aggregations