You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by aw...@apache.org on 2009/04/08 06:27:53 UTC
svn commit: r763099 -
/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/config/JsonContainerConfig.java
Author: awiner
Date: Wed Apr 8 04:27:53 2009
New Revision: 763099
URL: http://svn.apache.org/viewvc?rev=763099&view=rev
Log:
SHINDIG-1010: Race condition in JsonContainerConfig EL evaluation
- Aggressively evaluate all EL in the container configs, avoiding attempts to use ELContexts from multiple threads
Modified:
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/config/JsonContainerConfig.java
Modified: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/config/JsonContainerConfig.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/config/JsonContainerConfig.java?rev=763099&r1=763098&r2=763099&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/config/JsonContainerConfig.java (original)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/config/JsonContainerConfig.java Wed Apr 8 04:27:53 2009
@@ -24,6 +24,8 @@
import org.apache.shindig.common.util.ResourceLoader;
import org.apache.shindig.expressions.Expressions;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -80,6 +82,7 @@
throws ContainerConfigException {
this.expressions = expressions;
config = createContainers(loadContainers(containers));
+ evaluateConfig();
}
/**
@@ -88,6 +91,7 @@
public JsonContainerConfig(JSONObject json, Expressions expressions) {
this.expressions = expressions;
config = createContainers(json);
+ evaluateConfig();
}
@Override
@@ -350,4 +354,34 @@
public String toString() {
return JsonSerializer.serialize(config);
}
+
+ private void evaluateConfig() {
+ for (Map.Entry<String, Map<String, Object>> configEntry : config.entrySet()) {
+ @SuppressWarnings("unchecked")
+ Map<String, Object> value = (Map<String, Object>) evaluateAll(configEntry.getValue());
+ configEntry.setValue(value);
+ }
+ }
+
+ private Object evaluateAll(Object value) {
+ if (value instanceof CharSequence) {
+ return value.toString();
+ } else if (value instanceof Map) {
+ ImmutableMap.Builder<Object, Object> newMap = ImmutableMap.builder();
+ for (Map.Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) {
+ newMap.put(entry.getKey(), evaluateAll(entry.getValue()));
+ }
+
+ return newMap.build();
+ } else if (value instanceof List) {
+ ImmutableList.Builder<Object> newList = ImmutableList.builder();
+ for (Object entry : (List<?>) value) {
+ newList.add(evaluateAll(entry));
+ }
+
+ return newList.build();
+ } else {
+ return value;
+ }
+ }
}