Search in sources :

Example 61 with HttpException

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();
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HttpException (org.apache.commons.httpclient.HttpException)61 IOException (java.io.IOException)55 HttpClient (org.apache.commons.httpclient.HttpClient)34 GetMethod (org.apache.commons.httpclient.methods.GetMethod)31 HttpMethod (org.apache.commons.httpclient.HttpMethod)22 InputStream (java.io.InputStream)15 Header (org.apache.commons.httpclient.Header)12 PostMethod (org.apache.commons.httpclient.methods.PostMethod)12 DefaultHttpMethodRetryHandler (org.apache.commons.httpclient.DefaultHttpMethodRetryHandler)9 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)8 DeleteMethod (org.apache.commons.httpclient.methods.DeleteMethod)6 Test (org.junit.Test)5 ServiceException (com.zimbra.common.service.ServiceException)4 Server (com.zimbra.cs.account.Server)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 MultipartRequestEntity (org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 XStream (com.thoughtworks.xstream.XStream)3