Search in sources :

Example 51 with Transfer

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;
}
Also used : StoredObject(net.sf.webdav.StoredObject) StoreURIMatcher(org.commonjava.indy.dotmaven.util.StoreURIMatcher) Transfer(org.commonjava.maven.galley.model.Transfer) Date(java.util.Date)

Example 52 with Transfer

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;
}
Also used : NoHttpResponseException(org.apache.http.NoHttpResponseException) TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) IOException(java.io.IOException) GalleyException(org.commonjava.maven.galley.GalleyException) ClientProtocolException(org.apache.http.client.ClientProtocolException) StatusLine(org.apache.http.StatusLine) TransferException(org.commonjava.maven.galley.TransferException) SocketTimeoutException(java.net.SocketTimeoutException) Transfer(org.commonjava.maven.galley.model.Transfer) BadGatewayException(org.commonjava.maven.galley.BadGatewayException) TransferLocationException(org.commonjava.maven.galley.TransferLocationException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException)

Example 53 with Transfer

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);
    }
}
Also used : StoreURIMatcher(org.commonjava.indy.dotmaven.util.StoreURIMatcher) StorageAdvice(org.commonjava.indy.dotmaven.data.StorageAdvice) WebdavException(net.sf.webdav.exceptions.WebdavException) Transfer(org.commonjava.maven.galley.model.Transfer) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer)

Example 54 with Transfer

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);
    }
}
Also used : StoreURIMatcher(org.commonjava.indy.dotmaven.util.StoreURIMatcher) StorageAdvice(org.commonjava.indy.dotmaven.data.StorageAdvice) WebdavException(net.sf.webdav.exceptions.WebdavException) Transfer(org.commonjava.maven.galley.model.Transfer) IOException(java.io.IOException)

Example 55 with Transfer

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"));
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Document(org.w3c.dom.Document) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Aggregations

Transfer (org.commonjava.maven.galley.model.Transfer)154 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)63 Test (org.junit.Test)62 IOException (java.io.IOException)39 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)38 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)37 InputStream (java.io.InputStream)27 StoreKey (org.commonjava.indy.model.core.StoreKey)27 Logger (org.slf4j.Logger)26 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)22 ByteArrayInputStream (java.io.ByteArrayInputStream)21 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)21 HostedRepository (org.commonjava.indy.model.core.HostedRepository)21 Group (org.commonjava.indy.model.core.Group)20 ArrayList (java.util.ArrayList)19 IndyDataException (org.commonjava.indy.data.IndyDataException)19 OutputStream (java.io.OutputStream)15 HashSet (java.util.HashSet)15 Location (org.commonjava.maven.galley.model.Location)14 TransferException (org.commonjava.maven.galley.TransferException)12