@Override public void onFailure(final GoogleJsonError e, final HttpHeaders responseHeaders) { log.warn(String.format("Failure deleting %s. %s", file, e.getMessage())); failures.add(new HttpResponseExceptionMappingService().map( new HttpResponseException(e.getCode(), e.getMessage()))); }
@Override public BackgroundException map(final GenericException e) { final StringBuilder buffer = new StringBuilder(); this.append(buffer, e.getMessage()); final StatusLine status = e.getHttpStatusLine(); if(null != status) { this.append(buffer, String.format("%d %s", status.getStatusCode(), status.getReasonPhrase())); } switch(e.getHttpStatusCode()) { case HttpStatus.SC_BAD_REQUEST: return new LoginFailureException(buffer.toString(), e); } return new HttpResponseExceptionMappingService().map(new HttpResponseException(e.getHttpStatusCode(), buffer.toString())); } }
@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 HttpResponseExceptionMappingService().map(new HttpResponseException(failure.getStatusCode(), failure.getStatusMessage())); } }
return new HttpMethodReleaseInputStream(response); default: throw new HttpResponseExceptionMappingService().map(new HttpResponseException( response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()));
return new HttpResponseExceptionMappingService().map((HttpResponseException) cause); return new HttpResponseExceptionMappingService().map(failure, buffer, failure.getCode());
return new HttpResponseExceptionMappingService().map(new HttpResponseException(e.getStatus(), buffer.toString()));
return new HttpResponseExceptionMappingService().map(new HttpResponseException(failure.getStatusCode(), buffer.toString()));
@Override public BackgroundException map(final IOException failure) { final StringBuilder buffer = new StringBuilder(); if(failure instanceof GoogleJsonResponseException) { final GoogleJsonResponseException error = (GoogleJsonResponseException) failure; this.append(buffer, error.getDetails().getMessage()); switch(error.getDetails().getCode()) { case HttpStatus.SC_FORBIDDEN: final List<GoogleJsonError.ErrorInfo> errors = error.getDetails().getErrors(); for(GoogleJsonError.ErrorInfo info : errors) { if("usageLimits".equals(info.getDomain())) { return new RetriableAccessDeniedException(buffer.toString(), Duration.ofSeconds(5), failure); } } break; } } if(failure instanceof HttpResponseException) { final HttpResponseException response = (HttpResponseException) failure; this.append(buffer, response.getStatusMessage()); return new HttpResponseExceptionMappingService().map(new org.apache.http.client .HttpResponseException(response.getStatusCode(), buffer.toString())); } return super.map(failure); } }
/** * Forces a full reclaim of all caches, and waits until the reclaim completes. Cache contents that need to be retained because they are a part of an active job are retained. * Any cache contents that can be reclaimed will be. This operation may take a very long time to complete, depending on how much of the cache can be reclaimed and how many blobs the cache is managing. */ protected void clear() throws BackgroundException { try { // Cancel all active jobs to remove references to cached objects final Ds3Client ds3Client = new SpectraClientBuilder().wrap(session.getClient(), session.getHost()); ds3Client.cancelAllActiveJobsSpectraS3(new CancelAllActiveJobsSpectraS3Request()); // Clear cache final RequestEntityRestStorageService client = session.getClient(); final HttpPut request = new HttpPut(String.format("%s://%s:%s/_rest_/cache_filesystem?reclaim", session.getHost().getProtocol().getScheme(), session.getHost().getHostname(), session.getHost().getPort())); client.authorizeHttpRequest(request, null, null); final HttpResponse response = client.getHttpClient().execute(request); if(HttpStatus.SC_NO_CONTENT != response.getStatusLine().getStatusCode()) { throw new HttpResponseException(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()); } } catch(HttpResponseException e) { throw new HttpResponseExceptionMappingService().map(e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } catch(ServiceException e) { throw new S3ExceptionMappingService().map(e); } } }
return new DefaultIOExceptionMappingService().map((IOException) e.getCause()); return new HttpResponseExceptionMappingService().map(new HttpResponseException(e.getStatusCode(), buffer.toString()));
public OAuthTokens refresh(final OAuthTokens tokens) throws BackgroundException { if(StringUtils.isBlank(tokens.getRefreshToken())) { log.warn("Missing refresh token"); return tokens; } if(log.isDebugEnabled()) { log.debug(String.format("Refresh expired tokens %s", tokens)); } try { final TokenResponse response = new RefreshTokenRequest(transport, json, new GenericUrl(tokenServerUrl), tokens.getRefreshToken()) .setClientAuthentication(new ClientParametersAuthentication(clientid, clientsecret)) .executeUnparsed().parseAs(PermissiveTokenResponse.class).toTokenResponse(); final long expiryInMilliseconds = System.currentTimeMillis() + response.getExpiresInSeconds() * 1000; if(StringUtils.isBlank(response.getRefreshToken())) { return new OAuthTokens(response.getAccessToken(), tokens.getRefreshToken(), expiryInMilliseconds); } return new OAuthTokens(response.getAccessToken(), response.getRefreshToken(), expiryInMilliseconds); } catch(TokenResponseException e) { throw new OAuthExceptionMappingService().map(e); } catch(HttpResponseException e) { throw new HttpResponseExceptionMappingService().map(new org.apache.http.client .HttpResponseException(e.getStatusCode(), e.getStatusMessage())); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
return new InteroperabilityException(buffer.toString(), e); return new HttpResponseExceptionMappingService().map(new HttpResponseException(e.getResponseCode(), buffer.toString()));
@Override public BackgroundException map(final OneDriveAPIException failure) { if(failure.getResponseCode() > 0) { final StringAppender buffer = new StringAppender(); buffer.append(failure.getMessage()); buffer.append(failure.getErrorMessage()); return new HttpResponseExceptionMappingService().map(new HttpResponseException(failure.getResponseCode(), buffer.toString())); } if(ExceptionUtils.getRootCause(failure) instanceof IOException) { return new DefaultIOExceptionMappingService().map((IOException) ExceptionUtils.getRootCause(failure)); } return new InteroperabilityException(failure.getMessage(), failure); } }
throw new HttpResponseExceptionMappingService().map(new org.apache.http.client .HttpResponseException(e.getStatusCode(), e.getStatusMessage()));
public Reply upload(final Path file, final Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus status, final StreamCancelation cancel, final StreamProgress progress, final ConnectionCallback callback) throws BackgroundException { try { final Digest digest = this.digest(); // Wrap with digest stream if available final InputStream in = this.decorate(local.getInputStream(), digest); final StatusOutputStream<Reply> out = writer.write(file, status, callback); new StreamCopier(cancel, progress) .withOffset(status.getOffset()) .withLimit(status.getLength()) .withListener(listener) .transfer(in, new ThrottledOutputStream(out, throttle)); final Reply response = out.getStatus(); this.post(file, digest, response); return response; } catch(HttpResponseException e) { throw new HttpResponseExceptionMappingService().map("Upload {0} failed", e, file); } catch(IOException e) { throw new HttpExceptionMappingService().map("Upload {0} failed", e, file); } }