FELIX-4203 : ConfigAdmin plugin does not return json
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1648347 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigAdminSupport.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigAdminSupport.java
index f8bc2e5..ad6fd7a 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigAdminSupport.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigAdminSupport.java
@@ -31,12 +31,12 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedMap;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.Vector;
-import java.util.Map.Entry;
import javax.servlet.http.HttpServletRequest;
@@ -61,7 +61,7 @@
class ConfigAdminSupport
{
-
+
private static final String PROPERTY_FACTORYCONFIG_NAMEHINT = "webconsole.configurationFactory.nameHint";
private static final Set CONFIG_PROPERTIES_HIDE = new HashSet();
static {
@@ -200,10 +200,10 @@
String paramName = "action".equals(propName) //$NON-NLS-1$
|| ConfigManager.ACTION_DELETE.equals(propName)
|| ConfigManager.ACTION_APPLY.equals(propName)
- || ConfigManager.PROPERTY_LIST.equals(propName)
+ || ConfigManager.PROPERTY_LIST.equals(propName)
? '$' + propName : propName;
propsToKeep.add(propName);
-
+
PropertyDescriptor ad = (PropertyDescriptor) adMap.get( propName );
// try to derive from current value
@@ -593,7 +593,7 @@
configManager.log("listConfigurations: Unexpected problem encountered", e);
}
}
-
+
/**
* Builds a "name hint" for factory configuration based on other property
* values of the config and a "name hint template" defined as hidden
@@ -845,4 +845,9 @@
}
}
+
+ public Configuration[] listConfigurations(String filter) throws IOException, InvalidSyntaxException
+ {
+ return this.service.listConfigurations(filter);
+ }
}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java
index 0cc826e..d00532a 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java
@@ -19,9 +19,7 @@
import java.io.IOException;
import java.io.PrintWriter;
-import java.util.Iterator;
import java.util.Locale;
-import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@@ -33,6 +31,7 @@
import org.apache.felix.webconsole.internal.OsgiManagerPlugin;
import org.json.JSONException;
import org.json.JSONObject;
+import org.osgi.framework.Constants;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.service.cm.Configuration;
@@ -273,28 +272,58 @@
final ConfigAdminSupport ca = this.getConfigurationAdminSupport();
if ( ca != null )
{
+ // create filter
+ final StringBuffer sb = new StringBuffer();
+ if ( pid != null && pidFilter != null)
+ {
+ sb.append("(&");
+ }
+ if ( pid != null )
+ {
+ sb.append('(');
+ sb.append(Constants.SERVICE_PID);
+ sb.append('=');
+ sb.append(pid);
+ sb.append(')');
+ }
+ if ( pidFilter != null )
+ {
+ sb.append(pidFilter);
+ }
+ if ( pid != null && pidFilter != null)
+ {
+ sb.append(')');
+ }
+ final String filter = sb.toString();
try
{
- final Map services = ca.getServices( pid, pidFilter, locale, false );
+ // we use listConfigurations to not create configuration
+ // objects persistently without the user providing actual
+ // configuration
+ final Configuration[] configs = ca.listConfigurations( filter );
boolean printComma = false;
- for ( Iterator spi = services.keySet().iterator(); spi.hasNext(); )
+ for(int i=0; i<configs.length; i++)
{
- final String servicePid = ( String ) spi.next();
- final Configuration config = ca.getConfiguration( servicePid );
+ final Configuration config = configs[i];
if ( config != null )
{
if ( printComma )
{
pw.print( ',' );
}
- ca.printConfigurationJson( pw, servicePid, config, pidFilter, locale );
+ ca.printConfigurationJson( pw, config.getPid(), config, null, locale );
printComma = true;
}
}
}
- catch ( InvalidSyntaxException e )
+ catch ( final InvalidSyntaxException ise )
{
- // this should not happened as we checked the filter before
+ // should print message
+ // however this should not happen as we checked the filter before
+ }
+ catch ( final IOException ioe )
+ {
+ // should print message
}
}
pw.write( "]" ); //$NON-NLS-1$