Search in sources :

Example 1 with MantaClientHttpResponseException

use of com.joyent.manta.exception.MantaClientHttpResponseException in project cyberduck by iterate-ch.

the class MantaHttpExceptionMappingService method map.

@Override
public BackgroundException map(final MantaClientHttpResponseException failure) {
    switch(failure.getStatusCode()) {
        case 403:
            final StringBuilder buffer = new StringBuilder();
            this.append(buffer, failure.getStatusMessage());
            return new LoginFailureException(buffer.toString(), failure);
    }
    return new DefaultHttpResponseExceptionMappingService().map(new HttpResponseException(failure.getStatusCode(), failure.getStatusMessage()));
}
Also used : DefaultHttpResponseExceptionMappingService(ch.cyberduck.core.http.DefaultHttpResponseExceptionMappingService) LoginFailureException(ch.cyberduck.core.exception.LoginFailureException) MantaClientHttpResponseException(com.joyent.manta.exception.MantaClientHttpResponseException) HttpResponseException(org.apache.http.client.HttpResponseException)

Example 2 with MantaClientHttpResponseException

use of com.joyent.manta.exception.MantaClientHttpResponseException in project cyberduck by iterate-ch.

the class MantaListService method list.

@Override
public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException {
    if (directory.isRoot()) {
        return new AttributedList<Path>(Collections.singletonList(new MantaAccountHomeInfo(session.getHost().getCredentials().getUsername(), session.getHost().getDefaultPath()).getNormalizedHomePath()));
    }
    final AttributedList<Path> children = new AttributedList<>();
    final Iterator<MantaObject> objectsIter;
    try {
        objectsIter = session.getClient().listObjects(directory.getAbsolute()).iterator();
    } catch (MantaObjectException e) {
        throw new MantaExceptionMappingService().map("Listing directory {0} failed", e, directory);
    } catch (MantaClientHttpResponseException e) {
        throw new MantaHttpExceptionMappingService().map("Listing directory {0} failed", e, directory);
    } catch (IOException e) {
        throw new DefaultIOExceptionMappingService().map("Listing directory {0} failed", e);
    }
    final MantaObjectAttributeAdapter adapter = new MantaObjectAttributeAdapter(session);
    while (objectsIter.hasNext()) {
        MantaObject o = objectsIter.next();
        final Path file = new Path(directory, PathNormalizer.name(o.getPath()), EnumSet.of(o.isDirectory() ? Path.Type.directory : Path.Type.file), adapter.toAttributes(o));
        children.add(file);
        listener.chunk(directory, children);
    }
    return children;
}
Also used : Path(ch.cyberduck.core.Path) MantaObject(com.joyent.manta.client.MantaObject) IOException(java.io.IOException) MantaClientHttpResponseException(com.joyent.manta.exception.MantaClientHttpResponseException) AttributedList(ch.cyberduck.core.AttributedList) DefaultIOExceptionMappingService(ch.cyberduck.core.DefaultIOExceptionMappingService) MantaObjectException(com.joyent.manta.exception.MantaObjectException)

Example 3 with MantaClientHttpResponseException

use of com.joyent.manta.exception.MantaClientHttpResponseException in project cyberduck by iterate-ch.

the class MantaReadFeature method read.

