Search in sources :

Example 46 with TransferException

use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.

the class FileDownload method call.

@Override
public DownloadJob call() {
    FileInputStream in = null;
    OutputStream out = null;
    try {
        if (src.exists() && !src.isDirectory()) {
            in = new FileInputStream(src);
            out = txfr.openOutputStream(TransferOperation.DOWNLOAD, true, eventMetadata);
            copy(in, out);
        }
        return this;
    } catch (final IOException e) {
        error = new TransferException("Failed to copy from: %s to: %s. Reason: %s", e, src, txfr, e.getMessage());
    } finally {
        closeQuietly(in);
        closeQuietly(out);
    }
    return this;
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) OutputStream(java.io.OutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 47 with TransferException

use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.

the class ZipPublish method writeArchive.

private Boolean writeArchive(final File dest, final String path) {
    final boolean isJar = isJarOperation();
    FileOutputStream fos = null;
    ZipOutputStream zos = null;
    ZipFile zf = null;
    try {
        fos = new FileOutputStream(dest);
        zos = isJar ? new JarOutputStream(fos) : new ZipOutputStream(fos);
        zf = isJar ? new JarFile(dest) : new ZipFile(dest);
        final ZipEntry entry = zf.getEntry(path);
        zos.putNextEntry(entry);
        copy(stream, zos);
        return true;
    } catch (final IOException e) {
        error = new TransferException("Failed to write path: %s to NEW archive: %s. Reason: %s", e, path, dest, e.getMessage());
    } finally {
        closeQuietly(zos);
        closeQuietly(fos);
        if (zf != null) {
            try {
                zf.close();
            } catch (final IOException e) {
            }
        }
        closeQuietly(stream);
    }
    return false;
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) ZipFile(java.util.zip.ZipFile) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) JarOutputStream(java.util.jar.JarOutputStream) IOException(java.io.IOException) JarFile(java.util.jar.JarFile)

Example 48 with TransferException

use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.

the class ZipPublish method rewriteArchive.

private Boolean rewriteArchive(final File dest, final String path) {
    final boolean isJar = isJarOperation();
    final File src = new File(dest.getParentFile(), dest.getName() + ".old");
    dest.renameTo(src);
    InputStream zin = null;
    ZipFile zfIn = null;
    FileOutputStream fos = null;
    ZipOutputStream zos = null;
    ZipFile zfOut = null;
    try {
        fos = new FileOutputStream(dest);
        zos = isJar ? new JarOutputStream(fos) : new ZipOutputStream(fos);
        zfOut = isJar ? new JarFile(dest) : new ZipFile(dest);
        zfIn = isJar ? new JarFile(src) : new ZipFile(src);
        for (final Enumeration<? extends ZipEntry> en = zfIn.entries(); en.hasMoreElements(); ) {
            final ZipEntry inEntry = en.nextElement();
            final String inPath = inEntry.getName();
            try {
                if (inPath.equals(path)) {
                    zin = stream;
                } else {
                    zin = zfIn.getInputStream(inEntry);
                }
                final ZipEntry entry = zfOut.getEntry(inPath);
                zos.putNextEntry(entry);
                copy(stream, zos);
            } finally {
                closeQuietly(zin);
            }
        }
        return true;
    } catch (final IOException e) {
        error = new TransferException("Failed to write path: %s to EXISTING archive: %s. Reason: %s", e, path, dest, e.getMessage());
    } finally {
        closeQuietly(zos);
        closeQuietly(fos);
        if (zfOut != null) {
            try {
                zfOut.close();
            } catch (final IOException e) {
            }
        }
        if (zfIn != null) {
            try {
                zfIn.close();
            } catch (final IOException e) {
            }
        }
        closeQuietly(stream);
    }
    return false;
}
Also used : InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) JarOutputStream(java.util.jar.JarOutputStream) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) TransferException(org.commonjava.maven.galley.TransferException) ZipFile(java.util.zip.ZipFile) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) JarFile(java.util.jar.JarFile) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 49 with TransferException

use of org.commonjava.maven.galley.TransferException in project indy by Commonjava.

the class AutoProxDataManagerDecorator method checkValidity.

/**
     * Validates the remote connection, produced from rule-set for given key,
     * for a remote repo or group containing a remote. If:
     *
     * <ul>
     *   <li>rule.isValidationEnabled() == false, return true</li>
     *   <li>rule.getValidationRemote() == null, return true</li>
     *   <li>
     *     rule.getRemoteValidationPath() != null, validate remote.getUrl() + validationPath
     *     <ul>
     *       <li>if response code is 200 OK, then return true</li>
     *       <li>otherwise, return false</li>
     *     </ul>
     *   </li>
     * </ul>
     * @throws IndyDataException if the selected rule encounters an error while creating the new group/repository instance(s).
     */
private boolean checkValidity(final StoreKey key) throws IndyDataException {
    if (catalog.isValidationEnabled(key)) {
        try {
            final RemoteRepository validationRepo = catalog.createValidationRemote(key);
            if (validationRepo == null) {
                logger.info("No validation repository was created: assuming {} is valid.", key);
                return true;
            }
            String path = catalog.getRemoteValidationPath(key);
            if (path == null) {
                path = PathUtils.ROOT;
            }
            logger.debug("\n\n\n\n\n[AutoProx] Checking path: {} under remote URL: {}", path, validationRepo.getUrl());
            boolean result = false;
            try {
                result = transferManager.exists(new ConcreteResource(LocationUtils.toLocation(validationRepo), path));
            } catch (final TransferException e) {
                logger.warn("[AutoProx] Cannot connect to target repository: '{}'. Reason: {}", validationRepo, e.getMessage());
                logger.debug("[AutoProx] exception from validation attempt for: " + validationRepo, e);
            }
            logger.debug("Validation result for: {} is: {}", validationRepo, result);
            return result;
        } catch (final AutoProxRuleException e) {
            throw new IndyDataException("[AUTOPROX] Failed to create new group from factory matching: '%s'. Reason: %s", e, key, e.getMessage());
        }
    }
    return true;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) TransferException(org.commonjava.maven.galley.TransferException) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository)

Aggregations

TransferException (org.commonjava.maven.galley.TransferException)49 IOException (java.io.IOException)17 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)15 Transfer (org.commonjava.maven.galley.model.Transfer)12 ArrayList (java.util.ArrayList)9 TransferLocationException (org.commonjava.maven.galley.TransferLocationException)9 TransferTimeoutException (org.commonjava.maven.galley.TransferTimeoutException)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 OutputStream (java.io.OutputStream)7 ListingResult (org.commonjava.maven.galley.model.ListingResult)7 InputStream (java.io.InputStream)6 Location (org.commonjava.maven.galley.model.Location)6 File (java.io.File)5 HashMap (java.util.HashMap)5 JarFile (java.util.jar.JarFile)5 ZipEntry (java.util.zip.ZipEntry)5 ZipFile (java.util.zip.ZipFile)5 SimpleHttpLocation (org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation)5 Test (org.junit.Test)5 ExecutionException (java.util.concurrent.ExecutionException)4