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 [1/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...

Author: cziegeler
Date: Tue Jan 24 19:26:00 2017
New Revision: 1780102

URL: http://svn.apache.org/viewvc?rev=1780102&view=rev
Log:
FELIX-5504 : Switch from org.json to new simple json writer

Modified:
    felix/trunk/webconsole/changelog.txt
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/LogServlet.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigAdminSupport.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/MetaTypeServiceSupport.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/MetaTypeSupport.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/json/JSONWriter.java

Modified: felix/trunk/webconsole/changelog.txt
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/changelog.txt?rev=1780102&r1=1780101&r2=1780102&view=diff
==============================================================================
--- felix/trunk/webconsole/changelog.txt (original)
+++ felix/trunk/webconsole/changelog.txt Tue Jan 24 19:26:00 2017
@@ -2,6 +2,7 @@ Changes from 4.2.18 to 4.3.0
 ----------------------------
 ** Improvement
     * [FELIX-5503] - Add simple json writer
+    * [FELIX-5504] - Switch from org.json to new simple json writer
 
 
 Changes from 4.2.16 to 4.2.18

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java?rev=1780102&r1=1780101&r2=1780102&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java Tue Jan 24 19:26:00 2017
@@ -23,8 +23,6 @@ import java.util.Comparator;
 import java.util.Enumeration;
 import java.util.Locale;
 
-import org.json.JSONException;
-import org.json.JSONWriter;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
 import org.osgi.framework.Version;
@@ -37,7 +35,7 @@ import org.osgi.framework.Version;
 public class Util
 {
 
-    // FIXME: from the constants below only PARAM_ACTION is used, consider removeal of others?
+    // FIXME: from the constants below only PARAM_ACTION is used, consider removal of others?
 
     /** web apps subpage */
     public static final String PAGE_WEBAPPS = "/webapps";
@@ -103,12 +101,12 @@ public class Util
      */
     public static String getHeaderValue( Bundle bundle, String headerName )
     {
-       Object value = bundle.getHeaders().get(headerName);
-       if ( value != null )
-       {
-           return value.toString();
-       }
-       return "";
+        Object value = bundle.getHeaders().get(headerName);
+        if ( value != null )
+        {
+            return value.toString();
+        }
+        return "";
     }
 
     /**
@@ -244,27 +242,4 @@ public class Util
             return 1;
         }
     }
-
-    /**
-     * Writes a key-value pair in a JSON writer. Write is performed only if both key and
-     * value are not null.
-     *
-     * @param jw the writer, where to write the data
-     * @param key the key value, stored under 'key'
-     * @param value the value stored under 'value'
-     * @throws JSONException if the value cannot be serialized.
-     */
-    public static final void keyVal(JSONWriter jw, String key, Object value)
-        throws JSONException
-    {
-        if (key != null && value != null)
-        {
-            jw.object();
-            jw.key("key"); //$NON-NLS-1$
-            jw.value(key);
-            jw.key("value"); //$NON-NLS-1$
-            jw.value(value);
-            jw.endObject();
-        }
-    }
 }
\ No newline at end of file

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/LogServlet.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/LogServlet.java?rev=1780102&r1=1780101&r2=1780102&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/LogServlet.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/LogServlet.java Tue Jan 24 19:26:00 2017
@@ -30,8 +30,7 @@ import javax.servlet.http.HttpServletRes
 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.JSONWriter;
+import org.apache.felix.webconsole.json.JSONWriter;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
@@ -87,42 +86,34 @@ public class LogServlet extends SimpleWe
     {
         // create status line
         final LogReaderService logReaderService = ( LogReaderService ) this.getService( LogReaderService.class
-            .getName() );
+                .getName() );
 
         JSONWriter jw = new JSONWriter( pw );
-        try
-        {
-            jw.object();
+        jw.object();
 
-            jw.key( "status" ); //$NON-NLS-1$
-            jw.value( logReaderService == null ? Boolean.FALSE : Boolean.TRUE );
+        jw.key( "status" ); //$NON-NLS-1$
+        jw.value( logReaderService == null ? Boolean.FALSE : Boolean.TRUE );
 
-            jw.key( "data" ); //$NON-NLS-1$
-            jw.array();
+        jw.key( "data" ); //$NON-NLS-1$
+        jw.array();
 
-            if ( logReaderService != null )
-            {
-                int index = 0;
-                for ( Enumeration logEntries = logReaderService.getLog(); logEntries.hasMoreElements()
+        if ( logReaderService != null )
+        {
+            int index = 0;
+            for ( Enumeration logEntries = logReaderService.getLog(); logEntries.hasMoreElements()
                     && index < MAX_LOGS; )
+            {
+                LogEntry nextLog = ( LogEntry ) logEntries.nextElement();
+                if ( nextLog.getLevel() <= minLogLevel )
                 {
-                    LogEntry nextLog = ( LogEntry ) logEntries.nextElement();
-                    if ( nextLog.getLevel() <= minLogLevel )
-                    {
-                        logJson( jw, nextLog, index++, traces );
-                    }
+                    logJson( jw, nextLog, index++, traces );
                 }
             }
+        }
 
-            jw.endArray();
-
-            jw.endObject();
+        jw.endArray();
 
-        }
-        catch ( JSONException je )
-        {
-            throw new IOException( je.toString() );
-        }
+        jw.endObject();
 
     }
 
@@ -131,7 +122,7 @@ public class LogServlet extends SimpleWe
      * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
      */
     protected void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException,
-        IOException
+    IOException
     {
         final int minLevel = WebConsoleUtil.getParameterInt( request, "minLevel", LogService.LOG_DEBUG ); //$NON-NLS-1$
         final String info = request.getPathInfo();
@@ -157,7 +148,7 @@ public class LogServlet extends SimpleWe
     }
 
 
-    private static final void logJson( JSONWriter jw, LogEntry info, int index, boolean traces ) throws JSONException
+    private static final void logJson( JSONWriter jw, LogEntry info, int index, boolean traces ) throws IOException
     {
         jw.object();
         jw.key( "id" ); //$NON-NLS-1$
@@ -209,15 +200,15 @@ public class LogServlet extends SimpleWe
     {
         switch ( level )
         {
-            case LogService.LOG_INFO:
-                return "INFO"; //$NON-NLS-1$
-            case LogService.LOG_WARNING:
-                return "WARNING"; //$NON-NLS-1$
-            case LogService.LOG_ERROR:
-                return "ERROR"; //$NON-NLS-1$
-            case LogService.LOG_DEBUG:
-            default:
-                return "DEBUG"; //$NON-NLS-1$
+        case LogService.LOG_INFO:
+            return "INFO"; //$NON-NLS-1$
+        case LogService.LOG_WARNING:
+            return "WARNING"; //$NON-NLS-1$
+        case LogService.LOG_ERROR:
+            return "ERROR"; //$NON-NLS-1$
+        case LogService.LOG_DEBUG:
+        default:
+            return "DEBUG"; //$NON-NLS-1$
         }
     }
 

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigAdminSupport.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigAdminSupport.java?rev=1780102&r1=1780101&r2=1780102&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigAdminSupport.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigAdminSupport.java Tue Jan 24 19:26:00 2017
@@ -44,9 +44,7 @@ import java.util.regex.Pattern;
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.felix.webconsole.internal.Util;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.json.JSONWriter;
+import org.apache.felix.webconsole.json.JSONWriter;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -165,7 +163,7 @@ class ConfigAdminSupport
     }
 
     String applyConfiguration( HttpServletRequest request, String pid )
-        throws IOException
+            throws IOException
     {
         if ( request.getParameter( ConfigManager.ACTION_DELETE ) != null ) //$NON-NLS-1$
         {
@@ -205,10 +203,10 @@ class ConfigAdminSupport
             {
                 String propName = propTokens.nextToken();
                 String paramName = "action".equals(propName) //$NON-NLS-1$
-                    || ConfigManager.ACTION_DELETE.equals(propName)
-                    || ConfigManager.ACTION_APPLY.equals(propName)
-                    || ConfigManager.PROPERTY_LIST.equals(propName)
-                    ? '$' + propName : propName;
+                        || ConfigManager.ACTION_DELETE.equals(propName)
+                        || ConfigManager.ACTION_APPLY.equals(propName)
+                        || ConfigManager.PROPERTY_LIST.equals(propName)
+                        ? '$' + propName : propName;
                 propsToKeep.add(propName);
 
                 PropertyDescriptor ad = (PropertyDescriptor) adMap.get( propName );
@@ -222,11 +220,11 @@ class ConfigAdminSupport
                 int attributeType = MetaTypeSupport.getAttributeType( ad );
 
                 if ( ad == null
-                    || ( ad.getCardinality() == 0 && ( attributeType == AttributeDefinition.STRING || attributeType == MetaTypeServiceSupport.ATTRIBUTE_TYPE_PASSWORD ) ) )
+                        || ( ad.getCardinality() == 0 && ( attributeType == AttributeDefinition.STRING || attributeType == MetaTypeServiceSupport.ATTRIBUTE_TYPE_PASSWORD ) ) )
                 {
                     String prop = request.getParameter( paramName );
                     if ( prop != null
-                        && ( attributeType != MetaTypeSupport.ATTRIBUTE_TYPE_PASSWORD || !MetaTypeSupport.PASSWORD_PLACEHOLDER_VALUE.equals( prop ) ) )
+                            && ( attributeType != MetaTypeSupport.ATTRIBUTE_TYPE_PASSWORD || !MetaTypeSupport.PASSWORD_PLACEHOLDER_VALUE.equals( prop ) ) )
                     {
                         props.put( propName, prop );
                     }
@@ -346,7 +344,7 @@ class ConfigAdminSupport
 
 
     void printConfigurationJson( PrintWriter pw, String pid, Configuration config, String pidFilter,
-        String locale )
+            String locale )
     {
 
         JSONWriter result = new JSONWriter( pw );
@@ -369,7 +367,7 @@ class ConfigAdminSupport
 
 
     void configForm( JSONWriter json, String pid, Configuration config, String pidFilter, String locale )
-        throws JSONException
+            throws IOException
     {
 
         json.key( ConfigManager.PID );
@@ -415,7 +413,7 @@ class ConfigAdminSupport
         {
             json.key( "title" ).value( pid ); //$NON-NLS-1$
             json.key( "description" ).value( //$NON-NLS-1$
-                "This form is automatically generated from existing properties because no property "
+                    "This form is automatically generated from existing properties because no property "
                     + "descriptors are available for this configuration. This may be cause by the absence "
                     + "of the OSGi Metatype Service or the absence of a MetaType descriptor for this configuration." );
 
@@ -426,9 +424,9 @@ class ConfigAdminSupport
 
                 // ignore well known special properties
                 if ( !id.equals( Constants.SERVICE_PID ) && !id.equals( Constants.SERVICE_DESCRIPTION )
-                    && !id.equals( Constants.SERVICE_ID ) && !id.equals( Constants.SERVICE_VENDOR )
-                    && !id.equals( ConfigurationAdmin.SERVICE_BUNDLELOCATION )
-                    && !id.equals( ConfigurationAdmin.SERVICE_FACTORYPID ) )
+                        && !id.equals( Constants.SERVICE_ID ) && !id.equals( Constants.SERVICE_VENDOR )
+                        && !id.equals( ConfigurationAdmin.SERVICE_BUNDLELOCATION )
+                        && !id.equals( ConfigurationAdmin.SERVICE_FACTORYPID ) )
                 {
                     final Object value = props.get( id );
                     final PropertyDescriptor ad = MetaTypeServiceSupport.createAttributeDefinition( id, value );
@@ -446,7 +444,8 @@ class ConfigAdminSupport
     }
 
 
-    void addConfigurationInfo( Configuration config, JSONWriter json, String locale ) throws JSONException
+    void addConfigurationInfo( Configuration config, JSONWriter json, String locale )
+            throws IOException
     {
 
         if ( config.getFactoryPid() != null )
@@ -500,8 +499,8 @@ class ConfigAdminSupport
         try
         {
             final ServiceReference[] refs = getBundleContext().getServiceReferences(
-                (String)null,
-                "(&(" + Constants.OBJECTCLASS + '=' + ManagedService.class.getName() //$NON-NLS-1$
+                    (String)null,
+                    "(&(" + Constants.OBJECTCLASS + '=' + ManagedService.class.getName() //$NON-NLS-1$
                     + ")(" + Constants.SERVICE_PID + '=' + pid + "))"); //$NON-NLS-1$ //$NON-NLS-2$
             if ( refs != null && refs.length > 0 )
             {
@@ -538,13 +537,13 @@ class ConfigAdminSupport
     }
 
 
-    final void listConfigurations( JSONObject json, String pidFilter, String locale, Locale loc )
+    final void listConfigurations( JSONWriter jw, String pidFilter, String locale, Locale loc )
     {
         try
         {
             // start with ManagedService instances
             Map optionsPlain = getServices(ManagedService.class.getName(), pidFilter,
-                locale, true);
+                    locale, true);
 
             // next are the MetaType informations without ManagedService
             final MetaTypeServiceSupport mtss = getMetaTypeSupport();
@@ -591,37 +590,44 @@ class ConfigAdminSupport
                 optionsPlain.put( pid, pid );
             }
 
+            jw.key("pids");//$NON-NLS-1$
+            jw.array();
             for ( Iterator ii = optionsPlain.keySet().iterator(); ii.hasNext(); )
             {
                 String id = ( String ) ii.next();
                 Object name = optionsPlain.get( id );
 
                 final Configuration config = this.getConfiguration( id );
-                JSONObject data = new JSONObject() //
-                    .put( "id", id ) //$NON-NLS-1$
-                    .put( "name", name ); //$NON-NLS-1$
+                jw.object();
+                jw.key("id").value( id ); //$NON-NLS-1$
+                jw.key( "name").value( name ); //$NON-NLS-1$
                 if ( null != config )
                 {
                     // FELIX-3848
-                    data.put ( "has_config", true ); //$NON-NLS-1$
+                    jw.key("has_config").value( true ); //$NON-NLS-1$
 
                     final String fpid = config.getFactoryPid();
                     if ( null != fpid )
                     {
-                        data.put( "fpid", fpid ); //$NON-NLS-1$
-                        data.putOpt( "nameHint", getConfigurationFactoryNameHint(config, mtss) ); //$NON-NLS-1$
+                        jw.key("fpid").value( fpid ); //$NON-NLS-1$
+                        final String val = getConfigurationFactoryNameHint(config, mtss);
+                        if ( val != null )
+                        {
+                            jw.key( "nameHint").value(val ); //$NON-NLS-1$
+                        }
                     }
 
                     final Bundle bundle = getBoundBundle( config );
                     if ( null != bundle )
                     {
-                        data.put( "bundle", bundle.getBundleId() ); //$NON-NLS-1$
-                        data.put( "bundle_name", Util.getName( bundle, loc ) ); //$NON-NLS-1$
+                        jw.key( "bundle").value( bundle.getBundleId() ); //$NON-NLS-1$
+                        jw.key( "bundle_name").value( Util.getName( bundle, loc ) ); //$NON-NLS-1$
                     }
                 }
+                jw.endObject();
 
-                json.append( "pids", data ); //$NON-NLS-1$
             }
+            jw.endArray();
         }
         catch (Exception e)
         {
@@ -642,7 +648,7 @@ class ConfigAdminSupport
         Map adMap = (mtss != null) ? mtss.getAttributeDefinitionMap(config, null) : null;
         if (null == adMap)
         {
-          return null;
+            return null;
         }
 
         // check for configured name hint template
@@ -739,27 +745,31 @@ class ConfigAdminSupport
         return sb.toString();
     }
 
-    final void listFactoryConfigurations(JSONObject json, String pidFilter,
-        String locale)
+    final void listFactoryConfigurations(JSONWriter jw, String pidFilter,
+            String locale)
     {
         try
         {
             final Map optionsFactory = getServices(ManagedServiceFactory.class.getName(),
-                pidFilter, locale, true);
+                    pidFilter, locale, true);
             final MetaTypeServiceSupport mtss = getMetaTypeSupport();
             if ( mtss != null )
             {
                 addMetaTypeNames( optionsFactory, mtss.getFactoryPidObjectClasses( locale ), pidFilter,
-                    ConfigurationAdmin.SERVICE_FACTORYPID );
+                        ConfigurationAdmin.SERVICE_FACTORYPID );
             }
+            jw.key("fpids");
+            jw.array();
             for ( Iterator ii = optionsFactory.keySet().iterator(); ii.hasNext(); )
             {
                 String id = ( String ) ii.next();
                 Object name = optionsFactory.get( id );
-                json.append( "fpids", new JSONObject() //$NON-NLS-1$
-                    .put( "id", id ) //$NON-NLS-1$
-                    .put( "name", name ) ); //$NON-NLS-1$
+                jw.object();
+                jw.key("id").value(id ); //$NON-NLS-1$
+                jw.key("name").value( name ); //$NON-NLS-1$
+                jw.endObject();
             }
+            jw.endArray();
         }
         catch (Exception e)
         {
@@ -768,7 +778,7 @@ class ConfigAdminSupport
     }
 
     SortedMap getServices( String serviceClass, String serviceFilter, String locale,
-        boolean ocdRequired ) throws InvalidSyntaxException
+            boolean ocdRequired ) throws InvalidSyntaxException
     {
         // sorted map of options
         SortedMap optionsFactory = new TreeMap( String.CASE_INSENSITIVE_ORDER );

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java?rev=1780102&r1=1780101&r2=1780102&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java Tue Jan 24 19:26:00 2017
@@ -19,6 +19,7 @@ package org.apache.felix.webconsole.inte
 
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.util.Locale;
 
 import javax.servlet.ServletException;
@@ -29,8 +30,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.Constants;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.service.cm.Configuration;
@@ -208,7 +208,7 @@ public class ConfigManager extends Simpl
      * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
      */
     protected void doGet( HttpServletRequest request, HttpServletResponse response )
-    throws ServletException, IOException
+            throws ServletException, IOException
     {
         // check for "post" requests from previous versions
         if ( "true".equals(request.getParameter("post")) ) { //$NON-NLS-1$ //$NON-NLS-2$
@@ -386,21 +386,17 @@ public class ConfigManager extends Simpl
         final String locale = ( loc != null ) ? loc.toString() : null;
 
 
-        JSONObject json = new JSONObject();
-        try
-        {
-            final ConfigAdminSupport ca = getConfigurationAdminSupport();
-            json.put("status", ca != null ? Boolean.TRUE : Boolean.FALSE); //$NON-NLS-1$
-            if ( ca != null )
-            {
-                ca.listConfigurations( json, pidFilter, locale, loc );
-                ca.listFactoryConfigurations( json, pidFilter, locale );
-            }
-        }
-        catch (JSONException e)
+        StringWriter json = new StringWriter();
+        JSONWriter jw = new JSONWriter(json);
+        jw.object();
+        final ConfigAdminSupport ca = getConfigurationAdminSupport();
+        jw.key("status").value( ca != null ? Boolean.TRUE : Boolean.FALSE); //$NON-NLS-1$
+        if ( ca != null )
         {
-            throw new IOException(e.toString());
+            ca.listConfigurations( jw, pidFilter, locale, loc );
+            ca.listFactoryConfigurations( jw, pidFilter, locale );
         }
+        jw.endObject();
 
         // if a configuration is addressed, display it immediately
         if ( request.getParameter( ACTION_CREATE ) != null && pid != null )

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/MetaTypeServiceSupport.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/MetaTypeServiceSupport.java?rev=1780102&r1=1780101&r2=1780102&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/MetaTypeServiceSupport.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/MetaTypeServiceSupport.java Tue Jan 24 19:26:00 2017
@@ -17,6 +17,7 @@
 package org.apache.felix.webconsole.internal.configuration;
 
 
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Dictionary;
@@ -27,8 +28,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import org.json.JSONException;
-import org.json.JSONWriter;
+import org.apache.felix.webconsole.json.JSONWriter;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.cm.Configuration;
@@ -264,7 +264,8 @@ class MetaTypeServiceSupport extends Met
     }
 
 
-    void mergeWithMetaType( Dictionary props, ObjectClassDefinition ocd, JSONWriter json, Set ignoreAttrIds ) throws JSONException
+    void mergeWithMetaType( Dictionary props, ObjectClassDefinition ocd, JSONWriter json, Set ignoreAttrIds )
+            throws IOException
     {
         json.key( "title" ).value( ocd.getName() ); //$NON-NLS-1$
 

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/MetaTypeSupport.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/MetaTypeSupport.java?rev=1780102&r1=1780101&r2=1780102&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/MetaTypeSupport.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/MetaTypeSupport.java Tue Jan 24 19:26:00 2017
@@ -17,17 +17,17 @@
 package org.apache.felix.webconsole.internal.configuration;
 
 
+import java.io.IOException;
 import java.lang.reflect.Array;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Vector;
 
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONWriter;
+import org.apache.felix.webconsole.json.JSONWriter;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.metatype.AttributeDefinition;
@@ -78,7 +78,7 @@ class MetaTypeSupport
 
 
     static void attributeToJson( final JSONWriter json, final PropertyDescriptor ad, final Object propValue )
-        throws JSONException
+            throws IOException
     {
         json.object();
 
@@ -149,17 +149,23 @@ class MetaTypeSupport
         }
         else
         {
-            value = new JSONArray( toList( value ) );
-            if ( isPassword )
+            json.key( "values" ); //$NON-NLS-1$
+            json.array();
+            final List list = toList( value );
+            final Iterator iter = list.iterator();
+            while ( iter.hasNext() )
             {
-                JSONArray tmp = ( JSONArray ) value;
-                for ( int tmpI = 0; tmpI < tmp.length(); tmpI++ )
+                final Object val = iter.next();
+                if ( isPassword )
+                {
+                    json.value(PASSWORD_PLACEHOLDER_VALUE);
+                }
+                else
                 {
-                    tmp.put( tmpI, PASSWORD_PLACEHOLDER_VALUE );
+                    json.value(val);
                 }
             }
-            json.key( "values" ); //$NON-NLS-1$
-            json.value( value );
+            json.endArray();
         }
 
         if ( ad.getDescription() != null )
@@ -299,27 +305,27 @@ class MetaTypeSupport
     {
         switch ( type )
         {
-            case AttributeDefinition.BOOLEAN:
-                return Boolean.valueOf( value );
-            case AttributeDefinition.BYTE:
-                return Byte.valueOf( value );
-            case AttributeDefinition.CHARACTER:
-                char c = ( value.length() > 0 ) ? value.charAt( 0 ) : 0;
-                return new Character( c );
-            case AttributeDefinition.DOUBLE:
-                return Double.valueOf( value );
-            case AttributeDefinition.FLOAT:
-                return Float.valueOf( value );
-            case AttributeDefinition.LONG:
-                return Long.valueOf( value );
-            case AttributeDefinition.INTEGER:
-                return Integer.valueOf( value );
-            case AttributeDefinition.SHORT:
-                return Short.valueOf( value );
-            default:
-                // includes AttributeDefinition.STRING
-                // includes ATTRIBUTE_TYPE_PASSWORD/AttributeDefinition.PASSWORD
-                return value;
+        case AttributeDefinition.BOOLEAN:
+            return Boolean.valueOf( value );
+        case AttributeDefinition.BYTE:
+            return Byte.valueOf( value );
+        case AttributeDefinition.CHARACTER:
+            char c = ( value.length() > 0 ) ? value.charAt( 0 ) : 0;
+            return new Character( c );
+        case AttributeDefinition.DOUBLE:
+            return Double.valueOf( value );
+        case AttributeDefinition.FLOAT:
+            return Float.valueOf( value );
+        case AttributeDefinition.LONG:
+            return Long.valueOf( value );
+        case AttributeDefinition.INTEGER:
+            return Integer.valueOf( value );
+        case AttributeDefinition.SHORT:
+            return Short.valueOf( value );
+        default:
+            // includes AttributeDefinition.STRING
+            // includes ATTRIBUTE_TYPE_PASSWORD/AttributeDefinition.PASSWORD
+            return value;
         }
     }
 
@@ -357,33 +363,33 @@ class MetaTypeSupport
         Object array;
         switch ( type )
         {
-            case AttributeDefinition.BOOLEAN:
-                array = new boolean[size];
-                break;
-            case AttributeDefinition.BYTE:
-                array = new byte[size];
-                break;
-            case AttributeDefinition.CHARACTER:
-                array = new char[size];
-                break;
-            case AttributeDefinition.DOUBLE:
-                array = new double[size];
-                break;
-            case AttributeDefinition.FLOAT:
-                array = new float[size];
-                break;
-            case AttributeDefinition.LONG:
-                array = new long[size];
-                break;
-            case AttributeDefinition.INTEGER:
-                array = new int[size];
-                break;
-            case AttributeDefinition.SHORT:
-                array = new short[size];
-                break;
-            default:
-                // unexpected, but assume string
-                array = new String[size];
+        case AttributeDefinition.BOOLEAN:
+            array = new boolean[size];
+            break;
+        case AttributeDefinition.BYTE:
+            array = new byte[size];
+            break;
+        case AttributeDefinition.CHARACTER:
+            array = new char[size];
+            break;
+        case AttributeDefinition.DOUBLE:
+            array = new double[size];
+            break;
+        case AttributeDefinition.FLOAT:
+            array = new float[size];
+            break;
+        case AttributeDefinition.LONG:
+            array = new long[size];
+            break;
+        case AttributeDefinition.INTEGER:
+            array = new int[size];
+            break;
+        case AttributeDefinition.SHORT:
+            array = new short[size];
+            break;
+        default:
+            // unexpected, but assume string
+            array = new String[size];
         }
 
         for ( int i = 0; i < size; i++ )

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java?rev=1780102&r1=1780101&r2=1780102&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java Tue Jan 24 19:26:00 2017
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.io.Writer;
+import java.lang.reflect.Array;
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -32,6 +33,7 @@ import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -58,10 +60,7 @@ import org.apache.felix.webconsole.bundl
 import org.apache.felix.webconsole.bundleinfo.BundleInfoProvider;
 import org.apache.felix.webconsole.internal.OsgiManagerPlugin;
 import org.apache.felix.webconsole.internal.Util;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.json.JSONWriter;
+import org.apache.felix.webconsole.json.JSONWriter;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
@@ -159,7 +158,7 @@ public class BundlesServlet extends Simp
 
         Hashtable props = new Hashtable();
         props.put( WebConsoleConstants.CONFIG_PRINTER_MODES, new String[] { ConfigurationPrinter.MODE_TXT,
-            ConfigurationPrinter.MODE_ZIP } );
+                ConfigurationPrinter.MODE_ZIP } );
         configurationPrinter = bundleContext.registerService( ConfigurationPrinter.SERVICE, this, props );
     }
 
@@ -194,80 +193,71 @@ public class BundlesServlet extends Simp
     {
         try
         {
-            StringWriter w = new StringWriter();
-            writeJSON( w, null, null, null, true, Locale.ENGLISH, null, null );
-            String jsonString = w.toString();
-            JSONObject json = new JSONObject( jsonString );
+            final Map map = createObjectStructure(null, null, null, true, Locale.ENGLISH, null, null );
 
-            pw.println( "Status: " + json.get( "status" ) );
+            pw.println( "Status: " + map.get( "status" ) );
             pw.println();
 
-            JSONArray data = json.getJSONArray( "data" );
-            for ( int i = 0; i < data.length(); i++ )
+            Object[] data = (Object[]) map.get( "data" );
+            for ( int i = 0; i < data.length; i++ )
             {
-                if ( !data.isNull( i ) )
-                {
-                    JSONObject bundle = data.getJSONObject( i );
+                Map bundle = (Map) data[i];
 
-                    pw.println( MessageFormat.format( "Bundle {0} - {1} {2} (state: {3})", new Object[]
+                pw.println( MessageFormat.format( "Bundle {0} - {1} {2} (state: {3})", new Object[]
                         { bundle.get( "id" ), bundle.get( "name" ), bundle.get( "version" ), bundle.get( "state" ) } ) );
 
-                    JSONArray props = bundle.getJSONArray( "props" );
-                    for ( int pi = 0; pi < props.length(); pi++ )
+                Object[] props = (Object[]) bundle.get( "props" );
+                for ( int pi = 0; pi < props.length; pi++ )
+                {
+                    Map entry = (Map) props[pi];
+                    String key = ( String ) entry.get( "key" );
+                    if ( "nfo".equals( key ) )
                     {
-                        if ( !props.isNull( pi ) )
+                        // BundleInfo (see #bundleInfo & #bundleInfoDetails
+                        Map infos = ( Map ) entry.get( "value" );
+                        Iterator infoKeys = infos.keySet().iterator();
+                        while ( infoKeys.hasNext() )
                         {
-                            JSONObject entry = props.getJSONObject( pi );
-                            String key = ( String ) entry.get( "key" );
-                            if ( "nfo".equals( key ) )
+                            String infoKey = ( String ) infoKeys.next();
+                            pw.println( "    " + infoKey + ": " );
+
+                            Object[] infoA = (Object[]) infos.get(infoKey);
+                            for ( int iai = 0; iai < infoA.length; iai++ )
                             {
-                                // BundleInfo (see #bundleInfo & #bundleInfoDetails
-                                JSONObject infos = ( JSONObject ) entry.get( "value" );
-                                Iterator infoKeys = infos.keys();
-                                while ( infoKeys.hasNext() )
+                                if ( infoA[iai] != null )
                                 {
-                                    String infoKey = ( String ) infoKeys.next();
-                                    pw.println( "    " + infoKey + ": " );
-
-                                    JSONArray infoA = infos.getJSONArray( infoKey );
-                                    for ( int iai = 0; iai < infoA.length(); iai++ )
-                                    {
-                                        if ( !infoA.isNull( iai ) )
-                                        {
-                                            JSONObject info = infoA.getJSONObject( iai );
-                                            pw.println( "        " + info.get( "name" ) );
-                                        }
-                                    }
+                                    Map info = (Map) infoA[iai];
+                                    pw.println( "        " + info.get( "name" ) );
                                 }
                             }
-                            else
-                            {
-                                // regular data
-                                pw.print( "    " + key + ": " );
+                        }
+                    }
+                    else
+                    {
+                        // regular data
+                        pw.print( "    " + key + ": " );
 
-                                Object entryValue = entry.get( "value" );
-                                if ( entryValue instanceof JSONArray )
-                                {
-                                    pw.println();
-                                    JSONArray entryArray = ( JSONArray ) entryValue;
-                                    for ( int ei = 0; ei < entryArray.length(); ei++ )
-                                    {
-                                        if ( !entryArray.isNull( ei ) )
-                                        {
-                                            pw.println( "        " + entryArray.get( ei ) );
-                                        }
-                                    }
-                                }
-                                else
+                        Object entryValue = entry.get( "value" );
+                        if ( entryValue.getClass().isArray() )
+                        {
+                            pw.println();
+                            for ( int ei = 0; ei < Array.getLength(entryValue); ei++ )
+                            {
+                                Object o = Array.get(entryValue, ei);
+                                if ( o != null )
                                 {
-                                    pw.println( entryValue );
+                                    pw.println( "        " + o );
                                 }
                             }
                         }
+                        else
+                        {
+                            pw.println( entryValue );
+                        }
                     }
-
-                    pw.println();
                 }
+
+                pw.println();
             }
         }
         catch ( Exception e )
@@ -283,7 +273,7 @@ public class BundlesServlet extends Simp
      * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
      */
     protected void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException,
-        IOException
+    IOException
     {
         final RequestInfo reqInfo = new RequestInfo(request);
         if ( "upload".equals(reqInfo.pathInfo) )
@@ -411,13 +401,13 @@ public class BundlesServlet extends Simp
                 resp.setCharacterEncoding( "UTF-8" ); //$NON-NLS-1$
                 if ( null == getBundleContext() )
                 {
-                  // refresh package on the web console itself or some of it's dependencies
-                  resp.getWriter().print("false"); //$NON-NLS-1$
+                    // refresh package on the web console itself or some of it's dependencies
+                    resp.getWriter().print("false"); //$NON-NLS-1$
                 }
                 else
                 {
-                  resp.getWriter().print( "{\"fragment\":" + isFragmentBundle( bundle ) //$NON-NLS-1$
-                      + ",\"stateRaw\":" + bundle.getState() + "}" ); //$NON-NLS-1$ //$NON-NLS-2$
+                    resp.getWriter().print( "{\"fragment\":" + isFragmentBundle( bundle ) //$NON-NLS-1$
+                    + ",\"stateRaw\":" + bundle.getState() + "}" ); //$NON-NLS-1$ //$NON-NLS-2$
                 }
                 return;
             }
@@ -445,7 +435,7 @@ public class BundlesServlet extends Simp
     private String getServicesRoot(HttpServletRequest request)
     {
         return ( ( String ) request.getAttribute( WebConsoleConstants.ATTR_APP_ROOT ) ) +
-            "/" + ServicesServlet.LABEL + "/";
+                "/" + ServicesServlet.LABEL + "/";
     }
 
     Bundle getBundle( String pathInfo )
@@ -541,7 +531,7 @@ public class BundlesServlet extends Simp
     }
 
     private void renderJSON( final HttpServletResponse response, final Bundle bundle, final String pluginRoot, final String servicesRoot, final Locale locale, final String filter, final BundleException be )
-        throws IOException, InvalidSyntaxException
+            throws IOException, InvalidSyntaxException
     {
         response.setContentType( "application/json" );
         response.setCharacterEncoding( "UTF-8" );
@@ -552,14 +542,16 @@ public class BundlesServlet extends Simp
 
 
     private void writeJSON( final Writer pw, final Bundle bundle, final String pluginRoot, final String servicesRoot, final Locale locale, final String filter, final BundleException be )
-        throws IOException, InvalidSyntaxException
+            throws IOException, InvalidSyntaxException
     {
-        writeJSON( pw, bundle, pluginRoot, servicesRoot, false, locale, filter, be );
-    }
+        final Map map = createObjectStructure( bundle, pluginRoot, servicesRoot, false, locale, filter, be );
+        final JSONWriter writer = new JSONWriter(pw);
 
+        writer.value(map);
+    }
 
-    private void writeJSON( final Writer pw, final Bundle bundle, final String pluginRoot,
-        final String servicesRoot, final boolean fullDetails, final Locale locale, final String filter, final BundleException be ) throws IOException, InvalidSyntaxException
+    private Map createObjectStructure( final Bundle bundle, final String pluginRoot,
+            final String servicesRoot, final boolean fullDetails, final Locale locale, final String filter, final BundleException be ) throws IOException, InvalidSyntaxException
     {
         final Bundle[] allBundles = this.getBundles();
         final Object[] status = getStatusLine(allBundles);
@@ -592,49 +584,30 @@ public class BundlesServlet extends Simp
 
         Util.sort( bundles, locale );
 
-        final JSONWriter jw = new JSONWriter( pw );
+        final Map map = new LinkedHashMap();
 
-        try
+        if (null != be)
         {
-            jw.object();
-
-            if (null != be)
-            {
-                final StringWriter s = new StringWriter();
-                final Throwable t = be.getNestedException() != null ? be.getNestedException() : be;
-                t.printStackTrace( new PrintWriter(s) );
-                jw.key( "error" );
-                jw.value( s.toString() );
-            }
-
-            jw.key( "status" );
-            jw.value( statusLine );
-
-            // add raw status
-            jw.key( "s" );
-            jw.array();
-            for ( int i = 0; i < 5; i++ ) jw.value(status[i]);
-            jw.endArray();
-
-            jw.key( "data" );
-
-            jw.array();
-
-            for ( int i = 0; i < bundles.length; i++ )
-            {
-                bundleInfo( jw, bundles[i], fullDetails || bundle != null, pluginRoot, servicesRoot, locale );
-            }
+            final StringWriter s = new StringWriter();
+            final Throwable t = be.getNestedException() != null ? be.getNestedException() : be;
+            t.printStackTrace( new PrintWriter(s) );
+            map.put("error", s.toString());
+        }
 
-            jw.endArray();
+        map.put("status", statusLine);
 
-            jw.endObject();
+        // add raw status
+        map.put( "s", status );
 
-        }
-        catch ( JSONException je )
+        final Object[] bundlesArray = new Object[bundles.length];
+        for ( int i = 0; i < bundles.length; i++ )
         {
-            throw new IOException( je.toString() );
+            bundlesArray[i] =
+                    bundleInfo( bundles[i], fullDetails || bundle != null, pluginRoot, servicesRoot, locale );
         }
 
+        map.put("data", bundlesArray);
+        return map;
     }
 
     private Object[] getStatusLine(final Bundle[] bundles)
@@ -645,22 +618,22 @@ public class BundlesServlet extends Simp
         {
             switch ( bundles[i].getState() )
             {
-                case Bundle.ACTIVE:
-                    active++;
-                    break;
-                case Bundle.INSTALLED:
-                    installed++;
-                    break;
-                case Bundle.RESOLVED:
-                    if ( isFragmentBundle( bundles[i] ) )
-                    {
-                        fragments++;
-                    }
-                    else
-                    {
-                        resolved++;
-                    }
-                    break;
+            case Bundle.ACTIVE:
+                active++;
+                break;
+            case Bundle.INSTALLED:
+                installed++;
+                break;
+            case Bundle.RESOLVED:
+                if ( isFragmentBundle( bundles[i] ) )
+                {
+                    fragments++;
+                }
+                else
+                {
+                    resolved++;
+                }
+                break;
             }
         }
         final StringBuffer buffer = new StringBuffer();
@@ -704,33 +677,27 @@ public class BundlesServlet extends Simp
         return ret;
     }
 
-    private void bundleInfo( JSONWriter jw, Bundle bundle, boolean details, final String pluginRoot, final String servicesRoot, final Locale locale )
-        throws JSONException
+    private Map bundleInfo( Bundle bundle, boolean details, final String pluginRoot, final String servicesRoot, final Locale locale )
     {
-        jw.object();
-        jw.key( "id" );
-        jw.value( bundle.getBundleId() );
-        jw.key( "name" );
-        jw.value( Util.getName( bundle, locale ) );
-        jw.key( "fragment" );
-        jw.value( isFragmentBundle(bundle) );
-        jw.key( "stateRaw" );
-        jw.value( bundle.getState() );
-        jw.key( "state" );
-        jw.value( toStateString( bundle ) );
-        jw.key( "version" );
-        jw.value( Util.getHeaderValue(bundle, Constants.BUNDLE_VERSION) );
-        jw.key( "symbolicName" );
-        jw.value( bundle.getSymbolicName() );
-        jw.key( "category" );
-        jw.value( Util.getHeaderValue(bundle, Constants.BUNDLE_CATEGORY) );
+        final Map result = new LinkedHashMap();
+        result.put("id", String.valueOf(bundle.getBundleId()) );
+        result.put("name", Util.getName( bundle, locale ) );
+        result.put("fragment", String.valueOf(isFragmentBundle(bundle)) );
+        result.put("stateRaw", String.valueOf(bundle.getState() ) );
+        result.put("state", toStateString( bundle ) );
+        result.put("version", Util.getHeaderValue(bundle, Constants.BUNDLE_VERSION) );
+        if ( bundle.getSymbolicName() != null )
+        {
+            result.put("symbolicName",  bundle.getSymbolicName() );
+        }
+        result.put("category",  Util.getHeaderValue(bundle, Constants.BUNDLE_CATEGORY) );
 
         if ( details )
         {
-            bundleDetails( jw, bundle, pluginRoot, servicesRoot, locale );
+            bundleDetails( result, bundle, pluginRoot, servicesRoot, locale );
         }
 
-        jw.endObject();
+        return result;
     }
 
 
@@ -744,24 +711,24 @@ public class BundlesServlet extends Simp
     {
         switch ( bundle.getState() )
         {
-            case Bundle.INSTALLED:
-                return "Installed";
-            case Bundle.RESOLVED:
-                if ( isFragmentBundle(bundle) )
-                {
-                    return "Fragment";
-                }
-                return "Resolved";
-            case Bundle.STARTING:
-                return "Starting";
-            case Bundle.ACTIVE:
-                return "Active";
-            case Bundle.STOPPING:
-                return "Stopping";
-            case Bundle.UNINSTALLED:
-                return "Uninstalled";
-            default:
-                return "Unknown: " + bundle.getState();
+        case Bundle.INSTALLED:
+            return "Installed";
+        case Bundle.RESOLVED:
+            if ( isFragmentBundle(bundle) )
+            {
+                return "Fragment";
+            }
+            return "Resolved";
+        case Bundle.STARTING:
+            return "Starting";
+        case Bundle.ACTIVE:
+            return "Active";
+        case Bundle.STOPPING:
+            return "Stopping";
+        case Bundle.UNINSTALLED:
+            return "Uninstalled";
+        default:
+            return "Unknown: " + bundle.getState();
         }
     }
 
@@ -777,65 +744,70 @@ public class BundlesServlet extends Simp
         return getPackageAdmin().getBundleType( bundle ) == PackageAdmin.BUNDLE_TYPE_FRAGMENT;
     }
 
-
-    private final void bundleDetails( JSONWriter jw, Bundle bundle, final String pluginRoot, final String servicesRoot, final Locale locale)
-        throws JSONException
+    private void keyVal(final List props, final String key, final Object val)
+    {
+        if ( val != null )
+        {
+            final Map obj = new LinkedHashMap();
+            obj.put("key", key);
+            obj.put("value", val);
+            props.add(obj);
+        }
+    }
+    private final void bundleDetails( final Map result, Bundle bundle, final String pluginRoot, final String servicesRoot, final Locale locale)
     {
         Dictionary headers = bundle.getHeaders( locale == null ? null : locale.toString() );
 
-        jw.key( "props" );
-        jw.array();
-        Util.keyVal( jw, "Symbolic Name", bundle.getSymbolicName() );
-        Util.keyVal( jw, "Version", headers.get( Constants.BUNDLE_VERSION ) );
-        Util.keyVal( jw, "Bundle Location", bundle.getLocation() );
-        Util.keyVal( jw, "Last Modification", new Date( bundle.getLastModified() ) );
+        final List props = new ArrayList();
+
+        keyVal( props, "Symbolic Name", bundle.getSymbolicName() );
+        keyVal( props, "Version", headers.get( Constants.BUNDLE_VERSION ) );
+        keyVal( props, "Bundle Location", bundle.getLocation() );
+        keyVal( props, "Last Modification", new Date( bundle.getLastModified() ) );
 
         String docUrl = ( String ) headers.get( Constants.BUNDLE_DOCURL );
         if ( docUrl != null )
         {
-            Util.keyVal( jw, "Bundle Documentation", docUrl );
+            keyVal( props, "Bundle Documentation", docUrl );
         }
 
-        Util.keyVal( jw, "Vendor", headers.get( Constants.BUNDLE_VENDOR ) );
-        Util.keyVal( jw, "Copyright", headers.get( Constants.BUNDLE_COPYRIGHT ) );
-        Util.keyVal( jw, "Description", headers.get( Constants.BUNDLE_DESCRIPTION ) );
+        keyVal( props, "Vendor", headers.get( Constants.BUNDLE_VENDOR ) );
+        keyVal( props, "Copyright", headers.get( Constants.BUNDLE_COPYRIGHT ) );
+        keyVal( props, "Description", headers.get( Constants.BUNDLE_DESCRIPTION ) );
 
-        Util.keyVal( jw, "Start Level", getStartLevel( bundle ) );
+        keyVal( props, "Start Level", getStartLevel( bundle ) );
 
-        Util.keyVal( jw, "Bundle Classpath", headers.get( Constants.BUNDLE_CLASSPATH ) );
+        keyVal( props, "Bundle Classpath", headers.get( Constants.BUNDLE_CLASSPATH ) );
 
-        listFragmentInfo( jw, bundle, pluginRoot );
+        listFragmentInfo( props, bundle, pluginRoot );
 
         if ( bundle.getState() == Bundle.INSTALLED )
         {
-            listImportExportsUnresolved( jw, bundle, pluginRoot );
+            listImportExportsUnresolved( props, bundle, pluginRoot );
         }
         else
         {
-            listImportExport( jw, bundle, pluginRoot );
+            listImportExport( props, bundle, pluginRoot );
         }
 
         if ( bundle.getState() != Bundle.UNINSTALLED )
         {
-            listServices( jw, bundle, servicesRoot );
+            listServices( props, bundle, servicesRoot );
         }
 
-        listHeaders( jw, bundle );
+        listHeaders( props, bundle );
         final String appRoot = ( pluginRoot == null ) ? "" : pluginRoot.substring( 0, pluginRoot.lastIndexOf( "/" ) );
-        bundleInfoDetails( jw, bundle, appRoot, locale );
+        bundleInfoDetails( props, bundle, appRoot, locale );
 
-        jw.endArray();
+        result.put( "props", props.toArray(new Object[props.size()]));
     }
 
 
-    private final void bundleInfoDetails( JSONWriter jw, Bundle bundle, String appRoot, final Locale locale)
-	        throws JSONException
+    private final void bundleInfoDetails( List props, Bundle bundle, String appRoot, final Locale locale)
     {
-	jw.object();
-	jw.key( "key" );
-	jw.value( "nfo" );
-	jw.key( "value");
-	jw.object();
+        final Map val = new LinkedHashMap();
+        val.put("key", "nfo");
+        final Map value = new LinkedHashMap();
         final Object[] bundleInfoProviders = bundleInfoTracker.getServices();
         for ( int i = 0; bundleInfoProviders != null && i < bundleInfoProviders.length; i++ )
         {
@@ -843,32 +815,27 @@ public class BundlesServlet extends Simp
             final BundleInfo[] infos = infoProvider.getBundleInfo(bundle, appRoot, locale);
             if ( null != infos && infos.length > 0)
             {
-        	jw.key( infoProvider.getName(locale) );
-        	jw.array();
-        	for ( int j = 0; j < infos.length; j++ )
-        	{
-        	    bundleInfo( jw, infos[j] );
-        	}
-        	jw.endArray();
-            }
-        }
-        jw.endObject(); // value
-        jw.endObject();
+                final Object[] infoArray = new Object[infos.length];
+                for ( int j = 0; j < infos.length; j++ )
+                {
+                    infoArray[j] = bundleInfo( infos[j] );
+                }
+                value.put(infoProvider.getName(locale), infoArray);
+            }
+        }
+        val.put("value", value);
+        props.add(val);
     }
 
 
-    private static final void bundleInfo( JSONWriter jw, BundleInfo info ) throws JSONException
-    {
-        jw.object();
-        jw.key( "name" );
-        jw.value( info.getName() );
-        jw.key( "description" );
-        jw.value( info.getDescription() );
-        jw.key( "type" );
-        jw.value( info.getType().getName() );
-        jw.key( "value" );
-        jw.value( info.getValue() );
-        jw.endObject();
+    private static final Object bundleInfo( BundleInfo info )
+    {
+        final Map val = new LinkedHashMap();
+        val.put( "name", info.getName() );
+        val.put( "description", info.getDescription() );
+        val.put( "type", info.getType().getName() );
+        val.put( "value", info.getValue() );
+        return val;
     }
 
 
@@ -888,7 +855,7 @@ public class BundlesServlet extends Simp
     }
 
 
-    private void listImportExport( JSONWriter jw, Bundle bundle, final String pluginRoot ) throws JSONException
+    private void listImportExport( List props, Bundle bundle, final String pluginRoot )
     {
         PackageAdmin packageAdmin = getPackageAdmin();
         if ( packageAdmin == null )
@@ -916,11 +883,11 @@ public class BundlesServlet extends Simp
                 }
             } );
 
-            JSONArray val = new JSONArray();
+            Object[] val = new Object[exports.length];
             for ( int j = 0; j < exports.length; j++ )
             {
                 ExportedPackage export = exports[j];
-                collectExport( val, export.getName(), export.getVersion() );
+                val[j] = collectExport( export.getName(), export.getVersion() );
                 Bundle[] ubList = export.getImportingBundles();
                 if ( ubList != null )
                 {
@@ -933,11 +900,11 @@ public class BundlesServlet extends Simp
                     }
                 }
             }