@Override
public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback connectionCallback) throws BackgroundException {
    final MantaHttpHeaders headers = new MantaHttpHeaders();
    try {
        try {
            if (status.isAppend()) {
                final HttpRange range = HttpRange.withStatus(status);
                headers.setByteRange(range.getStart(), range.getEnd() < 0 ? null : range.getEnd());
            }
            // see https://github.com/joyent/java-manta/issues/248
            return session.getClient().getAsInputStream(file.getAbsolute(), headers);
        } catch (UnsupportedOperationException e) {
            final MantaObject probablyEmptyFile = session.getClient().head(file.getAbsolute());
            if (probablyEmptyFile.getContentLength() != 0) {
                throw new AccessDeniedException();
            }
            return new NullInputStream(0L);
        }
    } catch (MantaException e) {
        throw new MantaExceptionMappingService().map("Download {0} failed", e, file);
    } catch (MantaClientHttpResponseException e) {
        throw new MantaHttpExceptionMappingService().map("Download {0} failed", e, file);
    } catch (IOException e) {
        throw new DefaultIOExceptionMappingService().map("Download {0} failed", e, file);
    }
}
Also used : AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) MantaObject(com.joyent.manta.client.MantaObject) MantaHttpHeaders(com.joyent.manta.http.MantaHttpHeaders) IOException(java.io.IOException) DefaultIOExceptionMappingService(ch.cyberduck.core.DefaultIOExceptionMappingService) MantaClientHttpResponseException(com.joyent.manta.exception.MantaClientHttpResponseException) MantaException(com.joyent.manta.exception.MantaException) HttpRange(ch.cyberduck.core.http.HttpRange) NullInputStream(org.apache.commons.io.input.NullInputStream)

Example 4 with MantaClientHttpResponseException

use of com.joyent.manta.exception.MantaClientHttpResponseException in project cyberduck by iterate-ch.

the class MantaSession method login.

@Override
public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException {
    try {
        config.setMantaUser(host.getCredentials().getUsername());
        if (host.getCredentials().isPublicKeyAuthentication()) {
            config.setMantaKeyId(new MantaPublicKeyAuthentication(this).authenticate(host, prompt, cancel));
        }
        if (host.getCredentials().isPasswordAuthentication()) {
            config.setPassword(host.getCredentials().getPassword());
        }
        config.setNoAuth(false);
        config.reload();
        // Instantiation of client does not validate credentials. List the home path to test the connection
        client.isDirectoryEmpty(new MantaHomeFinderFeature(host).find().getAbsolute());
    } catch (ConfigurationException e) {
        throw new BackgroundException(e.getRawMessage(), e);
    } catch (MantaException e) {
        throw new MantaExceptionMappingService().map(e);
    } catch (MantaClientHttpResponseException e) {
        throw new MantaHttpExceptionMappingService().map(e);
    } catch (IOException e) {
        throw new DefaultIOExceptionMappingService().map(e);
    }
}
Also used : ConfigurationException(com.joyent.manta.exception.ConfigurationException) IOException(java.io.IOException) DefaultIOExceptionMappingService(ch.cyberduck.core.DefaultIOExceptionMappingService) MantaClientHttpResponseException(com.joyent.manta.exception.MantaClientHttpResponseException) BackgroundException(ch.cyberduck.core.exception.BackgroundException) MantaException(com.joyent.manta.exception.MantaException)

Aggregations

MantaClientHttpResponseException (com.joyent.manta.exception.MantaClientHttpResponseException)4 DefaultIOExceptionMappingService (ch.cyberduck.core.DefaultIOExceptionMappingService)3 IOException (java.io.IOException)3 MantaObject (com.joyent.manta.client.MantaObject)2 MantaException (com.joyent.manta.exception.MantaException)2 AttributedList (ch.cyberduck.core.AttributedList)1 Path (ch.cyberduck.core.Path)1 AccessDeniedException (ch.cyberduck.core.exception.AccessDeniedException)1 BackgroundException (ch.cyberduck.core.exception.BackgroundException)1 LoginFailureException (ch.cyberduck.core.exception.LoginFailureException)1 DefaultHttpResponseExceptionMappingService (ch.cyberduck.core.http.DefaultHttpResponseExceptionMappingService)1 HttpRange (ch.cyberduck.core.http.HttpRange)1 ConfigurationException (com.joyent.manta.exception.ConfigurationException)1 MantaObjectException (com.joyent.manta.exception.MantaObjectException)1 MantaHttpHeaders (com.joyent.manta.http.MantaHttpHeaders)1 NullInputStream (org.apache.commons.io.input.NullInputStream)1 HttpResponseException (org.apache.http.client.HttpResponseException)1