Author: kien_nguyen
Date: 2011-08-15 07:36:41 -0400 (Mon, 15 Aug 2011)
New Revision: 7126
Removed:
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ShindigClientEndpoint.java
Modified:
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetEditor.java
portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/portal/PortalHttpRequest.js
portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/portal/gadget-configuration.xml
Log:
GTNPORTAL-1957: Caching issue when edit gadget in ApplicationRegistry (Revert to use
javascript request)
Deleted:
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ShindigClientEndpoint.java
===================================================================
---
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ShindigClientEndpoint.java 2011-08-15
10:39:08 UTC (rev 7125)
+++
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ShindigClientEndpoint.java 2011-08-15
11:36:41 UTC (rev 7126)
@@ -1,122 +0,0 @@
-/*
- * Copyright (C) 2011 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.exoplatform.portal.gadget.core;
-
-import org.exoplatform.container.xml.InitParams;
-import org.exoplatform.container.xml.ValueParam;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStreamWriter;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.Timer;
-import java.util.TimerTask;
-
-/**
- * An endpoint to send requests to Shindig from Portal.
- *
- * This endpoint is necessary as Shindig does not expose any public API to manipulates
- * its caches from Portal.
- *
- * @author <a href="hoang281283(a)gmail.com">Minh Hoang TO</a>
- * @date 8/15/11
- */
-public class ShindigClientEndpoint
-{
-
- private final long delay;
-
- private final Timer timer;
-
- public ShindigClientEndpoint(InitParams params) throws Exception
- {
- long delayTime = 1000;
- if(params != null)
- {
- ValueParam delayParam = params.getValueParam("delayTime");
- delayTime = Long.parseLong(delayParam.getValue());
- }
- delay = delayTime;
- timer = new Timer(true);
- }
-
- /**
- * Etablish URLConnection to shindigURL and post request data to it
- *
- * @param requestData
- * @param shindigURL
- */
- public void sendRequest(String requestData, String shindigURL)
- {
- timer.schedule(createTimerTask(requestData, shindigURL), delay);
- }
-
- private TimerTask createTimerTask(final String requestData, final String shindigURL)
- {
- return new TimerTask()
- {
- @Override
- public void run()
- {
- OutputStreamWriter out = null;
- InputStream in = null;
-
- try
- {
- URLConnection conn = new URL(shindigURL).openConnection();
- conn.setDoOutput(true);
- out = new OutputStreamWriter(conn.getOutputStream());
- out.write(requestData);
- out.flush();
-
- in = conn.getInputStream(); //Don't remove this if you don't
understand!
- }
- catch (IOException ioEx)
- {
- ioEx.printStackTrace();
-
- }
- finally
- {
- try
- {
- if (out != null)
- out.close();
- }
- catch (IOException ex)
- {
- ex.printStackTrace();
- }
-
- try
- {
- if (in != null)
- in.close();
- }
- catch (IOException ex)
- {
- ex.printStackTrace();
- }
- }
-
- }
- };
- }
-
-}
Modified:
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetEditor.java
===================================================================
---
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetEditor.java 2011-08-15
10:39:08 UTC (rev 7125)
+++
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetEditor.java 2011-08-15
11:36:41 UTC (rev 7126)
@@ -26,9 +26,8 @@
import org.exoplatform.application.gadget.GadgetRegistryService;
import org.exoplatform.application.gadget.Source;
import org.exoplatform.application.gadget.SourceStorage;
-import org.exoplatform.commons.serialization.api.annotations.Serialized;
-import org.exoplatform.portal.gadget.core.ShindigClientEndpoint;
import org.exoplatform.portal.webui.application.GadgetUtil;
+import org.exoplatform.commons.serialization.api.annotations.Serialized;
import org.exoplatform.web.application.ApplicationMessage;
import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.config.InitParams;
@@ -214,14 +213,6 @@
source.setLastModified(Calendar.getInstance());
sourceStorage.saveSource(gadget, source);
-
- //Send request to invalidate the cache on Shindig
- String requestData =
"{\"context\":{\"ignoreCache\":\"true\"},\"gadgets\":["
+ "{\"url\":\"" + GadgetUtil.reproduceUrl(gadget.getUrl(),
gadget.isLocal()) + "\"}]}";
- String gadgetServerURL = GadgetUtil.getGadgetServerUrl();
- String gadgetShindigURL = gadgetServerURL +
(gadgetServerURL.endsWith("/")?"" : "/") +
"metadata";
- ShindigClientEndpoint endPoint =
uiForm.getApplicationComponent(ShindigClientEndpoint.class);
- endPoint.sendRequest(requestData, gadgetShindigURL);
-
uiManagement.removeChild(UIGadgetEditor.class);
// This will update the source and also update the gadget related
// cached meta data
@@ -229,6 +220,13 @@
uiManagement.initData();
uiManagement.setSelectedGadget(gadget.getName());
event.getRequestContext().addUIComponentToUpdateByAjax(uiManagement);
+
+ //Send request to invalidate the cache to Shindig
+ String gadgetServerUrl = GadgetUtil.getGadgetServerUrl();
+ String gadgetUrl = GadgetUtil.reproduceUrl(gadget.getUrl(), gadget.isLocal());
+ String metadataUrl = gadgetServerUrl + (gadgetServerUrl.endsWith("/")
? "" : "/") + "metadata";
+ String queryString =
"{\"context\":{\"ignoreCache\":\"true\"},\"gadgets\":["
+ "{\"url\":\"" + gadgetUrl + "\"}]}";
+
event.getRequestContext().getJavascriptManager().addJavascript("ajaxAsyncRequest('"
+ metadataUrl + "', true, 'POST', '" + queryString +
"');");
}
}
Modified:
portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/portal/PortalHttpRequest.js
===================================================================
---
portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/portal/PortalHttpRequest.js 2011-08-15
10:39:08 UTC (rev 7125)
+++
portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/portal/PortalHttpRequest.js 2011-08-15
11:36:41 UTC (rev 7126)
@@ -724,17 +724,28 @@
} ;
/**
+ * Create a ajax GET request
+ * @param {String} url - Url
+ * @param {boolean} async - asynchronous or none
+ * @return {String} response text if request is not async
+ */
+function ajaxAsyncGetRequest(url, async) {
+ ajaxAsyncRequest("GET", url, async);
+}
+
+/**
* Create a ajax request
+ * @param {String} method - GET, POST, etc
* @param {String} url - Url
* @param {boolean} async - asynchronous or none
* @return {String} response text if request is not async
*/
-function ajaxAsyncGetRequest(url, async) {
+function ajaxAsyncRequest(url, async, method, queryString) {
if(async == undefined) async = true ;
var request = eXo.core.Browser.createHttpRequest() ;
- request.open('GET', url, async) ;
+ request.open(method, url, async) ;
request.setRequestHeader("Cache-Control", "max-age=86400") ;
- request.send(null) ;
+ request.send((queryString != undefined && queryString != null) ? queryString :
null) ;
eXo.session.itvDestroy() ;
if(eXo.session.canKeepState && eXo.session.isOpen &&
eXo.env.portal.accessMode == 'private') {
eXo.session.itvInit() ;
Modified:
portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/portal/gadget-configuration.xml
===================================================================
---
portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/portal/gadget-configuration.xml 2011-08-15
10:39:08 UTC (rev 7125)
+++
portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/portal/gadget-configuration.xml 2011-08-15
11:36:41 UTC (rev 7126)
@@ -39,10 +39,6 @@
</values-param>
</init-params>
</component>
-
- <component>
- <type>org.exoplatform.portal.gadget.core.ShindigClientEndpoint</type>
- </component>
<external-component-plugins>
<target-component>org.exoplatform.commons.chromattic.ChromatticManager</target-component>