Search in sources :

Example 11 with DefaultVariableResolver

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

the class MemoryUsagePanel method renderContent.

@SuppressWarnings("unchecked")
@Override
protected void renderContent(HttpServletRequest req, HttpServletResponse res) throws IOException {
    final PrintWriter pw = res.getWriter();
    final StringBuilder statusBuf = new StringBuilder(1024);
    statusBuf.append('{');
    final StringBuilder filesBuf = new StringBuilder(1024);
    filesBuf.append('[');
    final File[] files = support.getDumpFiles();
    if (files != null) {
        long totalSize = 0;
        for (File file : files) {
            filesBuf.append('{');
            filesBuf.append("'name':'").append(file.getName());
            filesBuf.append("',").append("'date':").append(file.lastModified());
            support.formatNumber(filesBuf, "size", file.length());
            filesBuf.append("},");
            totalSize += file.length();
        }
        statusBuf.append("'files':").append(files.length);
        support.formatNumber(statusBuf, "total", totalSize);
    } else {
        statusBuf.append("'files':0,'total':0");
    }
    filesBuf.append(']');
    statusBuf.append('}');
    JsonPrintHelper jph = new JsonPrintHelper();
    support.printOverallMemory(jph);
    DefaultVariableResolver resolver = (DefaultVariableResolver) WebConsoleUtil.getVariableResolver(req);
    resolver.put("__files__", filesBuf.toString());
    resolver.put("__status__", statusBuf.toString());
    resolver.put("__threshold__", String.valueOf(support.getThreshold()));
    resolver.put("__interval__", String.valueOf(support.getInterval()));
    resolver.put("__overall__", jph.getString());
    resolver.put("__pools__", support.getMemoryPoolsJson());
    String template = readTemplateFile("/templates/memoryusage.html");
    pw.println(template);
}
Also used : DefaultVariableResolver(org.apache.felix.webconsole.DefaultVariableResolver) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 12 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 IOException {
    // prepare variables
    DefaultVariableResolver vars = ((DefaultVariableResolver) WebConsoleUtil.getVariableResolver(request));
    // $NON-NLS-1$
    vars.put("__data__", getData(request));
    response.getWriter().print(TEMPLATE);
}
Also used : DefaultVariableResolver(org.apache.felix.webconsole.DefaultVariableResolver)

Example 13 with DefaultVariableResolver

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

the class ScriptConsolePlugin method renderContent.

@SuppressWarnings("unchecked")
@Override
protected void renderContent(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    final PrintWriter pw = response.getWriter();
    DefaultVariableResolver varResolver = (DefaultVariableResolver) WebConsoleUtil.getVariableResolver(request);
    varResolver.put("__scriptConfig__", getScriptConfig());
    pw.println(TEMPLATE);
}
Also used : DefaultVariableResolver(org.apache.felix.webconsole.DefaultVariableResolver)

Example 14 with DefaultVariableResolver

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

the class IPOJOPlugin method renderContent.

/**
 * This methods is called by the web console when the plugin is required.
 * This methods writes the corresponding page (loads template and set variables).
 * @param request the request
 * @param response the response
 * @throws ServletException something bad happened
 * @throws IOException something bad happened
 * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#renderContent(
 *  javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
@Override
protected void renderContent(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // get request info from request attribute
    final RequestInfo reqInfo = new RequestInfo(request);
    // prepare variables
    DefaultVariableResolver vars = ((DefaultVariableResolver) WebConsoleUtil.getVariableResolver(request));
    if (reqInfo.instances) {
        // Instance
        if (reqInfo.name == null) {
            // All
            response.getWriter().print(INSTANCES);
        } else {
            // Specific
            // Inject the name variable.
            vars.put("name", reqInfo.name);
            response.getWriter().print(INSTANCE_DETAILS);
        }
    } else if (reqInfo.factories) {
        // Factory
        if (reqInfo.name == null) {
            // All
            response.getWriter().print(FACTORIES);
        } else {
            // Specific
            // Inject the name variable.
            vars.put("name", reqInfo.name);
            response.getWriter().print(FACTORY_DETAILS);
        }
    } else if (reqInfo.handlers) {
        // Handlers
        response.getWriter().print(HANDLERS);
    // No detailed view for handlers.
    } else {
        // Default
        response.getWriter().print(INSTANCES);
    }
}
Also used : DefaultVariableResolver(org.apache.felix.webconsole.DefaultVariableResolver)

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