use of org.apache.commons.httpclient.methods.multipart.StringPart in project sling by apache.
the class FelixPostDeployMethod method deploy.
@Override
public void deploy(String targetURL, File file, String bundleSymbolicName, DeployContext context) throws MojoExecutionException {
// append pseudo path after root URL to not get redirected for nothing
final PostMethod filePost = new PostMethod(targetURL + "/install");
try {
// set referrer
filePost.setRequestHeader("referer", "about:blank");
List<Part> partList = new ArrayList<Part>();
partList.add(new StringPart("action", "install"));
partList.add(new StringPart("_noredir_", "_noredir_"));
partList.add(new FilePart("bundlefile", new FilePartSource(file.getName(), file)));
partList.add(new StringPart("bundlestartlevel", context.getBundleStartLevel()));
if (context.isBundleStart()) {
partList.add(new StringPart("bundlestart", "start"));
}
if (context.isRefreshPackages()) {
partList.add(new StringPart("refreshPackages", "true"));
}
Part[] parts = partList.toArray(new Part[partList.size()]);
filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));
int status = context.getHttpClient().executeMethod(filePost);
if (status == HttpStatus.SC_OK) {
context.getLog().info("Bundle installed");
} else {
String msg = "Installation failed, cause: " + HttpStatus.getStatusText(status);
if (context.isFailOnError()) {
throw new MojoExecutionException(msg);
} else {
context.getLog().error(msg);
}
}
} catch (Exception ex) {
throw new MojoExecutionException("Installation on " + targetURL + " failed, cause: " + ex.getMessage(), ex);
} finally {
filePost.releaseConnection();
}
}
use of org.apache.commons.httpclient.methods.multipart.StringPart 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();
}
}
Aggregations