use of net.sf.webdav.exceptions.WebdavException in project indy by Commonjava.
the class ArtifactStoreSubStore method removeObject.
@Override
public void removeObject(final ITransaction transaction, final String uri) throws WebdavException {
final StoreURIMatcher matcher = new StoreURIMatcher(uri);
if (!matcher.hasStorePath()) {
throw new WebdavException("No store-level path specified: '" + uri + "'. This URI references either a list of stores, a root store directory, or something else equally read-only.");
}
final StorageAdvice advice = getStorageAdviceFor(matcher);
final String path = matcher.getStorePath();
final Transfer item = fileManager.getStorageReference(advice.getHostedStore(), path);
try {
if (item.exists()) {
item.delete();
}
} catch (final IOException e) {
logger.error("Failed to delete file: {} in store: {}. Reason: {}", e, path, advice.getStore().getKey(), e.getMessage());
throw new WebdavException("Failed to delete file: " + uri);
}
}
use of net.sf.webdav.exceptions.WebdavException in project indy by Commonjava.
the class ArtifactStoreSubStore method createFolder.
@Override
public void createFolder(final ITransaction transaction, final String folderUri) throws WebdavException {
final StoreURIMatcher matcher = new StoreURIMatcher(folderUri);
if (!matcher.hasStorePath()) {
throw new WebdavException("No store-level path specified: '" + folderUri + "'. This URI references either a list of stores, a root store directory, or something else equally read-only.");
}
final StorageAdvice advice = getStorageAdviceFor(matcher);
final String path = matcher.getStorePath();
final Transfer item = fileManager.getStorageReference(advice.getHostedStore(), path);
try {
item.mkdirs();
} catch (final IOException e) {
logger.error("Failed to create folder: {} in store: {}. Reason: {}", e, path, advice.getStore().getKey(), e.getMessage());
throw new WebdavException("Failed to create folder: " + folderUri);
}
}
use of net.sf.webdav.exceptions.WebdavException in project indy by Commonjava.
the class ArtifactStoreSubStore method setResourceContent.
@Override
public long setResourceContent(final ITransaction transaction, final String resourceUri, final InputStream content, final String contentType, final String characterEncoding) throws WebdavException {
final StoreURIMatcher matcher = new StoreURIMatcher(resourceUri);
if (!matcher.hasStorePath()) {
throw new WebdavException("No store-level path specified: '" + resourceUri + "'. This URI references either a list of stores, a root store directory, or something else equally read-only.");
}
final StorageAdvice advice = getStorageAdviceFor(matcher);
final String path = matcher.getStorePath();
final Transfer item = fileManager.getStorageReference(advice.getHostedStore(), path);
Writer writer = null;
try {
if (characterEncoding != null) {
writer = new OutputStreamWriter(item.openOutputStream(TransferOperation.UPLOAD), characterEncoding);
} else {
writer = new OutputStreamWriter(item.openOutputStream(TransferOperation.UPLOAD));
}
copy(content, writer);
return item.length();
} catch (final IOException e) {
logger.error("Failed to write file: {} in store: {}. Reason: {}", e, path, advice.getStore().getKey(), e.getMessage());
throw new WebdavException("Failed to write file: " + resourceUri);
} finally {
closeQuietly(writer);
}
}
use of net.sf.webdav.exceptions.WebdavException in project indy by Commonjava.
the class SettingsSubStore method getSettingsTemplate.
private synchronized SettingsTemplate getSettingsTemplate(final URIMatcher matcher) throws WebdavException {
final StoreKey key = matcher.getStoreKey();
ArtifactStore store;
try {
store = indy.getArtifactStore(key);
} catch (final IndyDataException e) {
logger.error(String.format("Failed to retrieve artifact store: %s. Reason: %s", key, e.getMessage()), e);
throw new WebdavException("Failed to retrieve length for: " + matcher.getURI());
}
if (store == null) {
throw new WebdavException("Cannot retrieve ArtifactStore: " + key);
}
StorageAdvice advice;
try {
advice = advisor.getStorageAdvice(store);
} catch (final DotMavenException e) {
logger.error(String.format("Failed to retrieve storage advice for: %s. Reason: %s", key, e.getMessage()), e);
throw new WebdavException("Failed to retrieve length for: " + matcher.getURI());
}
return new SettingsTemplate(key, advice, requestInfo, templatingEngine);
}
use of net.sf.webdav.exceptions.WebdavException in project indy by Commonjava.
the class SettingsTemplate method formatSettings.
private void formatSettings() throws WebdavException {
if (content != null) {
return;
}
final String name = key.getName();
final StoreType type = key.getType();
final StringBuilder url = new StringBuilder();
url.append(requestInfo.getBaseUrl());
logger.debug("settings base-url is: '{}'", url);
if (url.charAt(url.length() - 1) != '/') {
url.append('/');
}
url.append("api/");
url.append(type.singularEndpointName()).append('/').append(name);
try {
final Map<String, Object> params = new HashMap<String, Object>();
params.put(TYPE_KEY, type.singularEndpointName());
params.put(NAME_KEY, name);
params.put(URL_KEY, url);
params.put(RELEASES_KEY, advice.isReleasesAllowed());
params.put(SNAPSHOTS_KEY, advice.isSnapshotsAllowed());
params.put(DEPLOY_ENABLED_KEY, advice.isDeployable());
final String rendered = templateEngine.render(TEMPLATE, params);
content = rendered.getBytes("UTF-8");
} catch (final UnsupportedEncodingException e) {
throw new IllegalStateException("Cannot find encoding for UTF-8!", e);
} catch (final IndyGroovyException e) {
throw new WebdavException(String.format("Failed to render settings.xml template for: '%s'. Reason: %s", key, e.getMessage()), e);
}
}
Aggregations