Skip to content

Commit 0193a8e

Browse files
committed
Merged branch '2.7.x' into 'master'.
2 parents 12318b6 + f4755ff commit 0193a8e

17 files changed

Lines changed: 4637 additions & 4244 deletions

File tree

cometd-archetypes/jquery-jetty9/src/main/resources/archetype-resources/src/main/webapp/index.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<html>
66
<head>
77
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
8-
<script type="text/javascript" src="${symbol_dollar}{pageContext.request.contextPath}/jquery/jquery-1.9.1.js"></script>
8+
<script type="text/javascript" src="${symbol_dollar}{pageContext.request.contextPath}/jquery/jquery-1.10.2.js"></script>
99
<script type="text/javascript" src="${symbol_dollar}{pageContext.request.contextPath}/org/cometd.js"></script>
1010
<script type="text/javascript" src="${symbol_dollar}{pageContext.request.contextPath}/jquery/jquery.cometd.js"></script>
1111
<script type="text/javascript" src="application.js"></script>

cometd-archetypes/spring-jquery-jetty9/src/main/resources/archetype-resources/src/main/webapp/index.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<html>
66
<head>
77
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
8-
<script type="text/javascript" src="${symbol_dollar}{pageContext.request.contextPath}/jquery/jquery-1.9.1.js"></script>
8+
<script type="text/javascript" src="${symbol_dollar}{pageContext.request.contextPath}/jquery/jquery-1.10.2.js"></script>
99
<script type="text/javascript" src="${symbol_dollar}{pageContext.request.contextPath}/org/cometd.js"></script>
1010
<script type="text/javascript" src="${symbol_dollar}{pageContext.request.contextPath}/jquery/jquery.cometd.js"></script>
1111
<script type="text/javascript" src="application.js"></script>

cometd-java/cometd-java-common/pom.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
<artifactId>cometd-java-common</artifactId>
1111
<name>CometD :: Java :: Bayeux Common</name>
1212

13-
<properties>
14-
</properties>
15-
1613
<dependencies>
1714
<dependency>
1815
<groupId>org.cometd.java</groupId>

cometd-java/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
<packaging>pom</packaging>
1414
<name>CometD :: Java</name>
1515

16-
<properties>
17-
<jackson1-version>1.9.12</jackson1-version>
18-
<jackson2-version>2.1.4</jackson2-version>
19-
</properties>
20-
2116
<modules>
2217
<module>bayeux-api</module>
2318
<module>cometd-java-annotations</module>

cometd-javascript/common-test/src/main/java/org/cometd/javascript/WebSocketConnection.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.eclipse.jetty.websocket.client.WebSocketClient;
2525
import org.mozilla.javascript.Scriptable;
2626
import org.mozilla.javascript.ScriptableObject;
27+
import org.mozilla.javascript.Undefined;
2728
import org.slf4j.Logger;
2829
import org.slf4j.LoggerFactory;
2930

@@ -38,11 +39,13 @@ public WebSocketConnection()
3839
{
3940
}
4041

