Author: alain_defrance
Date: 2011-02-28 05:42:35 -0500 (Mon, 28 Feb 2011)
New Revision: 5949
Modified:
portal/branches/shindig2/gadgets/core/pom.xml
portal/branches/shindig2/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ExoModule.java
portal/branches/shindig2/gadgets/server/pom.xml
portal/branches/shindig2/gadgets/server/src/main/webapp/WEB-INF/web.xml
portal/branches/shindig2/gadgets/server/src/main/webapp/containers/default/container.js
portal/branches/shindig2/pom.xml
portal/branches/shindig2/web/eXoResources/src/main/webapp/javascript/eXo/gadget/Gadgets.js
portal/branches/shindig2/web/eXoResources/src/main/webapp/javascript/eXo/gadget/UIGadget.js
portal/branches/shindig2/web/portal/src/main/webapp/groovy/portal/webui/application/UIGadget.gtmpl
portal/branches/shindig2/webui/portal/src/main/java/org/exoplatform/portal/webui/application/GadgetUtil.java
portal/branches/shindig2/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIGadget.java
Log:
- Fix RPC service to help getting gadget's metadata by calling rpc URI:
gadgets/api/rpc. I also remove shindig-server dependency that don't be used anywhere
in GateIn.
- Change fetching gadget data of GateIn, instead of calling metadata service,now we will
use via RPC
Modified: portal/branches/shindig2/gadgets/core/pom.xml
===================================================================
--- portal/branches/shindig2/gadgets/core/pom.xml 2011-02-28 08:13:04 UTC (rev 5948)
+++ portal/branches/shindig2/gadgets/core/pom.xml 2011-02-28 10:42:35 UTC (rev 5949)
@@ -91,6 +91,10 @@
<artifactId>shindig-features</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.shindig</groupId>
+ <artifactId>shindig-social-api</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.chromattic</groupId>
<artifactId>chromattic.api</artifactId>
</dependency>
Modified:
portal/branches/shindig2/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ExoModule.java
===================================================================
---
portal/branches/shindig2/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ExoModule.java 2011-02-28
08:13:04 UTC (rev 5948)
+++
portal/branches/shindig2/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ExoModule.java 2011-02-28
10:42:35 UTC (rev 5949)
@@ -20,9 +20,17 @@
package org.exoplatform.portal.gadget.core;
import com.google.inject.AbstractModule;
+import com.google.inject.name.Names;
+
import org.apache.shindig.config.ContainerConfig;
import org.apache.shindig.gadgets.DefaultGuiceModule;
import org.apache.shindig.gadgets.http.HttpFetcher;
+import org.apache.shindig.protocol.conversion.BeanConverter;
+import org.apache.shindig.protocol.conversion.BeanJsonConverter;
+import org.apache.shindig.protocol.conversion.BeanXStreamConverter;
+import org.apache.shindig.protocol.conversion.xstream.XStreamConfiguration;
+import org.apache.shindig.social.core.util.xstream.XStream081Configuration;
+import org.apache.shindig.social.core.util.BeanXStreamAtomConverter;
/**
* The goal of the module is to bind the {@link
org.apache.shindig.common.ContainerConfig} interface to the
@@ -40,5 +48,9 @@
{
bind(ContainerConfig.class).to(ExoContainerConfig.class);
bind(HttpFetcher.class).to(ExoHttpFetcher.class);
+ bind(XStreamConfiguration.class).to(XStream081Configuration.class);
+
bind(BeanConverter.class).annotatedWith(Names.named("shindig.bean.converter.xml")).to(BeanXStreamConverter.class);
+
bind(BeanConverter.class).annotatedWith(Names.named("shindig.bean.converter.json")).to(BeanJsonConverter.class);
+
bind(BeanConverter.class).annotatedWith(Names.named("shindig.bean.converter.atom")).to(BeanXStreamAtomConverter.class);
}
}
Modified: portal/branches/shindig2/gadgets/server/pom.xml
===================================================================
--- portal/branches/shindig2/gadgets/server/pom.xml 2011-02-28 08:13:04 UTC (rev 5948)
+++ portal/branches/shindig2/gadgets/server/pom.xml 2011-02-28 10:42:35 UTC (rev 5949)
@@ -49,12 +49,6 @@
<!-- project dependencies -->
<dependency>
<groupId>org.apache.shindig</groupId>
- <artifactId>shindig-server</artifactId>
- <type>war</type>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.shindig</groupId>
<artifactId>shindig-features</artifactId>
<scope>provided</scope>
</dependency>
Modified: portal/branches/shindig2/gadgets/server/src/main/webapp/WEB-INF/web.xml
===================================================================
--- portal/branches/shindig2/gadgets/server/src/main/webapp/WEB-INF/web.xml 2011-02-28
08:13:04 UTC (rev 5948)
+++ portal/branches/shindig2/gadgets/server/src/main/webapp/WEB-INF/web.xml 2011-02-28
10:42:35 UTC (rev 5949)
@@ -79,7 +79,6 @@
</filter-mapping>
<listener>
-
<!--<listener-class>org.apache.shindig.common.servlet.GuiceServletContextListener</listener-class>-->
<listener-class>org.exoplatform.portal.gadget.core.GateInGuiceServletContextListener</listener-class>
</listener>
@@ -139,7 +138,7 @@
</servlet-class>
<init-param>
<param-name>handlers</param-name>
- <param-value>org.apache.shindig.gadgets.handlers</param-value>
+ <param-value>org.apache.shindig.handlers</param-value>
</init-param>
</servlet>
@@ -150,7 +149,7 @@
</servlet-class>
<init-param>
<param-name>handlers</param-name>
- <param-value>org.apache.shindig.gadgets.handlers</param-value>
+ <param-value>org.apache.shindig.handlers</param-value>
</init-param>
</servlet>
Modified:
portal/branches/shindig2/gadgets/server/src/main/webapp/containers/default/container.js
===================================================================
---
portal/branches/shindig2/gadgets/server/src/main/webapp/containers/default/container.js 2011-02-28
08:13:04 UTC (rev 5948)
+++
portal/branches/shindig2/gadgets/server/src/main/webapp/containers/default/container.js 2011-02-28
10:42:35 UTC (rev 5949)
@@ -80,7 +80,7 @@
//New configuration for iframeUri generation:
"gadgets.uri.iframe.lockedDomainSuffix" : "-a.example.com:8080",
-"gadgets.uri.iframe.unlockedDomain" : "localhost:8080",
+"gadgets.uri.iframe.unlockedDomain" : "http://localhost:8080",
"gadgets.uri.iframe.basePath" : "/eXoGadgetServer/gadgets/ifr",
@@ -94,7 +94,7 @@
// Config param to load Opensocial data for social
// preloads in data pipelining. %host% will be
// substituted with the current host.
-"gadgets.osDataUri" : "http://%host%/social/rpc",
+"gadgets.osDataUri" : "http://%host%/rpc",
"gadgets.signingKeyFile" : "oauthkey.pem",
"gadgets.signingKeyName" : "mytestkey",
@@ -172,7 +172,8 @@
"opensocial-0.8" : {
// Path to fetch opensocial data from
// Must be on the same domain as the gadget rendering server
- "path" : "http://%host%/social",
+ "path" : "http://%host%/rpc",
+ "invalidatePath" : "http://%host%/rpc",
"domain" : "shindig",
"enableCaja" : false,
"supportedFields" : {
@@ -190,10 +191,10 @@
// E.g. "gadgets.rpc" : ["activities.requestCreate",
"messages.requestSend", "requestShareApp",
"requestPermission"]
"gadgets.rpc" : ["container.listMethods"]
},
-// "osapi" : {
-// // The endpoints to query for available JSONRPC/REST services
-// "endPoints" : [ "http://%host%/social/rpc",
"http://%host%/gadgets/api/rpc" ]
-// },
+ "osapi" : {
+ // The endpoints to query for available JSONRPC/REST services
+ "endPoints" : [ "http://%host%/rpc" ]
+ },
"osml": {
// OSML library resource. Can be set to null or the empty string to disable OSML
// for a container.
Modified: portal/branches/shindig2/pom.xml
===================================================================
--- portal/branches/shindig2/pom.xml 2011-02-28 08:13:04 UTC (rev 5948)
+++ portal/branches/shindig2/pom.xml 2011-02-28 10:42:35 UTC (rev 5949)
@@ -878,17 +878,6 @@
</dependency>
<dependency>
<groupId>org.apache.shindig</groupId>
- <artifactId>shindig-server</artifactId>
- <version>${org.shindig.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.shindig</groupId>
- <artifactId>shindig-server</artifactId>
- <version>${org.shindig.version}</version>
- <type>war</type>
- </dependency>
- <dependency>
- <groupId>org.apache.shindig</groupId>
<artifactId>shindig-social-api</artifactId>
<version>${org.shindig.version}</version>
</dependency>
Modified:
portal/branches/shindig2/web/eXoResources/src/main/webapp/javascript/eXo/gadget/Gadgets.js
===================================================================
---
portal/branches/shindig2/web/eXoResources/src/main/webapp/javascript/eXo/gadget/Gadgets.js 2011-02-28
08:13:04 UTC (rev 5948)
+++
portal/branches/shindig2/web/eXoResources/src/main/webapp/javascript/eXo/gadget/Gadgets.js 2011-02-28
10:42:35 UTC (rev 5949)
@@ -631,7 +631,7 @@
var j = 0;
for (var att in prefs) {
//TODO: dang.tung not append when using list
- type = prefs[att].type;
+ type = prefs[att].dataType.toLowerCase();
if(type == "list"|| type == "hidden") continue;
// end
var attEl = document.createElement("div");
Modified:
portal/branches/shindig2/web/eXoResources/src/main/webapp/javascript/eXo/gadget/UIGadget.js
===================================================================
---
portal/branches/shindig2/web/eXoResources/src/main/webapp/javascript/eXo/gadget/UIGadget.js 2011-02-28
08:13:04 UTC (rev 5948)
+++
portal/branches/shindig2/web/eXoResources/src/main/webapp/javascript/eXo/gadget/UIGadget.js 2011-02-28
10:42:35 UTC (rev 5949)
@@ -52,11 +52,11 @@
var gadget;
if (metadata != null) {
// Check if gadget's height is not set and current view is canvas. By
default, gadget's height is 800px
- if(metadata.gadgets[0].height == 0 && view == 'canvas') {
- metadata.gadgets[0].height = "800px";
+ if(metadata.modulePrefs.height == 0 && view == 'canvas') {
+ metadata.modulePrefs.height = "800px";
}
- gadget = gadgets.container.createGadget({specUrl: url,height:
metadata.gadgets[0].height, secureToken: metadata.gadgets[0].secureToken, view: view});
- gadget.metadata = metadata.gadgets[0];
+ gadget = gadgets.container.createGadget({specUrl: url,height:
metadata.modulePrefs.height, secureToken: metadata.secureToken, view: view});
+ gadget.metadata = metadata;
} else {
gadget = gadgets.container.createGadget({specUrl: url});
}
@@ -101,7 +101,7 @@
gadgetControl.style.display = "block";
var gadgetTitle = eXo.core.DOMUtil.findFirstDescendantByClass(gadgetControl,
"div", "GadgetTitle") ;
gadgetTitle.style.display = "block";
- if (metadata && metadata.title != null &&
metadata.title.length > 0) gadgetTitle.innerHTML = metadata.title;
+ if (metadata && metadata.modulePrefs.title != null &&
metadata.modulePrefs.title.length > 0) gadgetTitle.innerHTML =
metadata.modulePrefs.title;
}
if (inDesktop) {
Modified:
portal/branches/shindig2/web/portal/src/main/webapp/groovy/portal/webui/application/UIGadget.gtmpl
===================================================================
---
portal/branches/shindig2/web/portal/src/main/webapp/groovy/portal/webui/application/UIGadget.gtmpl 2011-02-28
08:13:04 UTC (rev 5948)
+++
portal/branches/shindig2/web/portal/src/main/webapp/groovy/portal/webui/application/UIGadget.gtmpl 2011-02-28
10:42:35 UTC (rev 5949)
@@ -20,7 +20,7 @@
def isLossData = uicomponent.isLossData();
if(!isLossData) {
url = uicomponent.getUrl();
- metadata = uicomponent.getMetadata();
+ metadata = uicomponent.getRpcMetadata();
userPref = uicomponent.getUserPref();
jsmanager.importJavascript("eXo.gadget.UIGadget");
rcontext.getJavascriptManager().addCustomizedOnLoadScript("eXo.gadget.UIGadget.confirmDeleteGadget
= '" + _ctx.appRes("UIGadgetContainerManagement.confirm.DeleteGadget")
+ "';");
Modified:
portal/branches/shindig2/webui/portal/src/main/java/org/exoplatform/portal/webui/application/GadgetUtil.java
===================================================================
---
portal/branches/shindig2/webui/portal/src/main/java/org/exoplatform/portal/webui/application/GadgetUtil.java 2011-02-28
08:13:04 UTC (rev 5948)
+++
portal/branches/shindig2/webui/portal/src/main/java/org/exoplatform/portal/webui/application/GadgetUtil.java 2011-02-28
10:42:35 UTC (rev 5949)
@@ -28,6 +28,7 @@
import org.exoplatform.portal.application.PortalRequestContext;
import org.exoplatform.portal.gadget.core.SecurityTokenGenerator;
import org.exoplatform.portal.webui.util.Util;
+import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -73,6 +74,7 @@
*
* @return the string represents metadata of gadget application
*/
+ @Deprecated
public static String fetchGagdetMetadata(String urlStr)
{
String result = null;
@@ -82,14 +84,15 @@
(GadgetRegistryService)container.getComponentInstanceOfType(GadgetRegistryService.class);
try
{
- String data =
- "{\"context\":{\"country\":\"" +
gadgetService.getCountry() + "\",\"language\":\""
- + gadgetService.getLanguage() +
"\"},\"gadgets\":[" + "{\"moduleId\":" +
gadgetService.getModuleId()
- + ",\"url\":\"" + urlStr +
"\",\"prefs\":[]}]}";
+ String data = "[{method:\"gadgets.metadata\",
id:\"test\", params: {ids:[\""
+ + urlStr + "\"], container:\"default\",
language:\""
+ + gadgetService.getLanguage() + "\", country:\"" +
gadgetService.getCountry() + "\", view:\"home\"}}]";
+
// Send data
String gadgetServer = getGadgetServerUrl();
- URL url = new URL(gadgetServer + (gadgetServer.endsWith("/") ?
"" : "/") + "metadata");
+ URL url = new URL(gadgetServer + (gadgetServer.endsWith("/") ?
"" : "/") + "api/rpc");
URLConnection conn = url.openConnection();
+ conn.setRequestProperty("Content-Type",
"application/json");
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
@@ -106,6 +109,47 @@
return result;
}
+ /**
+ * Fetchs Metatada of gadget application, create the connection to shindig
+ * server to get the metadata TODO cache the informations for better
+ * performance
+ *
+ * @return the string represents metadata of gadget application
+ */
+ public static String fetchGagdetRpcMetadata(String urlStr)
+ {
+ String result = null;
+
+ ExoContainer container = ExoContainerContext.getCurrentContainer();
+ GadgetRegistryService gadgetService =
+
(GadgetRegistryService)container.getComponentInstanceOfType(GadgetRegistryService.class);
+ try
+ {
+ String data = "[{method:\"gadgets.metadata\",
id:\"test\", params: {ids:[\""
+ + urlStr + "\"], container:\"default\",
language:\""
+ + gadgetService.getLanguage() + "\", country:\"" +
gadgetService.getCountry() + "\", view:\"home\"}}]";
+
+ // Send data
+ String gadgetServer = getGadgetServerUrl();
+ URL url = new URL(gadgetServer + (gadgetServer.endsWith("/") ?
"" : "/") + "api/rpc");
+ URLConnection conn = url.openConnection();
+ conn.setRequestProperty("Content-Type",
"application/json");
+ conn.setDoOutput(true);
+ OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
+ wr.write(data);
+ wr.flush();
+ // Get the response
+ result = IOUtils.toString(conn.getInputStream(), "UTF-8");
+ wr.close();
+ }
+ catch (IOException ioexc)
+ {
+ ioexc.printStackTrace();
+ return "{}";
+ }
+ return result;
+ }
+
public static String createToken(String gadgetURL, Long moduleId)
{
SecurityTokenGenerator tokenGenerator =
@@ -125,9 +169,9 @@
static public Map<String, String> getMapMetadata(String url) throws
JSONException
{
Map<String, String> mapMetaData = new HashMap<String, String>();
- String metadata = fetchGagdetMetadata(url);
+ String metadata = fetchGagdetRpcMetadata(url);
metadata = metadata.substring(metadata.indexOf("[") + 1,
metadata.lastIndexOf("]"));
- JSONObject jsonObj = new JSONObject(metadata);
+ JSONObject jsonObj = new
JSONObject(metadata).getJSONObject(UIGadget.RPC_RESULT).getJSONObject(url).getJSONObject(UIGadget.METADATA_MODULEPREFS);
Iterator<String> iter = jsonObj.keys();
while (iter.hasNext())
{
Modified:
portal/branches/shindig2/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIGadget.java
===================================================================
---
portal/branches/shindig2/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIGadget.java 2011-02-28
08:13:04 UTC (rev 5948)
+++
portal/branches/shindig2/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIGadget.java 2011-02-28
10:42:35 UTC (rev 5949)
@@ -94,8 +94,12 @@
public static final String METADATA_USERPREFS = "userPrefs";
- public static final String METADATA_USERPREFS_TYPE = "type";
+ public static final String METADATA_MODULEPREFS = "modulePrefs";
+ public static final String RPC_RESULT = "result";
+
+ public static final String METADATA_USERPREFS_TYPE = "dataType";
+
public static final String METADATA_USERPREFS_TYPE_HIDDEN = "hidden";
public static final String METADATA_USERPREFS_TYPE_LIST = "list";
@@ -207,13 +211,14 @@
this.properties_ = properties;
}
+ @Deprecated
public String getMetadata()
{
try
{
if (metadata_ == null)
{
- String strMetadata = GadgetUtil.fetchGagdetMetadata(getUrl());
+ String strMetadata = GadgetUtil.fetchGagdetRpcMetadata(getUrl());
metadata_ = new JSONObject(strMetadata);
}
JSONObject obj = metadata_.getJSONArray(METADATA_GADGETS).getJSONObject(0);
@@ -226,6 +231,27 @@
return null;
}
}
+
+ public String getRpcMetadata()
+ {
+ try
+ {
+ if (metadata_ == null)
+ {
+ String gadgetUrl = getUrl();
+ String strMetadata = GadgetUtil.fetchGagdetRpcMetadata(gadgetUrl);
+ metadata_ = new
JSONArray(strMetadata).getJSONObject(0).getJSONObject(UIGadget.RPC_RESULT).getJSONObject(gadgetUrl);
+ }
+ String token = GadgetUtil.createToken(this.getUrl(), new Random().nextLong());
+ metadata_.put("secureToken", token);
+ return metadata_.toString();
+ }
+ catch (JSONException e)
+ {
+ return null;
+ }
+ }
+
/**
* Check if content of gadget has <UserPref>? (Content is parsed from gadget
specification in .xml file)
* @return boolean
@@ -236,8 +262,7 @@
{
if(metadata_ != null)
{
- JSONObject obj = metadata_.getJSONArray(METADATA_GADGETS).getJSONObject(0);
- JSONObject userPrefs = obj.getJSONObject(METADATA_USERPREFS);
+ JSONObject userPrefs = metadata_.getJSONObject(METADATA_USERPREFS);
JSONArray names = userPrefs.names();
int count = names.length();
if(count > 0)