-            Util.keyVal( jw, "Exported Packages", val );
+            keyVal( props, "Exported Packages", val );
         }
         else
         {
-            Util.keyVal( jw, "Exported Packages", "---" );
+            keyVal( props, "Exported Packages", "---" );
         }
 
         exports = packageAdmin.getExportedPackages( ( Bundle ) null );
@@ -960,11 +927,11 @@ public class BundlesServlet extends Simp
                 }
             }
             // now sort
-            JSONArray val = new JSONArray();
+            Object[] val;
             if ( imports.size() > 0 )
             {
                 final ExportedPackage[] packages = ( ExportedPackage[] ) imports.toArray( new ExportedPackage[imports
-                    .size()] );
+                                                                                                              .size()] );
                 Arrays.sort( packages, new Comparator()
                 {
                     public int compare( ExportedPackage p1, ExportedPackage p2 )
@@ -979,35 +946,39 @@ public class BundlesServlet extends Simp
                     }
                 } );
                 // and finally print out
+                val = new Object[packages.length];
                 for ( int i = 0; i < packages.length; i++ )
                 {
                     ExportedPackage ep = packages[i];
-                    collectImport( val, ep.getName(), ep.getVersion(), false, ep, pluginRoot );
+                    val[i] = collectImport( ep.getName(), ep.getVersion(), false, ep, pluginRoot );
                 }
             }
             else
             {
                 // add description if there are no imports
-                val.put( "None" );
+                val = new Object[1];
+                val[0] =  "None";
             }
 
