Author: mwringe
Date: 2011-08-18 14:49:41 -0400 (Thu, 18 Aug 2011)
New Revision: 7177
Added:
epp/portal/branches/EPP_5_2_Branch/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ShindigClientEndpoint.java
Modified:
epp/portal/branches/EPP_5_2_Branch/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetEditor.java
epp/portal/branches/EPP_5_2_Branch/web/eXoResources/src/main/webapp/javascript/eXo/portal/PortalHttpRequest.js
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/UIFormTextAreaInput.java
Log:
JBEPP-1002: merge in patches for gadget caching issues in App.Registry
Added:
epp/portal/branches/EPP_5_2_Branch/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ShindigClientEndpoint.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ShindigClientEndpoint.java
(rev 0)
+++
epp/portal/branches/EPP_5_2_Branch/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ShindigClientEndpoint.java 2011-08-18
18:49:41 UTC (rev 7177)
@@ -0,0 +1,122 @@
+/*
+ * 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:
epp/portal/branches/EPP_5_2_Branch/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetEditor.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetEditor.java 2011-08-18
15:47:03 UTC (rev 7176)
+++
epp/portal/branches/EPP_5_2_Branch/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetEditor.java 2011-08-18
18:49:41 UTC (rev 7177)
@@ -26,9 +26,10 @@
import org.exoplatform.application.gadget.GadgetRegistryService;
import org.exoplatform.application.gadget.Source;
import org.exoplatform.application.gadget.SourceStorage;
+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.commons.serialization.api.annotations.Serialized;
import org.exoplatform.webui.config.InitParams;
import org.exoplatform.webui.config.Param;
import org.exoplatform.webui.config.annotation.ComponentConfig;
@@ -37,20 +38,18 @@
import org.exoplatform.webui.core.UIApplication;
import org.exoplatform.webui.core.lifecycle.UIFormLifecycle;
import org.exoplatform.webui.event.Event;
+import org.exoplatform.webui.event.Event.Phase;
import org.exoplatform.webui.event.EventListener;
-import org.exoplatform.webui.event.Event.Phase;
import org.exoplatform.webui.exception.MessageException;
import org.exoplatform.webui.form.UIForm;
import org.exoplatform.webui.form.UIFormInput;
import org.exoplatform.webui.form.UIFormStringInput;
import org.exoplatform.webui.form.UIFormTextAreaInput;
import org.exoplatform.webui.form.validator.ExpressionValidator;
-import org.exoplatform.webui.form.validator.IdentifierValidator;
import org.exoplatform.webui.form.validator.MandatoryValidator;
import org.exoplatform.webui.form.validator.ResourceValidator;
import org.exoplatform.webui.form.validator.StringLengthValidator;
import org.exoplatform.webui.form.validator.Validator;
-
import java.io.Serializable;
import java.util.Calendar;
@@ -214,7 +213,6 @@
source.setLastModified(Calendar.getInstance());
sourceStorage.saveSource(gadget, source);
-
uiManagement.removeChild(UIGadgetEditor.class);
// This will update the source and also update the gadget related
// cached meta data
@@ -222,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:
epp/portal/branches/EPP_5_2_Branch/web/eXoResources/src/main/webapp/javascript/eXo/portal/PortalHttpRequest.js
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/web/eXoResources/src/main/webapp/javascript/eXo/portal/PortalHttpRequest.js 2011-08-18
15:47:03 UTC (rev 7176)
+++
epp/portal/branches/EPP_5_2_Branch/web/eXoResources/src/main/webapp/javascript/eXo/portal/PortalHttpRequest.js 2011-08-18
18:49:41 UTC (rev 7177)
@@ -626,17 +626,28 @@
eXo.portal.CurrentRequest = null ;
} ;
/**
+ * 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:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/UIFormTextAreaInput.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/UIFormTextAreaInput.java 2011-08-18
15:47:03 UTC (rev 7176)
+++
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/UIFormTextAreaInput.java 2011-08-18
18:49:41 UTC (rev 7177)
@@ -42,10 +42,6 @@
*/
private int columns = 30;
- /**
- * HTML Entity Encoder
- */
- private EntityEncoder entityEncoder = EntityEncoder.FULL;
public UIFormTextAreaInput()
{
@@ -78,7 +74,9 @@
w.append("
cols=\"").append(String.valueOf(columns)).append("\"");
w.write(">");
if (value != null)
- w.write(entityEncoder.encode(value));
+ //TODO: remove from other components and than encode here
+ //w.write(org.gatein.common.text.EntityEncoder.FULL.encode(value));
+ w.write(value);
w.write("</textarea>");
if (this.isMandatory())
w.write(" *");