use of org.commonjava.maven.galley.TransferLocationException in project indy by Commonjava.
the class DefaultDownloadManager method list.
@Override
public List<StoreResource> list(final List<? extends ArtifactStore> stores, final String path) throws IndyWorkflowException {
final String dir = PathUtils.dirname(path);
final List<StoreResource> result = new ArrayList<>();
try {
final List<ListingResult> results = transfers.listAll(locationExpander.expand(new VirtualResource(LocationUtils.toLocations(stores), 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(), dir, 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, stores, e.getMessage());
}
return dedupeListing(result);
}
use of org.commonjava.maven.galley.TransferLocationException in project indy by Commonjava.
the class DefaultDownloadManager method store.
/*
* (non-Javadoc)
* @see org.commonjava.indy.core.rest.util.FileManager#upload(org.commonjava.indy.core.model.DeployPoint,
* java.lang.String, java.io.InputStream)
*/
@Override
public Transfer store(final ArtifactStore store, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
if (store.getKey().getType() == StoreType.group) {
//FIXME: Why is this null? Investigate.
return null;
}
if (store.getKey().getType() != StoreType.hosted) {
throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "Cannot deploy to non-deploy point artifact store: {}.", store.getKey());
}
if (storeManager.isReadonly(store)) {
throw new IndyWorkflowException(ApplicationStatus.METHOD_NOT_ALLOWED.code(), "The store {} is readonly. If you want to store any content to this store, please modify it to non-readonly", store.getKey());
}
if (store instanceof HostedRepository) {
final HostedRepository deploy = (HostedRepository) store;
// final ArtifactPathInfo pathInfo = ArtifactPathInfo.parse( path );
final ContentQuality quality = getQuality(path);
if (quality != null && quality == ContentQuality.SNAPSHOT) {
if (!deploy.isAllowSnapshots()) {
logger.error("Cannot store snapshot in non-snapshot deploy point: {}", deploy.getName());
throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "Cannot store snapshot in non-snapshot deploy point: {}", deploy.getName());
}
} else if (!deploy.isAllowReleases()) {
logger.error("Cannot store release in snapshot-only deploy point: {}", deploy.getName());
throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "Cannot store release in snapshot-only deploy point: {}", deploy.getName());
}
}
try {
return transfers.store(new ConcreteResource(LocationUtils.toLocation(store), path), stream, eventMetadata);
} 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);
throw new IndyWorkflowException("Failed to store path: {} in: {}. Reason: {}", e, path, store, e.getMessage());
} 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);
throw new IndyWorkflowException("Failed to store path: {} in: {}. Reason: {}", e, path, store, e.getMessage());
} 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);
throw new IndyWorkflowException("Failed to store path: {} in: {}. Reason: {}", e, path, store, e.getMessage());
} catch (TransferException e) {
logger.error(String.format("Failed to store: %s in: %s. Reason: %s", path, store.getKey(), e.getMessage()), e);
throw new IndyWorkflowException("Failed to store: %s in: %s. Reason: %s", e, path, store.getKey(), e.getMessage());
}
}
use of org.commonjava.maven.galley.TransferLocationException in project galley by Commonjava.
the class HttpImpl method createClient.
@Override
public CloseableHttpClient createClient(final HttpLocation location) throws GalleyException {
try {
if (location != null) {
locationLookup.register(location);
int maxConnections = LocationUtils.getMaxConnections(location);
SiteConfigBuilder configBuilder = new SiteConfigBuilder(location.getName(), location.getUri());
configBuilder.withAttributes(location.getAttributes()).withKeyCertPem(location.getKeyCertPem()).withServerCertPem(location.getServerCertPem()).withProxyHost(location.getProxyHost()).withProxyPort(location.getProxyPort()).withProxyUser(location.getProxyUser()).withRequestTimeoutSeconds(LocationUtils.getTimeoutSeconds(location)).withUser(location.getUser()).withMaxConnections(maxConnections);
if (location.getTrustType() != null) {
configBuilder.withTrustType(SiteTrustType.getType(location.getTrustType().name()));
}
SiteConfig config = configBuilder.build();
return httpFactory.createClient(config);
} else {
return httpFactory.createClient();
}
} catch (JHttpCException e) {
throw new TransferLocationException(location, "Failed to initialize http client: %s", e, e.getMessage());
} finally {
}
}
use of org.commonjava.maven.galley.TransferLocationException in project galley by Commonjava.
the class AbstractHttpJob method executeHttp.
protected boolean executeHttp() throws TransferException {
try {
client = http.createClient(location);
response = client.execute(request, http.createContext(location));
final StatusLine line = response.getStatusLine();
final int sc = line.getStatusCode();
logger.debug("{} {} : {}", request.getMethod(), line, url);
if (!successStatuses.contains(sc)) {
logger.debug("Detected failure response: " + sc);
success = TransferResponseUtils.handleUnsuccessfulResponse(request, response, location, url);
logger.debug("Returning non-error failure response for code: " + sc);
return false;
}
} catch (final NoHttpResponseException e) {
throw new TransferTimeoutException(location, url, "Repository remote request failed for: {}. Reason: {}", e, url, e.getMessage());
} catch (final ConnectTimeoutException e) {
throw new TransferTimeoutException(location, url, "Repository remote request failed for: {}. Reason: {}", e, url, e.getMessage());
} catch (final SocketTimeoutException e) {
throw new TransferTimeoutException(location, url, "Repository remote request failed for: {}. Reason: {}", e, url, e.getMessage());
} catch (final ClientProtocolException e) {
throw new TransferLocationException(location, "Repository remote request failed for: {}. Reason: {}", e, url, e.getMessage());
} catch (BadGatewayException e) {
throw e;
} catch (final GalleyException e) {
throw new TransferException("Repository remote request failed for: {}. Reason: {}", e, url, e.getMessage());
} catch (final IOException e) {
throw new TransferLocationException(location, "Repository remote request failed for: {}. Reason: {}", e, url, e.getMessage());
} finally {
/*
* we need to integrate the writeMetadata() method into the executeHttp() call in a finally block,
* and with a condition that it only runs on HEAD or GET. This would allow us to capture metadata on failed requests too,
* which is critical for responding consistently to the user after a failed request is cached in the NFC.
*/
String method = request.getMethod();
if ("GET".equalsIgnoreCase(method) || "HEAD".equalsIgnoreCase(method)) {
Transfer target = getTransfer();
ObjectMapper mapper = getMetadataObjectMapper();
if (target != null && mapper != null) {
writeMetadata(target, mapper);
}
}
}
return true;
}
use of org.commonjava.maven.galley.TransferLocationException in project galley by Commonjava.
the class TransferResponseUtils method handleUnsuccessfulResponse.
public static boolean handleUnsuccessfulResponse(final HttpUriRequest request, final CloseableHttpResponse response, HttpLocation location, final String url, final boolean graceful404) throws TransferException {
final Logger logger = LoggerFactory.getLogger(TransferResponseUtils.class);
final StatusLine line = response.getStatusLine();
InputStream in = null;
HttpEntity entity = null;
try {
entity = response.getEntity();
final int sc = line.getStatusCode();
boolean contentMissing = (sc == HttpStatus.SC_NOT_FOUND || sc == HttpStatus.SC_GONE);
if (graceful404 && contentMissing) {
return false;
} else {
ByteArrayOutputStream out = null;
if (entity != null) {
in = entity.getContent();
out = new ByteArrayOutputStream();
copy(in, out);
}
if (NON_SERVER_GATEWAY_ERRORS.contains(sc) || (sc > 499 && sc < 599)) {
throw new BadGatewayException(location, url, sc, "HTTP request failed: %s%s", line, (out == null ? "" : "\n\n" + new String(out.toByteArray())));
} else if (contentMissing) {
throw new TransferException("HTTP request failed: %s\nURL: %s%s", line, url, (out == null ? "" : "\n\n" + new String(out.toByteArray())));
} else {
throw new TransferLocationException(location, "HTTP request failed: %s%s", line, (out == null ? "" : "\n\n" + new String(out.toByteArray())));
}
}
} catch (final IOException e) {
request.abort();
throw new TransferLocationException(location, "Error reading body of unsuccessful request.\nStatus: %s.\nURL: %s.\nReason: %s", e, line, url, e.getMessage());
} finally {
IOUtils.closeQuietly(in);
if (entity != null) {
try {
EntityUtils.consume(entity);
} catch (final IOException e) {
logger.debug("Failed to consume entity: " + e.getMessage(), e);
}
}
}
}
Aggregations