-            Util.keyVal( jw, "Imported Packages", val );
+            keyVal( props, "Imported Packages", val );
         }
 
         if ( !usingBundles.isEmpty() )
         {
-            JSONArray val = new JSONArray();
+            Object[] val = new Object[usingBundles.size()];
+            int index = 0;
             for ( Iterator ui = usingBundles.values().iterator(); ui.hasNext(); )
             {
                 Bundle usingBundle = ( Bundle ) ui.next();
-                val.put( getBundleDescriptor( usingBundle, pluginRoot ) );
+                val[index] = getBundleDescriptor( usingBundle, pluginRoot );
+                index++;
             }
-            Util.keyVal( jw, "Importing Bundles", val );
+            keyVal( props, "Importing Bundles", val );
         }
     }
 
 
-    private void listImportExportsUnresolved( JSONWriter jw, Bundle bundle, final String pluginRoot ) throws JSONException
+    private void listImportExportsUnresolved( final List props, Bundle bundle, final String pluginRoot )
     {
         Dictionary dict = bundle.getHeaders();
 
@@ -1032,17 +1003,17 @@ public class BundlesServlet extends Simp
                     }
                 } );
 
-                JSONArray val = new JSONArray();
+                Object[] val = new Object[pkgs.length];
                 for ( int i = 0; i < pkgs.length; i++ )
                 {
                     Clause export = new Clause( pkgs[i].getName(), pkgs[i].getDirectives(), pkgs[i].getAttributes() );
-                    collectExport( val, export.getName(), export.getAttribute( Constants.VERSION_ATTRIBUTE ) );
+                    val[i] = collectExport( export.getName(), export.getAttribute( Constants.VERSION_ATTRIBUTE ) );
                 }
