use of org.osgi.service.deploymentadmin.DeploymentAdmin in project felix by apache.
the class WebConsolePlugin method renderContent.
/**
* @see org.apache.felix.webconsole.AbstractWebConsolePlugin#renderContent(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
protected void renderContent(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
final DeploymentAdmin admin = (DeploymentAdmin) adminTracker.getService();
StringWriter w = new StringWriter();
PrintWriter w2 = new PrintWriter(w);
JSONWriter jw = new JSONWriter(w2);
jw.object();
if (null == admin) {
// $NON-NLS-1$
jw.key("error");
jw.value(true);
} else {
final DeploymentPackage[] packages = admin.listDeploymentPackages();
// $NON-NLS-1$
jw.key("data");
jw.array();
for (int i = 0; i < packages.length; i++) {
packageInfoJson(jw, packages[i]);
}
jw.endArray();
}
jw.endObject();
// prepare variables
DefaultVariableResolver vars = ((DefaultVariableResolver) WebConsoleUtil.getVariableResolver(request));
// $NON-NLS-1$
vars.put("__data__", w.toString());
response.getWriter().print(TEMPLATE);
}
use of org.osgi.service.deploymentadmin.DeploymentAdmin in project felix by apache.
the class WebConsolePlugin method doPost.
/**
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// get the uploaded data
final String action = WebConsoleUtil.getParameter(req, Util.PARAM_ACTION);
if (ACTION_DEPLOY.equals(action)) {
Map params = (Map) req.getAttribute(AbstractWebConsolePlugin.ATTR_FILEUPLOAD);
if (params != null) {
final FileItem pck = getFileItem(params, PARAMETER_PCK_FILE, false);
final DeploymentAdmin admin = (DeploymentAdmin) adminTracker.getService();
if (admin != null) {
try {
admin.installDeploymentPackage(pck.getInputStream());
final String uri = req.getRequestURI();
resp.sendRedirect(uri);
return;
} catch (/*Deployment*/
Exception e) {
throw new ServletException("Unable to deploy package.", e);
}
}
}
throw new ServletException("Upload file or deployment admin missing.");
} else if (ACTION_UNINSTALL.equals(action)) {
final String pckId = req.getPathInfo().substring(req.getPathInfo().lastIndexOf('/') + 1);
if (pckId != null && pckId.length() > 0) {
final DeploymentAdmin admin = (DeploymentAdmin) adminTracker.getService();
if (admin != null) {
try {
final DeploymentPackage pck = admin.getDeploymentPackage(pckId);
if (pck != null) {
pck.uninstall();
}
} catch (/*Deployment*/
Exception e) {
throw new ServletException("Unable to undeploy package.", e);
}
}
}
final PrintWriter pw = resp.getWriter();
pw.println("{ \"reload\":true }");
return;
}
throw new ServletException("Unknown action: " + action);
}
use of org.osgi.service.deploymentadmin.DeploymentAdmin in project sling by apache.
the class Activator method getAdmin.
private void getAdmin() {
this.deploymentAdminReference = this.bundleContext.getServiceReference(DEPLOYMENT_ADMIN);
if (this.deploymentAdminReference != null) {
final DeploymentAdmin deploymentAdmin = (DeploymentAdmin) this.bundleContext.getService(this.deploymentAdminReference);
if (deploymentAdmin == null) {
this.deploymentAdminReference = null;
} else {
final Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Installer Support for Deployment Packages");
props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
this.serviceReg = this.bundleContext.registerService(new String[] { ResourceTransformer.class.getName(), InstallTaskFactory.class.getName() }, new DeploymentPackageInstaller(deploymentAdmin), props);
}
}
}
Aggregations