You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2013/07/25 11:20:53 UTC
svn commit: r1506857 - in /activemq/activemq-apollo/trunk:
apollo-distro/src/main/release/examples/stomp/websocket/js/
apollo-stomp/src/test/resources/org/apache/activemq/apollo/stomp/test/
apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/t...
Author: chirino
Date: Thu Jul 25 09:20:53 2013
New Revision: 1506857
URL: http://svn.apache.org/r1506857
Log:
Test and partial fix for APLO-325: Modify the stomp.js client so that it limits how big a WS frame can be.
Added:
activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/org/apache/activemq/apollo/stomp/test/websocket-large.html
Modified:
activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/stomp/websocket/js/stomp.js
activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompWebSocketTests.scala
Modified: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/stomp/websocket/js/stomp.js
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/stomp/websocket/js/stomp.js?rev=1506857&r1=1506856&r2=1506857&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/stomp/websocket/js/stomp.js (original)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/stomp/websocket/js/stomp.js Thu Jul 25 09:20:53 2013
@@ -2,7 +2,9 @@
(function() {
var Byte, Client, Frame, Stomp,
__hasProp = {}.hasOwnProperty;
-
+
+ var MAX_FRAME_SIZE=16*1024;;
+
Byte = {
LF: '\x0A',
NULL: '\x00'
@@ -111,7 +113,14 @@
if (typeof this.debug === "function") {
this.debug(">>> " + out);
}
- return this.ws.send(out);
+ while( true) {
+ if( out.length > MAX_FRAME_SIZE ) {
+ this.ws.send(out.substring(0, MAX_FRAME_SIZE));
+ out = out.substring(MAX_FRAME_SIZE);
+ } else {
+ return this.ws.send(out);
+ }
+ }
};
Client.prototype._setupHeartbeat = function(headers) {
Added: activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/org/apache/activemq/apollo/stomp/test/websocket-large.html
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/org/apache/activemq/apollo/stomp/test/websocket-large.html?rev=1506857&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/org/apache/activemq/apollo/stomp/test/websocket-large.html (added)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/org/apache/activemq/apollo/stomp/test/websocket-large.html Thu Jul 25 09:20:53 2013
@@ -0,0 +1,60 @@
+<!DOCTYPE html>
+<!--
+ 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.
+-->
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>Chat Example Using STOMP Over WebSockets</title>
+ <!--[if lt IE 9]>
+ <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
+ <![endif]-->
+ <script src='jquery.js'></script>
+ <script src='stomp.js'></script>
+ <script>//<![CDATA[
+ String.prototype.repeat = function( num ) {
+ return new Array( num + 1 ).join( this );
+ }
+
+ $(document).ready(function() {
+ if(window.WebSocket) {
+ var url = "ws://localhost:61623";
+ if(window.location.hash) {
+ url = window.location.hash.substring(1);
+ }
+ var login = "admin";
+ var passcode = "password";
+ destination = "/queue/websocket";
+
+ client = Stomp.client(url);
+
+ // the client is notified when it is connected to the server.
+ client.connect(login, passcode, function(frame) {
+ client.send(destination, null, "x".repeat(16385));
+ $("#status").html("Sent");
+
+ });
+ } else {
+ $("#status").html("No WebSockets");
+ }
+ });
+ //]]></script>
+</head>
+<body>
+<div id="status">Message not sent</div>
+<div id="received"></div>
+</body>
+</html>
Modified: activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompWebSocketTests.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompWebSocketTests.scala?rev=1506857&r1=1506856&r2=1506857&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompWebSocketTests.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompWebSocketTests.scala Thu Jul 25 09:20:53 2013
@@ -35,7 +35,9 @@ import java.io.File
object StompWebSocketTests {
class ChromeStompWebSocketTest extends StompWebSocketTestBase with ChromeWebDriverTrait
+
class FirefoxStompWebSocketTest extends StompWebSocketTestBase with FirefoxWebDriverTrait
+
class SafariStompWebSocketTest extends StompWebSocketTestBase with SafariWebDriverTrait
abstract class StompWebSocketTestBase extends StompTestSupport with WebDriverTrait {
@@ -44,7 +46,7 @@ object StompWebSocketTests {
override def broker_config_uri = "xml:classpath:apollo-stomp-websocket.xml"
- var jetty:Server = _
+ var jetty: Server = _
var jetty_port = 0
def start_jetty = {
@@ -55,9 +57,11 @@ object StompWebSocketTests {
test_data_dir.mkdirs()
var file = new File(getClass.getResource("websocket.html").getPath)
- file.copy_to(test_data_dir/"websocket.html")
- new File(file.getParentFile, "../../../../../../../../../apollo-website/src/scripts/jquery.js").getCanonicalFile.copy_to(test_data_dir/"jquery.js")
- new File(file.getParentFile, "../../../../../../../../../apollo-distro/src/main/release/examples/stomp/websocket/js/stomp.js").getCanonicalFile.copy_to(test_data_dir/"stomp.js")
+ file.copy_to(test_data_dir / "websocket.html")
+ file = new File(getClass.getResource("websocket-large.html").getPath)
+ file.copy_to(test_data_dir / "websocket-large.html")
+ new File(file.getParentFile, "../../../../../../../../../apollo-distro/src/main/release/examples/stomp/websocket/js/jquery-1.7.2.min.js").getCanonicalFile.copy_to(test_data_dir / "jquery.js")
+ new File(file.getParentFile, "../../../../../../../../../apollo-distro/src/main/release/examples/stomp/websocket/js/stomp.js").getCanonicalFile.copy_to(test_data_dir / "stomp.js")
var context = new WebAppContext
context.setContextPath("/")
@@ -73,7 +77,7 @@ object StompWebSocketTests {
}
def stop_jetty = {
- if( jetty!=null ) {
+ if (jetty != null) {
jetty.stop()
jetty = null
}
@@ -106,14 +110,14 @@ object StompWebSocketTests {
}
}
- for( protocol <- Array("ws", "wss") ) {
- test("websocket "+protocol) {
+ for (protocol <- Array("ws", "wss")) {
+ test("websocket " + protocol) {
- val url = "http://localhost:"+jetty_port+"/websocket.html"
+ val url = "http://localhost:" + jetty_port + "/websocket.html"
val ws_port: Int = connector_port(protocol).get
System.out.println("url: " + url)
- driver.get(url + "#"+protocol+"://127.0.0.1:" + ws_port);
+ driver.get(url + "#" + protocol + "://127.0.0.1:" + ws_port);
val web_status = driver.findElement(By.id("status"));
val web_received = driver.findElement(By.id("received"));
@@ -152,7 +156,68 @@ object StompWebSocketTests {
}
}
+
+ // broker sends client large message
+ for(protocol <- Array("ws", "wss")){
+ test("websockets large text messages to client: " +protocol){
+ val url = "http://localhost:" + jetty_port + "/websocket.html"
+ val ws_port: Int = connector_port(protocol).get
+
+ System.out.println("url: " + url)
+ driver.get(url + "#" + protocol + "://127.0.0.1:" + ws_port);
+ val web_status = driver.findElement(By.id("status"));
+ val web_received = driver.findElement(By.id("received"));
+
+ while ("Loading" == web_status.getText) {
+ Thread.sleep(100)
+ }
+
+ if (web_status.getText != "No WebSockets") {
+ within(2, SECONDS) {
+ web_status.getText should be("Connected")
+ }
+
+ connect("1.1")
+ async_send("/queue/websocket", "x"*16385)
+ within(2, SECONDS){
+ web_received.getText should startWith("xxxxx")
+ }
+
+ }
+ }
+ }
+
+ // client sends broker large message..
+ for(protocol <- Array( "ws")){
+ test("websockets large text messages from client: " +protocol){
+ def generateLargeText(x:String, i:Int) = {
+ x * i
+ }
+ val url = "http://localhost:" + jetty_port + "/websocket-large.html"
+ val ws_port: Int = connector_port(protocol).get
+
+ System.out.println("url: " + url)
+
+ driver.get(url + "#" + protocol + "://127.0.0.1:" + ws_port);
+
+ val web_status = driver.findElement(By.id("status"));
+
+ while ("Message not sent" == web_status.getText) {
+ Thread.sleep(100)
+ }
+
+ if(web_status != "No WebSockets"){
+ connect("1.1")
+ subscribe("0", "/queue/websocket")
+
+ within(2000000, SECONDS){
+ assert_received("""x.*""".r, "0")
+ }
+ }
+
+ }
}
+ }
}