-                Util.keyVal( jw, "Exported Packages", val );
+                keyVal( props, "Exported Packages", val );
             }
             else
             {
-                Util.keyVal( jw, "Exported Packages", "---" );
+                keyVal( props, "Exported Packages", "---" );
             }
         }
 
@@ -1082,9 +1053,10 @@ public class BundlesServlet extends Simp
                 }
 
                 // now sort
-                JSONArray val = new JSONArray();
+                Object[] val;
                 if ( imports.size() > 0 )
                 {
+                    final List importList = new ArrayList();
                     for ( Iterator ii = imports.values().iterator(); ii.hasNext(); )
                     {
                         Clause r4Import = ( Clause ) ii.next();
@@ -1101,18 +1073,20 @@ public class BundlesServlet extends Simp
                             }
                         }
 
-                        collectImport( val, r4Import.getName(), r4Import.getAttribute( Constants.VERSION_ATTRIBUTE ),
-                            Constants.RESOLUTION_OPTIONAL.equals( r4Import
-                                .getDirective( Constants.RESOLUTION_DIRECTIVE ) ), ep, pluginRoot );
+                        importList.add(collectImport(  r4Import.getName(), r4Import.getAttribute( Constants.VERSION_ATTRIBUTE ),
+                                Constants.RESOLUTION_OPTIONAL.equals( r4Import
+                                        .getDirective( Constants.RESOLUTION_DIRECTIVE ) ), ep, pluginRoot ));
                     }
