use of org.apache.commons.httpclient.HttpException in project sling by apache.
the class FsMountHelper method addConfiguration.
/**
* Add a new configuration for the file system provider
*/
private void addConfiguration(final String targetUrl, FsResourceConfiguration cfg) throws MojoExecutionException {
final String postUrl = targetUrl + "/configMgr/" + FS_FACTORY;
final PostMethod post = new PostMethod(postUrl);
post.addParameter("apply", "true");
post.addParameter("factoryPid", FS_FACTORY);
post.addParameter("pid", "[Temporary PID replaced by real PID upon save]");
Map<String, String> props = toMap(cfg);
for (Map.Entry<String, String> entry : props.entrySet()) {
post.addParameter(entry.getKey(), entry.getValue());
}
post.addParameter("propertylist", StringUtils.join(props.keySet(), ","));
try {
final int status = httpClient.executeMethod(post);
// we get a moved temporarily back from the configMgr plugin
if (status == HttpStatus.SC_MOVED_TEMPORARILY || status == HttpStatus.SC_OK) {
log.info("Configuration created.");
} else {
log.error("Configuration on " + postUrl + " failed, cause: " + HttpStatus.getStatusText(status));
}
} catch (HttpException ex) {
throw new MojoExecutionException("Configuration on " + postUrl + " failed, cause: " + ex.getMessage(), ex);
} catch (IOException ex) {
throw new MojoExecutionException("Configuration on " + postUrl + " failed, cause: " + ex.getMessage(), ex);
} finally {
post.releaseConnection();
}
}
Aggregations