use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.
the class ArtifactStoreSubStore method getStoredObject.
@Override
public StoredObject getStoredObject(final ITransaction transaction, final String uri) throws WebdavException {
final StoredObject so = new StoredObject();
final StoreURIMatcher matcher = new StoreURIMatcher(uri);
if (matcher.hasStorePath()) {
final Transfer item = getTransfer(matcher);
if (item == null) {
return null;
}
so.setCreationDate(new Date(item.lastModified()));
so.setLastModified(new Date(item.lastModified()));
so.setFolder(item.isDirectory());
so.setResourceLength(item.length());
} else {
final Date d = new Date();
so.setCreationDate(d);
so.setLastModified(d);
so.setFolder(true);
}
return so;
}
use of org.commonjava.maven.galley.model.Transfer 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.model.Transfer in project indy by Commonjava.
the class ArtifactStoreSubStore method setResourceContent.
@Override
public long setResourceContent(final ITransaction transaction, final String resourceUri, final InputStream content, final String contentType, final String characterEncoding) throws WebdavException {
final StoreURIMatcher matcher = new StoreURIMatcher(resourceUri);
if (!matcher.hasStorePath()) {
throw new WebdavException("No store-level path specified: '" + resourceUri + "'. This URI references either a list of stores, a root store directory, or something else equally read-only.");
}
final StorageAdvice advice = getStorageAdviceFor(matcher);
final String path = matcher.getStorePath();
final Transfer item = fileManager.getStorageReference(advice.getHostedStore(), path);
Writer writer = null;
try {
if (characterEncoding != null) {
writer = new OutputStreamWriter(item.openOutputStream(TransferOperation.UPLOAD), characterEncoding);
} else {
writer = new OutputStreamWriter(item.openOutputStream(TransferOperation.UPLOAD));
}
copy(content, writer);
return item.length();
} catch (final IOException e) {
logger.error("Failed to write file: {} in store: {}. Reason: {}", e, path, advice.getStore().getKey(), e.getMessage());
throw new WebdavException("Failed to write file: " + resourceUri);
} finally {
closeQuietly(writer);
}
}
use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.
the class ArtifactStoreSubStore method removeObject.
@Override
public void removeObject(final ITransaction transaction, final String uri) throws WebdavException {
final StoreURIMatcher matcher = new StoreURIMatcher(uri);
if (!matcher.hasStorePath()) {
throw new WebdavException("No store-level path specified: '" + uri + "'. This URI references either a list of stores, a root store directory, or something else equally read-only.");
}
final StorageAdvice advice = getStorageAdviceFor(matcher);
final String path = matcher.getStorePath();
final Transfer item = fileManager.getStorageReference(advice.getHostedStore(), path);
try {
if (item.exists()) {
item.delete();
}
} catch (final IOException e) {
logger.error("Failed to delete file: {} in store: {}. Reason: {}", e, path, advice.getStore().getKey(), e.getMessage());
throw new WebdavException("Failed to delete file: " + uri);
}
}
use of org.commonjava.maven.galley.model.Transfer in project galley by Commonjava.
the class ArtifactManagerImplTest method resolveSnapshot_FirstMatch_SingletonLocationList_TwoSnapshotList_LatestVersionStrategy.
@Test
public void resolveSnapshot_FirstMatch_SingletonLocationList_TwoSnapshotList_LatestVersionStrategy() throws Exception {
final String base = "2-snapshots-1-location/";
final String testResource = base + "two-snapshots.xml";
final String testPomResource = base + "two-snapshots-pom.xml";
final ProjectVersionRef ref = new SimpleProjectVersionRef("org.group2", "artifact", "1.0-SNAPSHOT");
final ConcreteResource metadataResource = new ConcreteResource(LOCATION, fixture.snapshotMetadataPath(ref));
final ConcreteResource pomResource = new ConcreteResource(LOCATION, fixture.pomPath(ref.selectVersion("1.0-20140604.102909-1").asPomArtifact()));
fixture.getTransport().registerDownload(metadataResource, new TestDownload(ROOT + testResource));
fixture.getTransport().registerDownload(pomResource, new TestDownload(ROOT + testPomResource));
final Transfer retrieved = fixture.getArtifactManager().retrieve(LOCATION, ref.asPomArtifact(), new EventMetadata());
final Document document = fixture.getXml().parse(retrieved, new EventMetadata());
final ProjectVersionRef result = fixture.getXml().getProjectVersionRef(document);
System.out.println(result);
assertThat(result, notNullValue());
assertThat(result.getVersionString(), equalTo("1.0-20140604.102909-1"));
}
Aggregations