+                    val = importList.toArray(new Object[importList.size()]);
                 }
                 else
                 {
                     // add description if there are no imports
-                    val.put( "---" );
+                    val = new Object[1];
+                    val[0] = "---" ;
                 }
 
-                Util.keyVal( jw, "Imported Packages", val );
+                keyVal( props, "Imported Packages", val );
             }
         }
     }
@@ -1134,7 +1108,7 @@ public class BundlesServlet extends Simp
     }
 
 
-    private void listServices( JSONWriter jw, Bundle bundle, final String servicesRoot ) throws JSONException
+    private void listServices( List props, Bundle bundle, final String servicesRoot )
     {
         ServiceReference[] refs = bundle.getRegisteredServices();
         if ( refs == null || refs.length == 0 )
@@ -1148,7 +1122,7 @@ public class BundlesServlet extends Simp
 
             String key = "Service ID " + getServiceID( refs[i], servicesRoot );
 
-            JSONArray val = new JSONArray();
+            List val = new ArrayList();
 
             appendProperty( val, refs[i], Constants.OBJECTCLASS, "Types" );
             appendProperty( val, refs[i], Constants.SERVICE_PID, "Service PID" );
@@ -1160,14 +1134,14 @@ public class BundlesServlet extends Simp
             appendProperty( val, refs[i], Constants.SERVICE_DESCRIPTION, "Description" );
             appendProperty( val, refs[i], Constants.SERVICE_VENDOR, "Vendor" );
 
-            Util.keyVal( jw, key, val);
+            keyVal( props, key, val.toArray(new Object[val.size()]));
         }
     }
 
 
