Search in sources :

Example 31 with MultipartRequestEntity

use of org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity in project sling by apache.

the class SlingPostDeployMethod method undeploy.

@Override
public void undeploy(String targetURL, File file, String bundleSymbolicName, DeployContext context) throws MojoExecutionException {
    final PostMethod post = new PostMethod(getURLWithFilename(targetURL, file.getName()));
    try {
        // Add SlingPostServlet operation flag for deleting the content
        Part[] parts = new Part[1];
        parts[0] = new StringPart(":operation", "delete");
        post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
        // Request JSON response from Sling instead of standard HTML
        post.setRequestHeader("Accept", JSON_MIME_TYPE);
        int status = context.getHttpClient().executeMethod(post);
        if (status == HttpStatus.SC_OK) {
            context.getLog().info("Bundle uninstalled");
        } else {
            context.getLog().error("Uninstall failed, cause: " + HttpStatus.getStatusText(status));
        }
    } catch (Exception ex) {
        throw new MojoExecutionException("Uninstall from " + targetURL + " failed, cause: " + ex.getMessage(), ex);
    } finally {
        post.releaseConnection();
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) PostMethod(org.apache.commons.httpclient.methods.PostMethod) Part(org.apache.commons.httpclient.methods.multipart.Part) StringPart(org.apache.commons.httpclient.methods.multipart.StringPart) FilePart(org.apache.commons.httpclient.methods.multipart.FilePart) StringPart(org.apache.commons.httpclient.methods.multipart.StringPart) MultipartRequestEntity(org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Aggregations

MultipartRequestEntity (org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity)31 Part (org.apache.commons.httpclient.methods.multipart.Part)29 PostMethod (org.apache.commons.httpclient.methods.PostMethod)27 FilePart (org.apache.commons.httpclient.methods.multipart.FilePart)26 StringPart (org.apache.commons.httpclient.methods.multipart.StringPart)24 HttpClient (org.apache.commons.httpclient.HttpClient)15 IOException (java.io.IOException)11 File (java.io.File)9 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)6 ByteArrayPartSource (org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource)5 HttpMethodParams (org.apache.commons.httpclient.params.HttpMethodParams)5 HttpState (org.apache.commons.httpclient.HttpState)4 FilePartSource (org.apache.commons.httpclient.methods.multipart.FilePartSource)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 ServiceException (com.zimbra.common.service.ServiceException)3 Element (com.zimbra.common.soap.Element)3 SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)3 Map (java.util.Map)3 HeaderElement (org.apache.commons.httpclient.HeaderElement)3