You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2017/01/24 19:26:00 UTC
svn commit: r1780102 [2/2] - in /felix/trunk/webconsole: ./
src/main/java/org/apache/felix/webconsole/internal/
src/main/java/org/apache/felix/webconsole/internal/compendium/
src/main/java/org/apache/felix/webconsole/internal/configuration/
src/main/ja...
Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java?rev=1780102&r1=1780101&r2=1780102&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java Tue Jan 24 19:26:00 2017
@@ -20,6 +20,7 @@ package org.apache.felix.webconsole.inte
import java.io.IOException;
+import java.io.StringWriter;
import java.text.DateFormat;
import java.text.MessageFormat;
import java.util.Date;
@@ -32,8 +33,7 @@ import org.apache.felix.webconsole.Defau
import org.apache.felix.webconsole.SimpleWebConsolePlugin;
import org.apache.felix.webconsole.WebConsoleUtil;
import org.apache.felix.webconsole.internal.OsgiManagerPlugin;
-import org.json.JSONException;
-import org.json.JSONObject;
+import org.apache.felix.webconsole.json.JSONWriter;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.service.startlevel.StartLevel;
@@ -86,7 +86,7 @@ public class VMStatPlugin extends Simple
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
protected void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException,
- IOException
+ IOException
{
final String action = request.getParameter( "action"); //$NON-NLS-1$
@@ -202,35 +202,35 @@ public class VMStatPlugin extends Simple
final String startTime = format.format( new Date( startDate ) );
final String upTime = formatPeriod( System.currentTimeMillis() - startDate );
- JSONObject json = new JSONObject();
- try
- {
- json.put( "systemStartLevel", getStartLevel().getStartLevel() );
- json.put( "bundleStartLevel", getStartLevel().getInitialBundleStartLevel() );
- json.put( "lastStarted", startTime );
- json.put( "upTime", upTime );
- json.put( "runtime", sysProp( "java.runtime.name" ) + "(build "
+ 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" ) + ")" );
- json.put( "jvm", sysProp( "java.vm.name" ) + "(build " + sysProp( "java.vm.version" )
- + ", " + sysProp( "java.vm.info" ) + ")" );
- json.put( "shutdownTimer", shutdownTimer );
- json.put( "mem_total", totalMem );
- json.put( "mem_free", freeMem );
- json.put( "mem_used", usedMem );
- json.put( "shutdownType", shutdownType );
-
- // only add the processors if the number is available
- final int processors = getAvailableProcessors();
- if ( processors > 0 )
- {
- json.put( "processors", processors );
- }
- }
- catch ( JSONException e )
+ 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 )
{
- throw new IOException( e.toString() );
+ jw.key( "processors").value(processors );
}
+ jw.endObject();
+
+ jw.flush();
+
DefaultVariableResolver vars = ( ( DefaultVariableResolver ) WebConsoleUtil.getVariableResolver( request ) );
vars.put( "startData", json.toString() );
@@ -255,9 +255,9 @@ public class VMStatPlugin extends Simple
final Long hours = new Long( period / 1000 / 60 / 60 % 24 );
final Long days = new Long( period / 1000 / 60 / 60 / 24 );
return MessageFormat.format(
- "{0,number} '${vmstat.upTime.format.days}' {1,number,00}:{2,number,00}:{3,number,00}.{4,number,000}",
- new Object[]
- { days, hours, mins, secs, msecs } );
+ "{0,number} '${vmstat.upTime.format.days}' {1,number,00}:{2,number,00}:{3,number,00}.{4,number,000}",
+ new Object[]
+ { days, hours, mins, secs, msecs } );
}
Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/json/JSONWriter.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/json/JSONWriter.java?rev=1780102&r1=1780101&r2=1780102&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/json/JSONWriter.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/json/JSONWriter.java Tue Jan 24 19:26:00 2017
@@ -20,6 +20,10 @@ package org.apache.felix.webconsole.json
import java.io.IOException;
import java.io.Writer;
+import java.lang.reflect.Array;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
/**
* Simple JSON writer to be used on top of a {@link Writer}.
@@ -137,6 +141,32 @@ public class JSONWriter
this.pw.write(str);
}
}
+ else if ( value instanceof Map)
+ {
+ this.comma = false;
+ this.object();
+
+ final Map map = (Map)value;
+ final Iterator iter = map.entrySet().iterator();
+ while ( iter.hasNext() )
+ {
+ Map.Entry entry = (Entry) iter.next();
+ this.key((String)entry.getKey());
+ this.value(entry.getValue());
+ }
+ this.endObject();
+ }
+ else if ( value.getClass().isArray() )
+ {
+ this.comma = false;
+ this.array();
+ for(int i=0;i<Array.getLength(value);i++)
+ {
+ final Object val = Array.get(value, i);
+ value(val);
+ }
+ this.endArray();
+ }
else
{
quote(value.toString());