-    private void listHeaders( JSONWriter jw, Bundle bundle ) throws JSONException
+    private void listHeaders( List props, Bundle bundle )
     {
-        JSONArray val = new JSONArray();
+        List val = new ArrayList();
 
         Dictionary headers = bundle.getHeaders(""); // don't localize at all - raw headers
         Enumeration he = headers.keys();
@@ -1178,10 +1152,10 @@ public class BundlesServlet extends Simp
             // Package headers may be long, support line breaking by
             // ensuring blanks after comma and semicolon.
             value = enableLineWrapping(value);
-            val.put( header + ": " + value );
+            val.add( header + ": " + value );
         }
 
-        Util.keyVal( jw, "Manifest Headers", val );
+        keyVal( props, "Manifest Headers", val.toArray(new Object[val.size()]) );
     }
 
     private static final String enableLineWrapping(final String value)
@@ -1202,8 +1176,7 @@ public class BundlesServlet extends Simp
         }
     }
 
-    private void listFragmentInfo( final JSONWriter jw, final Bundle bundle, final String pluginRoot )
-        throws JSONException
+    private void listFragmentInfo( final List props, final Bundle bundle, final String pluginRoot )
     {
 
         if ( isFragmentBundle( bundle ) )
@@ -1211,12 +1184,12 @@ public class BundlesServlet extends Simp
             Bundle[] hostBundles = getPackageAdmin().getHosts( bundle );
             if ( hostBundles != null )
             {
-                JSONArray val = new JSONArray();
+                final Object[] val = new Object[hostBundles.length];
                 for ( int i = 0; i < hostBundles.length; i++ )
                 {
-                    val.put( getBundleDescriptor( hostBundles[i], pluginRoot ) );
+                    val[i] = getBundleDescriptor( hostBundles[i], pluginRoot );
                 }
-                Util.keyVal( jw, "Host Bundles", val );
+                keyVal( props, "Host Bundles", val );
             }
         }
         else