41-
public void jsConstructor(Object cookieStore, Object threadModel, Scriptable thiz, Object connector, String url)
42+
public void jsConstructor(Object cookieStore, Object threadModel, Scriptable thiz, Object connector, String url, Object protocol)
4243
{
4344
this.threads = (ThreadModel)threadModel;
4445
this.thiz = thiz;
4546
WebSocketClient wsClient = ((WebSocketConnector)connector).getWebSocketClient();
47+
if (protocol != null && protocol != Undefined.instance)
48+
wsClient.setProtocol(protocol.toString());
4649
try
4750
{
4851
URI uri = new URI(url);

cometd-javascript/common-test/src/main/java/org/cometd/javascript/jquery/JQueryTestProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void provideCometD(ThreadModel threadModel, String contextURL) throws Exc
3333
// so we need to remove the Java package to avoid clashes.
3434
threadModel.remove("org");
3535
threadModel.evaluate("window_location", "window.location = '" + contextURL + "'");
36-
threadModel.evaluate(new URL(contextURL + "/jquery/jquery-1.9.1.js"));
36+
threadModel.evaluate(new URL(contextURL + "/jquery/jquery-1.10.2.js"));
3737
threadModel.evaluate(new URL(contextURL + "/org/cometd.js"));
3838
threadModel.evaluate(new URL(contextURL + "/jquery/jquery.cometd.js"));
3939
threadModel.evaluate("cometd", "var cometd = $.cometd;");

cometd-javascript/common-test/src/main/resources/env.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -978,11 +978,11 @@ var window = this;
978978
}();
979979

980980
var wsIds = 0;
981-
window.WebSocket = function(url)
981+
window.WebSocket = function(url, protocol)
982982
{
983983
this._id = ++wsIds;
984984
this._url = url;
985-
this._ws = new WebSocketConnection(cookies, threadModel, this, wsConnector, url);
985+
this._ws = new WebSocketConnection(cookies, threadModel, this, wsConnector, url, protocol);
986986
};
987987
window.WebSocket.CONNECTING = 0;
988988
window.WebSocket.OPEN = 1;

cometd-javascript/common-test/src/test/java/org/cometd/javascript/AbstractCometDTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.io.File;
2020
import java.lang.reflect.InvocationTargetException;
21+
import java.util.HashMap;
22+
import java.util.Map;
2123

2224
import org.cometd.javascript.jquery.JQueryTestProvider;
2325
import org.cometd.server.BayeuxServerImpl;
@@ -74,6 +76,12 @@ public void starting(Description description)
7476

7577
@Before
7678
public void initCometDServer() throws Exception
79+
{
80+
Map<String, String> options = new HashMap<>();
81+
initCometDServer(options);
82+
}
83+
84+
protected void initCometDServer(Map<String, String> options) throws Exception
7785
{
7886
String providerClass = getProviderClassName();
7987
provider = (TestProvider)Thread.currentThread().getContextClassLoader().loadClass(providerClass).newInstance();
@@ -96,6 +104,8 @@ public void initCometDServer() throws Exception
96104
// Setup CometD servlet
97105
cometdServlet = new CometDServlet();
98106
ServletHolder cometServletHolder = new ServletHolder(cometdServlet);
107+
for (Map.Entry<String, String> entry : options.entrySet())
108+
cometServletHolder.setInitParameter(entry.getKey(), entry.getValue());
99109
cometServletHolder.setInitParameter("timeout", String.valueOf(longPollingPeriod));
100110
cometServletHolder.setInitParameter("transports", WebSocketTransport.class.getName());
101111
if (Boolean.getBoolean("debugTests"))
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright (c) 2010 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.cometd.javascript;
18+
19+
import org.junit.Assert;
20+
import org.junit.Test;
21+
22+
public class CometDWebSocketClientProtocolTest extends AbstractCometDWebSocketTest
23+
{
24+
private static final String PROTOCOL = "bayeux/1.0";
25+
26+
@Test
27+
public void testClientWithoutWebSocketProtocolServerWithoutWebSocketProtocol() throws Exception
28+
{
29+
evaluateScript("cometd.configure({" +
30+
"url: '" + cometdURL + "', " +
31+
"logLevel: '" + getLogLevel() + "'" +
32+
"});");
33+
34+
defineClass(Latch.class);
35+
36+
evaluateScript("var latch = new Latch(1);");
37+
Latch latch = get("latch");
38+
String channelName = "/bar";
39+
evaluateScript("cometd.addListener('/meta/handshake', function(message)" +
40+
"{" +
41+
" if (message.successful)" +
42+
" {" +
43+
" cometd.batch(function()" +
44+
" {" +
45+
" cometd.subscribe('" + channelName + "', latch, 'countDown');" +
46+
" cometd.publish('" + channelName + "', {});" +
47+
" });" +
48+
" }" +
49+
"});");
50+
51+
evaluateScript("cometd.handshake();");
52+
Assert.assertTrue(latch.await(5000));
53+
54+
evaluateScript("var disconnectLatch = new Latch(1);");
55+
Latch disconnectLatch = get("disconnectLatch");
56+
evaluateScript("cometd.addListener('/meta/disconnect', disconnectLatch, disconnectLatch.countDown);");
57+
evaluateScript("cometd.disconnect();");
58+
Assert.assertTrue(disconnectLatch.await(5000));
59+
}
60+
61+
@Test
62+
public void testClientWithWebSocketProtocolServerWithoutWebSocketProtocol() throws Exception
63+
{
64+
evaluateScript("cometd.configure({" +
65+
"url: '" + cometdURL + "', " +
66+
"protocol: '" + PROTOCOL + "', " +
67+
"logLevel: '" + getLogLevel() + "'" +
68+
"});");
69+
70+
defineClass(Latch.class);
71+
72+
evaluateScript("var latch = new Latch(1);");
73+
Latch latch = get("latch");
74+
String channelName = "/bar";
75+
evaluateScript("cometd.addListener('/meta/handshake', function(message)" +
76+
"{" +
77+
" if (message.successful)" +
78+
" {" +
79+
" cometd.batch(function()" +
80+
" {" +
81+
" cometd.subscribe('" + channelName + "', latch, 'countDown');" +
82+
" cometd.publish('" + channelName + "', {});" +
83+
" });" +
84+
" }" +
85+
"});");
86+
87+
evaluateScript("cometd.handshake();");
88+
// The server tries to match the client protocol but if it can't tries
89+
// as if the client sent no protocol, which in this case will match
90+
Assert.assertTrue(latch.await(5000));
91+
92+
evaluateScript("var disconnectLatch = new Latch(1);");
93+
Latch disconnectLatch = get("disconnectLatch");
94+
evaluateScript("cometd.addListener('/meta/disconnect', disconnectLatch, disconnectLatch.countDown);");
95+
evaluateScript("cometd.disconnect();");
96+
Assert.assertTrue(disconnectLatch.await(5000));
97+
}
98+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright (c) 2010 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.cometd.javascript;
18+
19+
import java.util.HashMap;
20+
import java.util.Map;
21+
22+
import org.junit.Assert;
23+
import org.junit.Test;
24+
25+
public class CometDWebSocketServerProtocolTest extends AbstractCometDWebSocketTest
26+
{
27+
private static final String PROTOCOL = "bayeux/1.0";
28+
29+
@Override
30+
public void initCometDServer() throws Exception
31+
{
32+
Map<String, String> options = new HashMap<String, String>();
33+
options.put("ws.protocol", PROTOCOL);
34+
initCometDServer(options);
35+
}
36+
37+
@Test
38+
public void testClientWithoutWebSocketProtocolServerWithWebSocketProtocol() throws Exception
39+
{
40+
evaluateScript("cometd.configure({" +
41+
"url: '" + cometdURL + "', " +
42+
"logLevel: '" + getLogLevel() + "'" +
43+
"});");
44+
45+
defineClass(Latch.class);
46+
47+
evaluateScript("var latch = new Latch(1);");
48+
Latch latch = get("latch");
49+
String channelName = "/bar";
50+
evaluateScript("cometd.addListener('/meta/handshake', function(message)" +
51+
"{" +
52+
" if (message.successful)" +
53+
" {" +
54+
" cometd.batch(function()" +
55+
" {" +
56+
" cometd.subscribe('" + channelName + "', latch, 'countDown');" +
57+
" cometd.publish('" + channelName + "', {});" +
58+
" });" +
59+
" }" +
60+
"});");
61+
62+
evaluateScript("cometd.handshake();");
63+
Assert.assertFalse(latch.await(1000));
64+
}
65+
66+
@Test
67+
public void testClientWithWebSocketProtocolServerWithWebSocketProtocol() throws Exception
68+
{
69+
evaluateScript("cometd.configure({" +
70+
"url: '" + cometdURL + "', " +
71+
"protocol: '" + PROTOCOL + "', " +
72+
"logLevel: '" + getLogLevel() + "'" +
73+
"});");
74+
75+
defineClass(Latch.class);
76+
77+
evaluateScript("var latch = new Latch(1);");
78+
Latch latch = get("latch");
79+
String channelName = "/bar";
80+
evaluateScript("cometd.addListener('/meta/handshake', function(message)" +
81+
"{" +
82+
" if (message.successful)" +
83+
" {" +
84+
" cometd.batch(function()" +
85+
" {" +
86+
" cometd.subscribe('" + channelName + "', latch, 'countDown');" +
87+
" cometd.publish('" + channelName + "', {});" +
88+
" });" +
89+
" }" +
90+
"});");
91+
92+
evaluateScript("cometd.handshake();");
93+
Assert.assertTrue(latch.await(5000));
94+
95+
evaluateScript("var disconnectLatch = new Latch(1);");
96+
Latch disconnectLatch = get("disconnectLatch");
97+
evaluateScript("cometd.addListener('/meta/disconnect', disconnectLatch, disconnectLatch.countDown);");
98+
evaluateScript("cometd.disconnect();");
99+
Assert.assertTrue(disconnectLatch.await(5000));
100+
}
101+
}

0 commit comments

Comments
 (0)