Search in sources :

Example 1 with DefaultVariableResolver

use of org.apache.felix.webconsole.DefaultVariableResolver in project felix by apache.

the class LicenseServlet method renderContent.

/**
 * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#renderContent(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
protected void renderContent(HttpServletRequest request, HttpServletResponse res) throws IOException {
    Bundle[] bundles = getBundleContext().getBundles();
    Util.sort(bundles, request.getLocale());
    // prepare variables
    DefaultVariableResolver vars = ((DefaultVariableResolver) WebConsoleUtil.getVariableResolver(request));
    vars.put("__data__", getBundleData(bundles, request.getLocale()));
    res.getWriter().print(TEMPLATE);
}
Also used : Bundle(org.osgi.framework.Bundle) DefaultVariableResolver(org.apache.felix.webconsole.DefaultVariableResolver)

Example 2 with DefaultVariableResolver

use of org.apache.felix.webconsole.DefaultVariableResolver in project felix by apache.

the class VMStatPlugin 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 IOException {
    String body;
    if (request.getAttribute(ATTR_TERMINATED) != null) {
        Object restart = request.getAttribute(PARAM_SHUTDOWN_TYPE);
        if ((restart instanceof Boolean) && ((Boolean) restart).booleanValue()) {
            body = TPL_VM_RESTART;
        } else {
            body = TPL_VM_STOP;
        }
        response.getWriter().print(body);
        return;
    }
    body = TPL_VM_MAIN;
    long freeMem = Runtime.getRuntime().freeMemory() / 1024;
    long totalMem = Runtime.getRuntime().totalMemory() / 1024;
    long usedMem = totalMem - freeMem;
    boolean shutdownTimer = request.getParameter(PARAM_SHUTDOWN_TIMER) != null;
    String shutdownType = request.getParameter(PARAM_SHUTDOWN_TYPE);
    if (shutdownType == null)
        shutdownType = "";
    DateFormat format = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, request.getLocale());
    final String startTime = format.format(new Date(startDate));
    final String upTime = formatPeriod(System.currentTimeMillis() - startDate);
    StringWriter json = new StringWriter();
    JSONWriter jw = new JSONWriter(json);
    jw.object();
    jw.key("systemStartLevel").value(getStartLevel().getStartLevel());
    jw.key("bundleStartLevel").value(getStartLevel().getInitialBundleStartLevel());
    jw.key("lastStarted").value(startTime);
    jw.key("upTime").value(upTime);
    jw.key("runtime").value(sysProp("java.runtime.name") + "(build " + sysProp("java.runtime.version") + ")");
    jw.key("jvm").value(sysProp("java.vm.name") + "(build " + sysProp("java.vm.version") + ", " + sysProp("java.vm.info") + ")");
    jw.key("shutdownTimer").value(shutdownTimer);
    jw.key("mem_total").value(totalMem);
    jw.key("mem_free").value(freeMem);
    jw.key("mem_used").value(usedMem);
    jw.key("shutdownType").value(shutdownType);
    // only add the processors if the number is available
    final int processors = getAvailableProcessors();
    if (processors > 0) {
        jw.key("processors").value(processors);
    }
    jw.endObject();
    jw.flush();
    DefaultVariableResolver vars = ((DefaultVariableResolver) WebConsoleUtil.getVariableResolver(request));
    vars.put("startData", json.toString());
    response.getWriter().print(body);
}
Also used : JSONWriter(org.apache.felix.utils.json.JSONWriter) StringWriter(java.io.StringWriter) DefaultVariableResolver(org.apache.felix.webconsole.DefaultVariableResolver) DateFormat(java.text.DateFormat) Date(java.util.Date)

Example 3 with DefaultVariableResolver

use of org.apache.felix.webconsole.DefaultVariableResolver in project felix by apache.

the class WebConsolePlugin method renderContent.

@Override
@SuppressWarnings("unchecked")
protected void renderContent(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    RequestInfo reqInfo = getRequestInfo(req);
    StringWriter w = new StringWriter();
    PrintWriter w2 = new PrintWriter(w);
    renderResult(w2, reqInfo);
    // prepare variables
    DefaultVariableResolver vars = ((DefaultVariableResolver) WebConsoleUtil.getVariableResolver(req));
    vars.put("__data__", w.toString());
    res.getWriter().print(template);
}
Also used : StringWriter(java.io.StringWriter) DefaultVariableResolver(org.apache.felix.webconsole.DefaultVariableResolver) PrintWriter(java.io.PrintWriter)

Example 4 with DefaultVariableResolver

use of org.apache.felix.webconsole.DefaultVariableResolver in project felix by apache.

the class ServicesServlet 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 IOException {
    // get request info from request attribute
    final RequestInfo reqInfo = getRequestInfo(request);
    final String appRoot = (String) request.getAttribute(WebConsoleConstants.ATTR_APP_ROOT);
    StringWriter w = new StringWriter();
    final String filter = request.getParameter(FILTER_PARAM);
    writeJSON(w, reqInfo.service, request.getLocale(), filter);
    // prepare variables
    DefaultVariableResolver vars = ((DefaultVariableResolver) WebConsoleUtil.getVariableResolver(request));
    vars.put("bundlePath", appRoot + "/" + BundlesServlet.NAME + "/");
    vars.put("drawDetails", String.valueOf(reqInfo.serviceRequested));
    vars.put("__data__", w.toString());
    vars.put("filter", filter == null ? "" : WebConsoleUtil.escapeHtml(filter));
    response.getWriter().print(TEMPLATE);
}
Also used : StringWriter(java.io.StringWriter) DefaultVariableResolver(org.apache.felix.webconsole.DefaultVariableResolver)

Example 5 with DefaultVariableResolver

use of org.apache.felix.webconsole.DefaultVariableResolver 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)

Aggregations

DefaultVariableResolver (org.apache.felix.webconsole.DefaultVariableResolver)14 StringWriter (java.io.StringWriter)7 PrintWriter (java.io.PrintWriter)5 JSONWriter (org.apache.felix.utils.json.JSONWriter)3 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)2 File (java.io.File)1 DateFormat (java.text.DateFormat)1 Date (java.util.Date)1 Locale (java.util.Locale)1 Bundle (org.osgi.framework.Bundle)1 DeploymentAdmin (org.osgi.service.deploymentadmin.DeploymentAdmin)1 DeploymentPackage (org.osgi.service.deploymentadmin.DeploymentPackage)1