@@ -1224,19 +1197,19 @@ public class BundlesServlet extends Simp
             Bundle[] fragmentBundles = getPackageAdmin().getFragments( bundle );
             if ( fragmentBundles != null )
             {
-                JSONArray val = new JSONArray();
+                final Object[] val = new Object[fragmentBundles.length];
                 for ( int i = 0; i < fragmentBundles.length; i++ )
                 {
-                    val.put( getBundleDescriptor( fragmentBundles[i], pluginRoot ) );
+                    val[i] = getBundleDescriptor( fragmentBundles[i], pluginRoot );
                 }
-                Util.keyVal( jw, "Fragments Attached", val );
+                keyVal( props, "Fragments Attached", val );
             }
         }
 
     }
 
 
-    private void appendProperty( JSONArray array, ServiceReference ref, String name, String label )
+    private void appendProperty( final List props, ServiceReference ref, String name, String label )
     {
         StringBuffer dest = new StringBuffer();
         Object value = ref.getProperty( name );
@@ -1250,23 +1223,23 @@ public class BundlesServlet extends Simp
                     dest.append( ", " );
                 dest.append( values[j] );
             }
-            array.put(dest.toString());
+            props.add(dest.toString());
         }
         else if ( value != null )
         {
             dest.append( label ).append( ": " ).append( value );
-            array.put(dest.toString());
+            props.add(dest.toString());
         }
     }
 
 
-    private void collectExport( JSONArray array, String name, Version version )
+    private Object collectExport( String name, Version version )
     {
-        collectExport( array, name, ( version == null ) ? null : version.toString() );
+        return collectExport( name, ( version == null ) ? null : version.toString() );
     }
 
 
-    private void collectExport( JSONArray array, String name, String version )
+    private Object collectExport( String name, String version )
     {
         StringBuffer val = new StringBuffer();
         boolean bootDel = isBootDelegated( name );
@@ -1287,19 +1260,19 @@ public class BundlesServlet extends Simp
             val.append( " -- Overwritten by Boot Delegation" );
         }
 
-        array.put(val.toString());
+        return val.toString();
     }
 
 
-    private void collectImport( JSONArray array, String name, Version version, boolean optional,
-        ExportedPackage export, final String pluginRoot )
+    private Object collectImport(String name, Version version, boolean optional,
+            ExportedPackage export, final String pluginRoot )
     {
-        collectImport( array, name, ( version == null ) ? null : version.toString(), optional, export, pluginRoot );
+        return collectImport( name, ( version == null ) ? null : version.toString(), optional, export, pluginRoot );
     }
 
 
-    private void collectImport( JSONArray array, String name, String version, boolean optional, ExportedPackage export,
-        final String pluginRoot )
+    private Object collectImport( String name, String version, boolean optional, ExportedPackage export,
+            final String pluginRoot )
     {
         StringBuffer val = new StringBuffer();
         boolean bootDel = isBootDelegated( name );
@@ -1344,7 +1317,7 @@ public class BundlesServlet extends Simp
             val.insert(0, marker);
         }
 
-        array.put(val);
+        return val;
     }
 
 
@@ -1373,8 +1346,8 @@ public class BundlesServlet extends Simp
                 // test to see if the request should be delegated to the parent
                 // class loader.
                 if ( ( bootPkgWildcards[i] && ( pkgName.startsWith( bootPkgs[i] ) || bootPkgs[i].regionMatches( 0,
-                    pkgName, 0, pkgName.length() ) ) )
-                    || ( !bootPkgWildcards[i] && bootPkgs[i].equals( pkgName ) ) )
+                        pkgName, 0, pkgName.length() ) ) )
+                        || ( !bootPkgWildcards[i] && bootPkgs[i].equals( pkgName ) ) )
                 {
                     return true;
                 }
@@ -1548,7 +1521,7 @@ public class BundlesServlet extends Simp
             catch ( NumberFormatException nfe )
             {
                 log( LogService.LOG_INFO, "Cannot parse start level parameter " + startLevelItem
-                    + " to a number, not setting start level" );
+                        + " to a number, not setting start level" );
             }
         }
 
@@ -1628,7 +1601,7 @@ public class BundlesServlet extends Simp
 
 
     private void installBundle( String location, File bundleFile, int startLevel, boolean start, boolean refreshPackages )
-        throws IOException
+            throws IOException
     {
         if ( bundleFile != null )
         {
@@ -1653,7 +1626,7 @@ public class BundlesServlet extends Simp
                 for ( int i = 0; i < bundles.length; i++ )
                 {
                     if ( ( bundles[i].getLocation() != null && bundles[i].getLocation().equals( location ) )
-                        || ( bundles[i].getSymbolicName() != null && bundles[i].getSymbolicName().equals( symbolicName ) ) )
+                            || ( bundles[i].getSymbolicName() != null && bundles[i].getSymbolicName().equals( symbolicName ) ) )
                     {
                         updateBundle = bundles[i];
                         break;
@@ -1723,11 +1696,11 @@ public class BundlesServlet extends Simp
 
 
     private void installBackground( final File bundleFile, final String location, final int startlevel,
-        final boolean doStart, final boolean refreshPackages )
+            final boolean doStart, final boolean refreshPackages )
     {
 
         InstallHelper t = new InstallHelper( this, getBundleContext(), bundleFile, location, startlevel, doStart,
-            refreshPackages );
+                refreshPackages );
         t.start();
     }
 

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java?rev=1780102&r1=1780101&r2=1780102&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java Tue Jan 24 19:26:00 2017
@@ -35,8 +35,7 @@ import org.apache.felix.webconsole.WebCo
 import org.apache.felix.webconsole.WebConsoleUtil;
 import org.apache.felix.webconsole.internal.OsgiManagerPlugin;
 import org.apache.felix.webconsole.internal.Util;
-import org.json.JSONException;
-import org.json.JSONWriter;
+import org.apache.felix.webconsole.json.JSONWriter;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -132,11 +131,11 @@ public class ServicesServlet extends Sim
     }
 
     public void deactivate() {
-	if ( null != bipReg )
-	{
-	    bipReg.unregister();
-	    bipReg = null;
-	}
+        if ( null != bipReg )
+        {
+            bipReg.unregister();
+            bipReg = null;
+        }
         super.deactivate();
     }
 
@@ -213,7 +212,7 @@ public class ServicesServlet extends Sim
 
 
     private void renderJSON( final HttpServletResponse response, final ServiceReference service, final Locale locale )
-        throws IOException
+            throws IOException
     {
         response.setContentType( "application/json" );
         response.setCharacterEncoding( "UTF-8" );
@@ -222,8 +221,18 @@ public class ServicesServlet extends Sim
         writeJSON( pw, service, locale, null);
     }
 
+    private void keyVal( JSONWriter jw, String key, Object val) throws IOException
+    {
+        if ( val != null )
+        {
+            jw.object();
+            jw.key("key").value(key);
+            jw.key("value").value(val);
+            jw.endObject();
+        }
+    }
 
-    private void serviceDetails( JSONWriter jw, ServiceReference service ) throws JSONException
+    private void serviceDetails( JSONWriter jw, ServiceReference service ) throws IOException
     {
         String[] keys = service.getPropertyKeys();
 
@@ -235,19 +244,19 @@ public class ServicesServlet extends Sim
             String key = keys[i];
             if ( Constants.SERVICE_PID.equals( key ) )
             {
-                Util.keyVal( jw, "Service PID", service.getProperty( key ) );
+                keyVal(jw, "Service PID", service.getProperty( key ));
             }
             else if ( Constants.SERVICE_DESCRIPTION.equals( key ) )
             {
-                Util.keyVal( jw, "Service Description", service.getProperty( key ) );
+                keyVal(jw, "Service Description", service.getProperty( key ));
             }
             else if ( Constants.SERVICE_VENDOR.equals( key ) )
             {
-                Util.keyVal( jw, "Service Vendor", service.getProperty( key ) );
+                keyVal(jw, "Service Vendor", service.getProperty( key ));
             }
             else if ( !Constants.OBJECTCLASS.equals( key ) && !Constants.SERVICE_ID.equals( key ) )
             {
-                Util.keyVal( jw, key, service.getProperty( key ) );
+                keyVal(jw, key, service.getProperty( key ));
             }
 
         }
@@ -257,7 +266,7 @@ public class ServicesServlet extends Sim
     }
 
 
-    private void usingBundles( JSONWriter jw, ServiceReference service, Locale locale ) throws JSONException
+    private void usingBundles( JSONWriter jw, ServiceReference service, Locale locale ) throws IOException
     {
         jw.key( "usingBundles" );
         jw.array();
@@ -278,7 +287,8 @@ public class ServicesServlet extends Sim
     }
 
 
-    private void serviceInfo( JSONWriter jw, ServiceReference service, boolean details, final Locale locale ) throws JSONException
+    private void serviceInfo( JSONWriter jw, ServiceReference service, boolean details, final Locale locale )
+            throws IOException
     {
         jw.object();
         jw.key( "id" );
@@ -309,7 +319,8 @@ public class ServicesServlet extends Sim
     }
 
 
