Search in sources :

Example 1 with DeploymentAdmin

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);
}
Also used : DeploymentAdmin(org.osgi.service.deploymentadmin.DeploymentAdmin) JSONWriter(org.apache.felix.utils.json.JSONWriter) StringWriter(java.io.StringWriter) DefaultVariableResolver(org.apache.felix.webconsole.DefaultVariableResolver) DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) PrintWriter(java.io.PrintWriter)

Example 2 with DeploymentAdmin

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);
}
Also used : DeploymentAdmin(org.osgi.service.deploymentadmin.DeploymentAdmin) ServletException(javax.servlet.ServletException) FileItem(org.apache.commons.fileupload.FileItem) DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) Map(java.util.Map) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 3 with DeploymentAdmin

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);
        }
    }
}
Also used : DeploymentAdmin(org.osgi.service.deploymentadmin.DeploymentAdmin) Hashtable(java.util.Hashtable)

Aggregations

DeploymentAdmin (org.osgi.service.deploymentadmin.DeploymentAdmin)3 PrintWriter (java.io.PrintWriter)2 DeploymentPackage (org.osgi.service.deploymentadmin.DeploymentPackage)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 Hashtable (java.util.Hashtable)1 Map (java.util.Map)1 ServletException (javax.servlet.ServletException)1 FileItem (org.apache.commons.fileupload.FileItem)1 JSONWriter (org.apache.felix.utils.json.JSONWriter)1 DefaultVariableResolver (org.apache.felix.webconsole.DefaultVariableResolver)1