You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by so...@apache.org on 2016/11/10 04:59:29 UTC
svn commit: r1769033 - in /openmeetings/application:
branches/3.1.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/
branches/3.2.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/
trunk/openmeetings-web/src/main/java/or...
Author: solomax
Date: Thu Nov 10 04:59:28 2016
New Revision: 1769033
URL: http://svn.apache.org/viewvc?rev=1769033&view=rev
Log:
[OPENMEETINGS-1498] websocket is not closed on ajax download
Added:
openmeetings/application/branches/3.1.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/ajax-download.js
openmeetings/application/branches/3.2.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/ajax-download.js
openmeetings/application/trunk/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/ajax-download.js
Modified:
openmeetings/application/branches/3.1.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/AjaxDownload.java
openmeetings/application/branches/3.2.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/AjaxDownload.java
openmeetings/application/trunk/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/AjaxDownload.java
Modified: openmeetings/application/branches/3.1.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/AjaxDownload.java
URL: http://svn.apache.org/viewvc/openmeetings/application/branches/3.1.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/AjaxDownload.java?rev=1769033&r1=1769032&r2=1769033&view=diff
==============================================================================
--- openmeetings/application/branches/3.1.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/AjaxDownload.java (original)
+++ openmeetings/application/branches/3.1.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/AjaxDownload.java Thu Nov 10 04:59:28 2016
@@ -18,10 +18,19 @@
*/
package org.apache.openmeetings.web.util;
+import java.util.UUID;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.Page;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AbstractAjaxBehavior;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.JavaScriptHeaderItem;
+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler;
import org.apache.wicket.request.resource.ContentDisposition;
+import org.apache.wicket.request.resource.JavaScriptResourceReference;
+import org.apache.wicket.request.resource.ResourceReference;
import org.apache.wicket.util.resource.IResourceStream;
/**
@@ -31,11 +40,10 @@ import org.apache.wicket.util.resource.I
*/
public class AjaxDownload extends AbstractAjaxBehavior {
private static final long serialVersionUID = 1L;
-
private boolean addAntiCache;
-
private String fileName;
private IResourceStream resourceStream;
+ private final String iframeId;
public AjaxDownload() {
this(true);
@@ -44,21 +52,40 @@ public class AjaxDownload extends Abstra
public AjaxDownload(boolean addAntiCache) {
super();
this.addAntiCache = addAntiCache;
+ iframeId = String.format("download-iframe-%s", UUID.randomUUID().toString());
}
/**
* Call this method to initiate the download.
*/
public void initiate(AjaxRequestTarget target) {
- String url = getCallbackUrl().toString();
+ StringBuilder url = new StringBuilder(getCallbackUrl());
if (addAntiCache) {
- url = url + (url.contains("?") ? "&" : "?");
- url = url + "antiCache=" + System.currentTimeMillis();
+ url.append(url.indexOf("?") > -1 ? "&" : "?")
+ .append("antiCache=").append(System.currentTimeMillis());
}
+ target.appendJavaScript(String.format("$('#%s').attr('src', '%s');", iframeId, url.toString()));
+ }
- // the timeout is needed to let Wicket release the channel
- target.appendJavaScript("setTimeout(\"window.location.href='" + url + "'\", 100);");
+ @Override
+ protected void onBind() {
+ super.onBind();
+ // it is impossible to get page by id anyway
+ if (!(getComponent() instanceof Page)) {
+ getComponent().setOutputMarkupId(true);
+ }
+ }
+
+ private static ResourceReference newResourceReference() {
+ return new JavaScriptResourceReference(AjaxDownload.class, "ajax-download.js");
+ }
+
+ @Override
+ public void renderHead(Component component, IHeaderResponse response) {
+ super.renderHead(component, response);
+ response.render(JavaScriptHeaderItem.forReference(newResourceReference()));
+ response.render(OnDomReadyHeaderItem.forScript(String.format("addDwnldIframe('%s', '%s');", component instanceof Page ? "" : component.getMarkupId(), iframeId)));
}
@Override
Added: openmeetings/application/branches/3.1.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/ajax-download.js
URL: http://svn.apache.org/viewvc/openmeetings/application/branches/3.1.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/ajax-download.js?rev=1769033&view=auto
==============================================================================
--- openmeetings/application/branches/3.1.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/ajax-download.js (added)
+++ openmeetings/application/branches/3.1.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/ajax-download.js Thu Nov 10 04:59:28 2016
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") + you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+function addDwnldIframe(compId, id) {
+ compId = !!compId ? '#' + compId : 'body';
+ $(compId).append('<iframe id="' + id + '" style="display:none" src="about:blank"></iframe>');
+}
Modified: openmeetings/application/branches/3.2.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/AjaxDownload.java
URL: http://svn.apache.org/viewvc/openmeetings/application/branches/3.2.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/AjaxDownload.java?rev=1769033&r1=1769032&r2=1769033&view=diff
==============================================================================
--- openmeetings/application/branches/3.2.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/AjaxDownload.java (original)
+++ openmeetings/application/branches/3.2.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/AjaxDownload.java Thu Nov 10 04:59:28 2016
@@ -18,10 +18,19 @@
*/
package org.apache.openmeetings.web.util;
+import java.util.UUID;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.Page;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AbstractAjaxBehavior;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.JavaScriptHeaderItem;
+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler;
import org.apache.wicket.request.resource.ContentDisposition;
+import org.apache.wicket.request.resource.JavaScriptResourceReference;
+import org.apache.wicket.request.resource.ResourceReference;
import org.apache.wicket.util.resource.IResourceStream;
/**
@@ -31,11 +40,10 @@ import org.apache.wicket.util.resource.I
*/
public class AjaxDownload extends AbstractAjaxBehavior {
private static final long serialVersionUID = 1L;
-
private boolean addAntiCache;
-
private String fileName;
private IResourceStream resourceStream;
+ private final String iframeId;
public AjaxDownload() {
this(true);
@@ -44,21 +52,40 @@ public class AjaxDownload extends Abstra
public AjaxDownload(boolean addAntiCache) {
super();
this.addAntiCache = addAntiCache;
+ iframeId = String.format("download-iframe-%s", UUID.randomUUID().toString());
}
/**
* Call this method to initiate the download.
*/
public void initiate(AjaxRequestTarget target) {
- String url = getCallbackUrl().toString();
+ StringBuilder url = new StringBuilder(getCallbackUrl());
if (addAntiCache) {
- url = url + (url.contains("?") ? "&" : "?");
- url = url + "antiCache=" + System.currentTimeMillis();
+ url.append(url.indexOf("?") > -1 ? "&" : "?")
+ .append("antiCache=").append(System.currentTimeMillis());
}
+ target.appendJavaScript(String.format("$('#%s').attr('src', '%s');", iframeId, url.toString()));
+ }
- // the timeout is needed to let Wicket release the channel
- target.appendJavaScript("setTimeout(\"window.location.href='" + url + "'\", 100);");
+ @Override
+ protected void onBind() {
+ super.onBind();
+ // it is impossible to get page by id anyway
+ if (!(getComponent() instanceof Page)) {
+ getComponent().setOutputMarkupId(true);
+ }
+ }
+
+ private static ResourceReference newResourceReference() {
+ return new JavaScriptResourceReference(AjaxDownload.class, "ajax-download.js");
+ }
+
+ @Override
+ public void renderHead(Component component, IHeaderResponse response) {
+ super.renderHead(component, response);
+ response.render(JavaScriptHeaderItem.forReference(newResourceReference()));
+ response.render(OnDomReadyHeaderItem.forScript(String.format("addDwnldIframe('%s', '%s');", component instanceof Page ? "" : component.getMarkupId(), iframeId)));
}
@Override
Added: openmeetings/application/branches/3.2.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/ajax-download.js
URL: http://svn.apache.org/viewvc/openmeetings/application/branches/3.2.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/ajax-download.js?rev=1769033&view=auto
==============================================================================
--- openmeetings/application/branches/3.2.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/ajax-download.js (added)
+++ openmeetings/application/branches/3.2.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/ajax-download.js Thu Nov 10 04:59:28 2016
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") + you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+function addDwnldIframe(compId, id) {
+ compId = !!compId ? '#' + compId : 'body';
+ $(compId).append('<iframe id="' + id + '" style="display:none" src="about:blank"></iframe>');
+}
Modified: openmeetings/application/trunk/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/AjaxDownload.java
URL: http://svn.apache.org/viewvc/openmeetings/application/trunk/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/AjaxDownload.java?rev=1769033&r1=1769032&r2=1769033&view=diff
==============================================================================
--- openmeetings/application/trunk/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/AjaxDownload.java (original)
+++ openmeetings/application/trunk/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/AjaxDownload.java Thu Nov 10 04:59:28 2016
@@ -18,10 +18,19 @@
*/
package org.apache.openmeetings.web.util;
+import java.util.UUID;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.Page;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AbstractAjaxBehavior;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.JavaScriptHeaderItem;
+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler;
import org.apache.wicket.request.resource.ContentDisposition;
+import org.apache.wicket.request.resource.JavaScriptResourceReference;
+import org.apache.wicket.request.resource.ResourceReference;
import org.apache.wicket.util.resource.IResourceStream;
/**
@@ -31,11 +40,10 @@ import org.apache.wicket.util.resource.I
*/
public class AjaxDownload extends AbstractAjaxBehavior {
private static final long serialVersionUID = 1L;
-
private boolean addAntiCache;
-
private String fileName;
private IResourceStream resourceStream;
+ private final String iframeId;
public AjaxDownload() {
this(true);
@@ -44,21 +52,40 @@ public class AjaxDownload extends Abstra
public AjaxDownload(boolean addAntiCache) {
super();
this.addAntiCache = addAntiCache;
+ iframeId = String.format("download-iframe-%s", UUID.randomUUID().toString());
}
/**
* Call this method to initiate the download.
*/
public void initiate(AjaxRequestTarget target) {
- String url = getCallbackUrl().toString();
+ StringBuilder url = new StringBuilder(getCallbackUrl());
if (addAntiCache) {
- url = url + (url.contains("?") ? "&" : "?");
- url = url + "antiCache=" + System.currentTimeMillis();
+ url.append(url.indexOf("?") > -1 ? "&" : "?")
+ .append("antiCache=").append(System.currentTimeMillis());
}
+ target.appendJavaScript(String.format("$('#%s').attr('src', '%s');", iframeId, url.toString()));
+ }
- // the timeout is needed to let Wicket release the channel
- target.appendJavaScript("setTimeout(\"window.location.href='" + url + "'\", 100);");
+ @Override
+ protected void onBind() {
+ super.onBind();
+ // it is impossible to get page by id anyway
+ if (!(getComponent() instanceof Page)) {
+ getComponent().setOutputMarkupId(true);
+ }
+ }
+
+ private static ResourceReference newResourceReference() {
+ return new JavaScriptResourceReference(AjaxDownload.class, "ajax-download.js");
+ }
+
+ @Override
+ public void renderHead(Component component, IHeaderResponse response) {
+ super.renderHead(component, response);
+ response.render(JavaScriptHeaderItem.forReference(newResourceReference()));
+ response.render(OnDomReadyHeaderItem.forScript(String.format("addDwnldIframe('%s', '%s');", component instanceof Page ? "" : component.getMarkupId(), iframeId)));
}
@Override
Added: openmeetings/application/trunk/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/ajax-download.js
URL: http://svn.apache.org/viewvc/openmeetings/application/trunk/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/ajax-download.js?rev=1769033&view=auto
==============================================================================
--- openmeetings/application/trunk/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/ajax-download.js (added)
+++ openmeetings/application/trunk/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/ajax-download.js Thu Nov 10 04:59:28 2016
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") + you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+function addDwnldIframe(compId, id) {
+ compId = !!compId ? '#' + compId : 'body';
+ $(compId).append('<iframe id="' + id + '" style="display:none" src="about:blank"></iframe>');
+}