-    private void bundleInfo( final JSONWriter jw, final Bundle bundle, final Locale locale ) throws JSONException
+    private void bundleInfo( final JSONWriter jw, final Bundle bundle, final Locale locale )
+            throws IOException
     {
         jw.key( "bundleId" );
         jw.value( bundle.getBundleId() );
@@ -329,44 +340,36 @@ public class ServicesServlet extends Sim
 
 
     private void writeJSON( final Writer pw, final ServiceReference service, final boolean fullDetails, final Locale locale, final String filter )
-        throws IOException
+            throws IOException
     {
         final ServiceReference[] allServices = this.getServices(filter);
         final String statusLine = getStatusLine( allServices );
 
         final ServiceReference[] services = ( service != null ) ? new ServiceReference[]
-            { service } : allServices;
+                { service } : allServices;
 
-        final JSONWriter jw = new JSONWriter( pw );
-
-        try
-        {
-            jw.object();
+                final JSONWriter jw = new JSONWriter( pw );
 
-            jw.key( "status" );
-            jw.value( statusLine );
+                jw.object();
 
-            jw.key( "serviceCount" );
-            jw.value( allServices.length );
+                jw.key( "status" );
+                jw.value( statusLine );
 
-            jw.key( "data" );
+                jw.key( "serviceCount" );
+                jw.value( allServices.length );
 
-            jw.array();
+                jw.key( "data" );
 
-            for ( int i = 0; i < services.length; i++ )
-            {
-                serviceInfo( jw, services[i], fullDetails || service != null, locale );
-            }
+                jw.array();
 
-            jw.endArray();
+                for ( int i = 0; i < services.length; i++ )
+                {
+                    serviceInfo( jw, services[i], fullDetails || service != null, locale );
+                }
 
-            jw.endObject();
+                jw.endArray();
 
-        }
-        catch ( JSONException je )
-        {
-            throw new IOException( je.toString() );
-        }
+                jw.endObject();
 
     }
 
@@ -375,7 +378,7 @@ public class ServicesServlet extends Sim
      * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
      */
     protected void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException,
-        IOException
+    IOException
     {
         if (request.getPathInfo().indexOf("/res/") == -1)
         { // not resource

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java?rev=1780102&r1=1780101&r2=1780102&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java Tue Jan 24 19:26:00 2017
@@ -21,8 +21,12 @@ package org.apache.felix.webconsole.inte
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.StringWriter;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Locale;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
@@ -39,9 +43,7 @@ import org.apache.felix.webconsole.Simpl
 import org.apache.felix.webconsole.WebConsoleUtil;
 import org.apache.felix.webconsole.internal.OsgiManagerPlugin;
 import org.apache.felix.webconsole.internal.Util;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
+import org.apache.felix.webconsole.json.JSONWriter;
 import org.osgi.framework.Bundle;
 
 
@@ -49,10 +51,15 @@ import org.osgi.framework.Bundle;
  * LicenseServlet provides the licenses plugin that browses through the bundles,
  * searching for common license files.
  *
- * TODO: add support for 'Bundle-License' manifest header
  */
 public final class LicenseServlet extends SimpleWebConsolePlugin implements OsgiManagerPlugin
 {
+    public static final class Entry {
+        String url;
+        String path;
+        String jar;
+    }
+
     // common names (without extension) of the license files.
     static final String LICENSE_FILES[] =
         { "README", "DISCLAIMER", "LICENSE", "NOTICE", "DEPENDENCIES" };
@@ -79,7 +86,7 @@ public final class LicenseServlet extend
      * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
      */
     protected void doGet(HttpServletRequest request, HttpServletResponse response)
-        throws ServletException, IOException
+            throws ServletException, IOException
     {
         final PathInfo pathInfo = PathInfo.parse( request.getPathInfo() );
         if ( pathInfo != null )
@@ -106,37 +113,52 @@ public final class LicenseServlet extend
 
         // prepare variables
         DefaultVariableResolver vars = ( ( DefaultVariableResolver ) WebConsoleUtil.getVariableResolver( request ) );
-        vars.put( "__data__", getBundleData( bundles, request.getLocale() ).toString());
+        vars.put( "__data__", getBundleData( bundles, request.getLocale() ));
 
         res.getWriter().print(TEMPLATE);
     }
 
-    private static final JSONArray getBundleData(Bundle[] bundles, Locale locale) throws IOException
+    private static final String getBundleData(Bundle[] bundles, Locale locale) throws IOException
     {
-        JSONArray ret = new JSONArray();
-        try
+        final StringWriter json = new StringWriter();
+        final JSONWriter jw = new JSONWriter(json);
+        jw.array();
+
+        for (int i = 0; i < bundles.length; i++)
         {
-            for (int i = 0; i < bundles.length; i++)
-            {
-                Bundle bundle = bundles[i];
+            Bundle bundle = bundles[i];
 
-                JSONObject files = findResource(bundle, LICENSE_FILES);
-                addLicensesFromHeader(bundle, files);
-                if (files.length() > 0)
-                { // has resources
-                    JSONObject data = new JSONObject();
-                    data.put( "bid", bundle.getBundleId() );
-                    data.put( "title", Util.getName( bundle, locale ) );
-                    data.put( "files", files );
-                    ret.put( data );
+            List files = findResource(bundle, LICENSE_FILES);
+            addLicensesFromHeader(bundle, files);
+            if (!files.isEmpty())
+            { // has resources
+                jw.object();
+                jw.key( "bid").value( bundle.getBundleId() );
+                jw.key( "title").value( Util.getName( bundle, locale ) );
+                jw.key( "files");
+                jw.object();
+                jw.key("__res__");
+                jw.array();
+                Iterator iter = files.iterator();
+                while ( iter.hasNext() ) {
+                    jw.object();
+                    Entry entry = (Entry) iter.next();
+                    jw.key("path").value(entry.path);
+                    jw.key("url").value(entry.url);
+                    if ( entry.jar != null )
+                    {
+                        jw.key("jar").value(entry.jar);
+                    }
+                    jw.endObject();
                 }
+                jw.endArray();
+                jw.endObject();
+                jw.endObject();
             }
         }
-        catch (JSONException je)
-        {
-            throw new IOException(je.toString());
-        }
-        return ret;
+
+        jw.endArray();
+        return json.toString();
     }
 
 
@@ -145,8 +167,7 @@ public final class LicenseServlet extend
         return path.substring( path.lastIndexOf( '/' ) + 1 );
     }
 
-    private static final JSONObject addLicensesFromHeader(Bundle bundle, JSONObject files)
-        throws JSONException
+    private static final void addLicensesFromHeader(Bundle bundle, List files)
     {
         String target = (String) bundle.getHeaders("").get("Bundle-License");
         if (target != null)
@@ -175,19 +196,19 @@ public final class LicenseServlet extend
                     if (path.indexOf("://") == -1 && null == bundle.getEntry(path))
                         continue;
 
-                    JSONObject entry = new JSONObject();
-                    entry.put("path", path);
-                    entry.put("url", url);
-                    files.append("__res__", entry);
+                    Entry entry = new Entry();
+                    entry.path = path;
+                    entry.url = url;
+
+                    files.add(entry);
                 }
             }
         }
-        return files;
     }
 
-    private static final JSONObject findResource( Bundle bundle, String[] patterns ) throws IOException, JSONException
+    private static final List findResource( Bundle bundle, String[] patterns ) throws IOException
     {
-        JSONObject ret = new JSONObject();
+        final List files = new ArrayList();
 
         for ( int i = 0; i < patterns.length; i++ )
         {
@@ -197,10 +218,10 @@ public final class LicenseServlet extend
                 while ( entries.hasMoreElements() )
                 {
                     URL url = ( URL ) entries.nextElement();
-                    JSONObject entry = new JSONObject();
-                    entry.put( "path", url.getPath() );
-                    entry.put( "url", getName( url.getPath() ) );
-                    ret.append( "__res__", entry );
+                    Entry entry = new Entry();
+                    entry.path = url.getPath();
+                    entry.url = getName( url.getPath() ) ;
+                    files.add(entry);
                 }
             }
         }
@@ -211,7 +232,6 @@ public final class LicenseServlet extend
             while ( entries.hasMoreElements() )
             {
                 URL url = ( URL ) entries.nextElement();
-                final String resName = getName( url.getPath() );
 
                 InputStream ins = null;
                 try
@@ -234,11 +254,11 @@ public final class LicenseServlet extend
                         {
                             if ( name.startsWith( patterns[i] ) )
                             {
-                                JSONObject entry = new JSONObject();
-                                entry.put( "jar", url.getPath() );
-                                entry.put( "path", zentry.getName() );
-                                entry.put( "url", getName( name ) );
-                                ret.append( resName, entry );
+                                Entry entry = new Entry();
+                                entry.path = zentry.getName();
+                                entry.url = getName( name ) ;
+                                entry.jar = url.getPath();
+                                files.add(entry);
                             }
                         }
                     }
@@ -251,7 +271,7 @@ public final class LicenseServlet extend
             }
         }
 
-        return ret;
+        return files;
     }
 
 
@@ -282,8 +302,8 @@ public final class LicenseServlet extend
             {
                 resource = bundle.getResource( pathInfo.licenseFile );
             }
-        
-            
+
+
             if ( resource != null )
             {
                 final InputStream input = resource.openStream();