private StorageFileItem getMirrorsItemRemote(final String mirrorsURL) throws MalformedURLException, RemoteAccessException, RemoteStorageException, ItemNotFoundException { final URL url = new URL(mirrorsURL); final ResourceStoreRequest request = new ResourceStoreRequest(url.getFile()); final String baseUrl = getBaseMirrorsURL(url); final AbstractStorageItem mirrorsItem = getRemoteStorage().retrieveItem(this, request, baseUrl); if (mirrorsItem instanceof StorageFileItem) { return (StorageFileItem) mirrorsItem; } throw new ItemNotFoundException( ItemNotFoundException.reasonFor(request, this, "URL %s does not contain valid mirrors", mirrorsURL)); }
/** * Checks for remote existence of local item. * * @param localItem * @param request * @return * @throws RemoteAccessException * @throws StorageException */ protected boolean doCheckRemoteItemExistence( StorageItem localItem, ResourceStoreRequest request ) throws RemoteAccessException, RemoteStorageException { if ( localItem != null ) { return getRemoteStorage().containsItem( localItem.getModified(), this, request ); } else { return getRemoteStorage().containsItem( this, request ); } }
@VisibleForTesting StringBuilder ua( final RemoteStorageContext ctx, final ProxyRepository repository ) { final StringBuilder buf = new StringBuilder( getUserAgentPlatformInfo() ); if ( repository != null ) { final RemoteRepositoryStorage rrs = repository.getRemoteStorage(); buf.append( " " ).append( rrs.getProviderId() ).append( "/" ).append( rrs.getVersion() ); } // user customization RemoteConnectionSettings remoteConnectionSettings = ctx.getRemoteConnectionSettings(); if ( !StringUtils.isEmpty( remoteConnectionSettings.getUserAgentCustomizationString() ) ) { buf.append( " " ).append( remoteConnectionSettings.getUserAgentCustomizationString() ); } // plugin customization for ( UserAgentContributor contributor : contributors ) { final String contribution = contributor.getUserAgent( ctx, repository ); if ( !StringUtils.isEmpty( contribution ) ) { buf.append( " " ).append( contribution ); } } return buf; }
getRemoteStorage().validateStorageUrl( mirror.getUrl() ); getRemoteStorage().retrieveItem( this, request, mirror.getUrl() );
public void setRemoteStorage( RemoteRepositoryStorage remoteStorage ) { this.remoteStorage = remoteStorage; if ( remoteStorage == null ) { getCurrentConfiguration( true ).setRemoteStorage( null ); } else { if ( getCurrentConfiguration( true ).getRemoteStorage() == null ) { getCurrentConfiguration( true ).setRemoteStorage( new CRemoteStorage() ); } getCurrentConfiguration( true ).getRemoteStorage().setProvider( remoteStorage.getProviderId() ); setWritePolicy( RepositoryWritePolicy.READ_ONLY ); } }
public void setRemoteUrl( String remoteUrl ) throws RemoteStorageException { if ( getRemoteStorage() != null ) { String newRemoteUrl = remoteUrl.trim(); String oldRemoteUrl = getRemoteUrl(); if ( !newRemoteUrl.endsWith( RepositoryItemUid.PATH_SEPARATOR ) ) { newRemoteUrl = newRemoteUrl + RepositoryItemUid.PATH_SEPARATOR; } getRemoteStorage().validateStorageUrl( newRemoteUrl ); getCurrentConfiguration( true ).getRemoteStorage().setUrl( newRemoteUrl ); if ( ( StringUtils.isEmpty( oldRemoteUrl ) && StringUtils.isNotEmpty( newRemoteUrl ) ) || ( StringUtils.isNotEmpty( oldRemoteUrl ) && !oldRemoteUrl.equals( newRemoteUrl ) ) ) { this.remoteUrlChanged = true; } } else { throw new RemoteStorageException( "No remote storage set on repository \"" + getName() + "\" (ID=\"" + getId() + "\"), cannot set remoteUrl!" ); } }
protected boolean isRemoteStorageReachable( ResourceStoreRequest request ) throws StorageException { return getRemoteStorage().isReachable( this, request ); }
prepository.getRemoteStorage().getProviderId() ) )
configRemoteStorage.validateStorageUrl( repo.getRemoteStorage().getUrl() ); oldRemoteStorage.validateStorageUrl( repo.getRemoteStorage().getUrl() );
private DefaultStorageFileItem doRetriveRemoteChecksumItem( ProxyRepository proxy, ResourceStoreRequest request ) throws ItemNotFoundException { try { return (DefaultStorageFileItem) proxy.getRemoteStorage().retrieveItem( proxy, request, proxy.getRemoteUrl() ); } catch ( RemoteAccessException e ) { throw new ItemNotFoundException( request, proxy, e ); } catch ( RemoteStorageException e ) { throw new ItemNotFoundException( request, proxy, e ); } } }
@Override protected boolean isRemoteStorageReachable(final ResourceStoreRequest request) throws StorageException, RemoteAuthenticationNeededException, RemoteAccessDeniedException { // For p2 repositories, the root URL may not be reachable, // so we test if we can reach one of the "standard" p2 repository metadata files. for (final String metadataFilePath : P2Constants.METADATA_FILE_PATHS) { log.debug( "isRemoteStorageReachable: RepositoryId=" + getId() + ": Trying to access " + metadataFilePath); request.setRequestPath(metadataFilePath); try { // We cannot use getRemoteStorage().isReachable() here because that forces the request path to be "/" if (getRemoteStorage().containsItem(this, request)) { log.debug( "isRemoteStorageReachable: RepositoryId=" + getId() + ": Successfully accessed " + metadataFilePath); return true; } } catch (final RemoteStorageException e) { log.debug( "isRemoteStorageReachable: RepositoryId=" + getId() + ": Caught exception while trying to access " + metadataFilePath, e); // rethrow and core will say _why_ it autoblocked too // everything else than RemoteStorageException will bubble up too throw e; } } return false; }
private void fixRemoteUrl(final ResourceStoreRequest request) { if (overwriteRemoteUrl != null) { return; } if (P2Constants.SITE_XML.equals(request.getRequestPath())) { return; } try { final RepositoryItemUid siteUID = createUid(P2Constants.SITE_XML); final ResourceStoreRequest siteRequest = new ResourceStoreRequest(siteUID.getPath()); StorageFileItem siteItem; try { siteItem = (StorageFileItem) getLocalStorage().retrieveItem(this, siteRequest); } catch (final ItemNotFoundException e) { siteItem = (StorageFileItem) getRemoteStorage().retrieveItem(this, siteRequest, getRemoteUrl()); } final PlexusConfiguration plexusConfig = new XmlPlexusConfiguration(Xpp3DomBuilder.build(new InputStreamReader(siteItem.getInputStream()))); overwriteRemoteUrl = plexusConfig.getAttribute("url"); log.debug("Remote update site does overwrite the remote url " + overwriteRemoteUrl); } catch (final Exception e) { log.debug(e.getMessage(), e); overwriteRemoteUrl = ""; } }
(StorageFileItem) proxy.getRemoteStorage().retrieveItem( proxy, req, proxy.getRemoteUrl() );
public InputStream retrieve(String name) throws IOException { TaskUtil.checkInterruption(); ResourceStoreRequest req = new ResourceStoreRequest(PUBLISHING_PATH_PREFIX + "/" + name); try { StorageFileItem item = null; // XXX: ensure it goes to remote only and throws FileNotFoundException if nothing found on remote // kinda turn off transparent proxying for this method // We need to use ProxyRepository and get it's RemoteStorage stuff to completely // avoid "transparent" proxying, and even the slightest possibility to return // some stale file from cache to the updater. if (ISPROXY(repository) && REMOTEACCESSALLOWED(repository)) { item = (StorageFileItem) repository.getRemoteStorage() .retrieveItem(repository, req, repository.getRemoteUrl()); } else { throw new ItemNotFoundException(req, repository); } return item.getInputStream(); } catch (ItemNotFoundException ex) { final FileNotFoundException fne = new FileNotFoundException(name + " (remote item not found)"); fne.initCause(ex); throw fne; } } });
try { item = getRemoteStorage().retrieveItem(this, remoteStoreRequest, absoluteUrl);