@Override public void validateStorageUrl( String url ) throws RemoteStorageException { try { URL u = new URL( url ); if ( !"http".equals( u.getProtocol().toLowerCase() ) && !"https".equals( u.getProtocol().toLowerCase() ) ) { throw new RemoteStorageException( "Unsupported protocol, only HTTP/HTTPS protocols are supported: " + u.getProtocol().toLowerCase() ); } } catch ( MalformedURLException e ) { throw new RemoteStorageException( "Malformed URL", e ); } }
getLogger().debug( "HEAD method failed, will attempt GET. Exception: " + e.getMessage(), e ); throw new RemoteStorageException( "Unexpected response code while executing " + method.getMethod() + " method [repositoryId=\"" + repository.getId() + "\", requestPath=\"" + request.getRequestPath() + "\", remoteUrl=\"" + remoteUrl.toString() + "\"]. Expected: \"SUCCESS (200)\". Received: "
} catch (RemoteStorageException e) { ValidationResponse vr = new ApplicationValidationResponse(); ValidationMessage error = new ValidationMessage("remoteStorageUrl", e.getMessage(), e.getMessage()); vr.addValidationError(error); throw new InvalidConfigurationException(vr);
protected URL getAbsoluteUrlFromBase( final String baseUrl, final String path ) throws RemoteStorageException { final StringBuilder urlStr = new StringBuilder( baseUrl ); if ( !baseUrl.endsWith( RepositoryItemUid.PATH_SEPARATOR ) ) { urlStr.append( RepositoryItemUid.PATH_SEPARATOR ); } if ( !path.startsWith( RepositoryItemUid.PATH_SEPARATOR ) ) { urlStr.append( path ); } else { urlStr.append( path.substring( RepositoryItemUid.PATH_SEPARATOR.length() ) ); } try { return new URL( urlStr.toString() ); } catch ( MalformedURLException e ) { throw new RemoteStorageException( "The repository has broken URL!", e ); } }
getLogger().debug( "HEAD method failed, will attempt GET. Exception: " + e.getMessage(), e ); throw new RemoteStorageException( "Unexpected response code while executing " + method.getName() + " method [repositoryId=\"" + repository.getId() + "\", requestPath=\"" + request.getRequestPath() + "\", remoteUrl=\"" + remoteURL.toString() + "\"]. Expected: \"SUCCESS (200)\". Received: "
@Override public void deleteItem( final ProxyRepository repository, final ResourceStoreRequest request ) throws ItemNotFoundException, UnsupportedStorageOperationException, RemoteStorageException { final URL remoteUrl = appendQueryString( getAbsoluteUrlFromBase( repository, request ), repository ); final HttpDelete method = new HttpDelete( remoteUrl.toExternalForm() ); final HttpResponse httpResponse = executeRequestAndRelease( repository, request, method ); final int statusCode = httpResponse.getStatusLine().getStatusCode(); if ( statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_NO_CONTENT && statusCode != HttpStatus.SC_ACCEPTED ) { throw new RemoteStorageException( "The response to HTTP " + method.getMethod() + " was unexpected HTTP Code " + statusCode + " : " + httpResponse.getStatusLine().getReasonPhrase() + " [repositoryId=\"" + repository.getId() + "\", requestPath=\"" + request.getRequestPath() + "\", remoteUrl=\"" + remoteUrl.toString() + "\"]" ); } }
getLogger().debug( "HEAD method failed, will attempt GET. Exception: " + e.getMessage(), e ); throw new RemoteStorageException( e ); throw new RemoteStorageException( e ); throw new RemoteStorageException( "Unexpected response code while executing GET" + " method [repositoryId=\"" + repository.getId() + "\", requestPath=\"" + request.getRequestPath()
throw new RemoteStorageException( "Could not append query string \"" + queryString + "\" to url \"" + url + "\"", e );
@Override protected Map<String, StorageFileItem> doRetrieveArtifactsFileItems(final RequestContext context, final P2GroupRepository repository) throws RemoteStorageException, ItemNotFoundException { try { final List<StorageFileItem> fileItems = doRetrieveItems(P2Constants.ARTIFACTS_XML, context, repository); final ArtifactsMerge m = new ArtifactsMerge(); final Artifacts metadata = m.mergeArtifactsMetadata(repository.getName(), fileItems); return createMetadataItems( repository, P2Constants.ARTIFACTS_XML, P2Constants.ARTIFACTS_JAR, metadata, P2Constants.XMLPI_ARTIFACTS, context ); } catch (final P2MetadataMergeException e) { throw new RemoteStorageException(e); } catch (IOException e) { throw new RemoteStorageException(e); } }
@Override protected Map<String, StorageFileItem> doRetrieveContentFileItems(final RequestContext context, final P2GroupRepository repository) throws RemoteStorageException, ItemNotFoundException { try { final List<StorageFileItem> fileItems = doRetrieveItems(P2Constants.CONTENT_XML, context, repository); final ArtifactsMerge m = new ArtifactsMerge(); final Content metadata = m.mergeContentMetadata(repository.getName(), fileItems); return createMetadataItems( repository, P2Constants.CONTENT_XML, P2Constants.CONTENT_JAR, metadata, P2Constants.XMLPI_CONTENT, context ); } catch (final P2MetadataMergeException e) { throw new RemoteStorageException(e); } catch (final IOException e) { throw new RemoteStorageException(e); } }
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!" ); } }
throw new RemoteStorageException( e.getMessage() + " [repositoryId=\"" + repository.getId() + "\", requestPath=\"" + request.getRequestPath() + "\", remoteUrl=\"" + remoteUrl.toString() + "\"]", e ); && statusCode != HttpStatus.SC_NO_CONTENT && statusCode != HttpStatus.SC_ACCEPTED ) throw new RemoteStorageException( "Unexpected response code while executing " + method.getMethod() + " method [repositoryId=\"" + repository.getId() + "\", requestPath=\"" + request.getRequestPath() + "\", remoteUrl=\"" + remoteUrl.toString() + "\"]. Expected: \"any success (2xx)\". Received: "
throw new RemoteStorageException(e); throw new RemoteStorageException(e); throw new RemoteStorageException(e); throw new RemoteStorageException(e);
throw new RemoteStorageException(e); throw new RemoteStorageException(e); throw new RemoteStorageException(e); throw new RemoteStorageException(e); throw new RemoteStorageException(e);
throw new RemoteStorageException( "Invalid artifact found, most likely a proxy redirected to an HTML error page." ); throw new RemoteStorageException( "Protocol error while executing " + httpRequest.getMethod() + " method. [repositoryId=\"" + repository.getId() + "\", requestPath=\"" + request.getRequestPath() + "\", remoteUrl=\"" + methodUri.toASCIIString() + "\"]", ex ); throw new RemoteStorageException( "Transport error while executing " + httpRequest.getMethod() + " method [repositoryId=\"" + repository.getId() + "\", requestPath=\"" + request.getRequestPath() + "\", remoteUrl=\"" + methodUri.toASCIIString() + "\"]", ex );
@Override public void deleteItem( ProxyRepository repository, ResourceStoreRequest request ) throws ItemNotFoundException, UnsupportedStorageOperationException, RemoteStorageException { final URL remoteURL = getAbsoluteUrlFromBase( repository, request ); final String itemUrl = remoteURL.toString(); final AsyncHttpClient client = getClient( repository ); try { Response response = client.prepareDelete( itemUrl ).execute().get(); // expected: 200 OK, 202 ACCEPTED, 204 NO_CONTENT validateResponse( repository, request, "DELETE", itemUrl, response, 200, 202, 204 ); } catch ( ItemNotFoundException e ) { throw e; } catch ( RemoteStorageException e ) { throw e; } catch ( Exception e ) { throw new RemoteStorageException( e ); } }
@Override public void deleteItem( ProxyRepository repository, ResourceStoreRequest request ) throws ItemNotFoundException, UnsupportedStorageOperationException, RemoteStorageException { URL remoteURL = getAbsoluteUrlFromBase( repository, request ); DeleteMethod method = new DeleteMethod( remoteURL.toString() ); try { int response = executeMethod( repository, request, method, remoteURL ); if ( response != HttpStatus.SC_OK && response != HttpStatus.SC_NO_CONTENT && response != HttpStatus.SC_ACCEPTED ) { throw new RemoteStorageException( "The response to HTTP " + method.getName() + " was unexpected HTTP Code " + response + " : " + HttpStatus.getStatusText( response ) + " [repositoryId=\"" + repository.getId() + "\", requestPath=\"" + request.getRequestPath() + "\", remoteUrl=\"" + remoteURL.toString() + "\"]" ); } } finally { method.releaseConnection(); } }
throw new RemoteStorageException( "IO Error during response stream handling [repositoryId=\"" + repository.getId() + "\", requestPath=\"" + request.getRequestPath() + "\", remoteUrl=\"" + remoteURL.toString() + "\"]!", ex ); throw new RemoteStorageException( "The method execution returned result code " + httpResponse.getStatusLine().getStatusCode() + " (expected 200). [repositoryId=\"" + repository.getId() + "\", requestPath=\"" + request.getRequestPath() + "\", remoteUrl=\""
throw new RemoteStorageException( e ); throw new RemoteStorageException( e );
&& response != HttpStatus.SC_NO_CONTENT && response != HttpStatus.SC_ACCEPTED ) throw new RemoteStorageException( "Unexpected response code while executing " + method.getName() + " method [repositoryId=\"" + repository.getId() + "\", requestPath=\"" + request.getRequestPath() + "\", remoteUrl=\"" + remoteURL.toString() + "\"]. Expected: \"any success (2xx)\". Received: " throw new RemoteStorageException( e.getMessage() + " [repositoryId=\"" + repository.getId() + "\", requestPath=\"" + request.getRequestPath() + "\", remoteUrl=\"" + remoteURL.toString() + "\"]", e );