Updated Branches:
  refs/heads/master aa486e45c -> f54a2046b

WICKET-4611 Extend the client side API by providing a default WebSocket 
connection.

This way the API look more like Wicket.Ajax API - 
Wicket.WebSocket.send('something');
Add more logging.


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/f54a2046
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/f54a2046
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/f54a2046

Branch: refs/heads/master
Commit: f54a2046b05cad501eab478572361efee745c477
Parents: 1fb1322
Author: Martin Tzvetanov Grigorov <[email protected]>
Authored: Wed Jun 20 16:36:27 2012 +0300
Committer: Martin Tzvetanov Grigorov <[email protected]>
Committed: Wed Jun 20 16:36:27 2012 +0300

----------------------------------------------------------------------
 .../wicket/protocol/ws/api/WebSocketBehavior.java  |   15 ++++-
 .../ws/api/res/js/wicket-websocket-jquery.js       |   40 +++++++++++++--
 .../ws/api/res/js/wicket-websocket-setup.js.tmpl   |    8 +++
 .../ws/util/licence/ApacheLicenceHeaderTest.java   |   34 ++++++++++++
 .../util/license/ApacheLicenceHeaderTest.java      |   32 ------------
 .../ws/util/license/ApacheLicenceHeaderTest.java   |   34 ++++++++++++
 .../util/license/ApacheLicenceHeaderTest.java      |   32 ------------
 .../ws/util/license/ApacheLicenceHeaderTest.java   |   34 ++++++++++++
 .../util/license/ApacheLicenceHeaderTest.java      |   32 ------------
 9 files changed, 157 insertions(+), 104 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/f54a2046/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketBehavior.java
----------------------------------------------------------------------
diff --git 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketBehavior.java
 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketBehavior.java
index 62dead7..a3df2b8 100644
--- 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketBehavior.java
+++ 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketBehavior.java
@@ -16,12 +16,15 @@
  */
 package org.apache.wicket.protocol.ws.api;
 
+import java.util.Map;
+
 import org.apache.wicket.Component;
 import org.apache.wicket.ajax.WebSocketRequestHandler;
 import org.apache.wicket.behavior.Behavior;
 import org.apache.wicket.event.IEvent;
 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.protocol.ws.api.event.WebSocketBinaryPayload;
 import org.apache.wicket.protocol.ws.api.event.WebSocketClosedPayload;
 import org.apache.wicket.protocol.ws.api.event.WebSocketConnectedPayload;
@@ -31,6 +34,8 @@ import 
org.apache.wicket.protocol.ws.api.message.BinaryMessage;
 import org.apache.wicket.protocol.ws.api.message.ClosedMessage;
 import org.apache.wicket.protocol.ws.api.message.ConnectedMessage;
 import org.apache.wicket.protocol.ws.api.message.TextMessage;
+import org.apache.wicket.util.lang.Generics;
+import org.apache.wicket.util.template.PackageTextTemplate;
 
 /**
  * A behavior that contributes {@link WicketWebSocketJQueryResourceReference} 
and
@@ -99,10 +104,14 @@ public abstract class WebSocketBehavior extends Behavior
 
                
response.render(JavaScriptHeaderItem.forReference(WicketWebSocketJQueryResourceReference.get()));
 
+               PackageTextTemplate webSocketSetupTemplate =
+                               new 
PackageTextTemplate(WicketWebSocketJQueryResourceReference.class, 
"res/js/wicket-websocket-setup.js.tmpl");
+               Map<String, Object> variables = Generics.newHashMap();
                int pageId = component.getPage().getPageId();
-               response.render(JavaScriptHeaderItem.forScript(
-                               "jQuery.extend(Wicket.WebSocket, { pageId: " + 
pageId + "});",
-                               "wicket-web-socket"));
+               variables.put("pageId", Integer.valueOf(pageId));
+               String webSocketSetupScript = 
webSocketSetupTemplate.asString(variables);
+
+               
response.render(OnDomReadyHeaderItem.forScript(webSocketSetupScript));
        }
 
        @Override

http://git-wip-us.apache.org/repos/asf/wicket/blob/f54a2046/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/res/js/wicket-websocket-jquery.js
----------------------------------------------------------------------
diff --git 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/res/js/wicket-websocket-jquery.js
 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/res/js/wicket-websocket-jquery.js
index a5c8fd6..17e8775 100644
--- 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/res/js/wicket-websocket-jquery.js
+++ 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/res/js/wicket-websocket-jquery.js
@@ -82,24 +82,54 @@
                                        }
                                };
                        } else {
-                               Wicket.Log.error('WebSocket not supported in 
your browser!');
-
+                               var errMessage = '[WebSocket.initialize] 
WebSocket is not supported in your browser!';
+                               Wicket.Log.error(errMessage);
+                               throw errMessage;
                        }
                },
 
                send: function (text) {
-                       if (this.ws) {
-                               Wicket.Log.info("WebSocket.send: " + text);
+                       if (this.ws && text) {
+                               Wicket.Log.info("[WebSocket.send] Sending: " + 
text);
                                this.ws.send(text);
+                       } else if (!text) {
+                               Wicket.Log.error("[WebSocket.send] Cannot send 
an empty text message!");
+                       } else {
+                               Wicket.Log.error("[WebSocket.send] No open 
WebSocket connection! Cannot send text message: " + text);
                        }
                },
 
                close: function () {
                        if (this.ws) {
                                this.ws.close();
-                               Wicket.Log.info("WebSocket closed");
+                               Wicket.Log.info("[WebSocket.close] Connection 
closed.");
+                       } else {
+                               Wicket.Log.info("[WebSocket.close] Connection 
already closed.");
                        }
                }
        };
 
+       Wicket.WebSocket.createDefaultConnection = function () {
+               if (!Wicket.WebSocket.INSTANCE) {
+                       Wicket.WebSocket.INSTANCE = new Wicket.WebSocket();
+               }
+       };
+
+       Wicket.WebSocket.send = function (text) {
+               if (Wicket.WebSocket.INSTANCE) {
+                       Wicket.WebSocket.INSTANCE.send(text);
+               } else {
+                       Wicket.Log.error("[WebSocket.send] No default 
connection available!");
+               }
+       };
+
+       Wicket.WebSocket.close = function () {
+               if (Wicket.WebSocket.INSTANCE) {
+                       Wicket.WebSocket.INSTANCE.close();
+                       delete Wicket.WebSocket.INSTANCE;
+               } else {
+                       Wicket.Log.info("[WebSocket.close] No default 
connection to close.");
+               }
+       };
+
 })();
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/wicket/blob/f54a2046/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/res/js/wicket-websocket-setup.js.tmpl
----------------------------------------------------------------------
diff --git 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/res/js/wicket-websocket-setup.js.tmpl
 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/res/js/wicket-websocket-setup.js.tmpl
new file mode 100644
index 0000000..fbfe93b
--- /dev/null
+++ 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/res/js/wicket-websocket-setup.js.tmpl
@@ -0,0 +1,8 @@
+;(function(undefined) {
+       'use strict';
+
+       if (!Wicket.WebSocket.pageId) {
+               jQuery.extend(Wicket.WebSocket, { pageId: ${pageId} });
+               Wicket.WebSocket.createDefaultConnection();
+       }
+})();

http://git-wip-us.apache.org/repos/asf/wicket/blob/f54a2046/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/test/java/org/apache/wicket/protocol/ws/util/licence/ApacheLicenceHeaderTest.java
----------------------------------------------------------------------
diff --git 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/test/java/org/apache/wicket/protocol/ws/util/licence/ApacheLicenceHeaderTest.java
 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/test/java/org/apache/wicket/protocol/ws/util/licence/ApacheLicenceHeaderTest.java
new file mode 100644
index 0000000..cd3cbf1
--- /dev/null
+++ 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/test/java/org/apache/wicket/protocol/ws/util/licence/ApacheLicenceHeaderTest.java
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+package org.apache.wicket.protocol.ws.util.licence;
+
+import org.apache.wicket.util.license.ApacheLicenseHeaderTestCase;
+
+/**
+ * Test that the license headers are in place in this project. The tests are 
run from
+ * {@link org.apache.wicket.util.license.ApacheLicenseHeaderTestCase}, but you 
can add project specific tests here if needed.
+ */
+public class ApacheLicenceHeaderTest extends ApacheLicenseHeaderTestCase
+{
+       /**
+        * Construct.
+        */
+       public ApacheLicenceHeaderTest()
+       {
+               // addHeaders = true;
+       }
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/f54a2046/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/test/java/org/apache/wicket/util/license/ApacheLicenceHeaderTest.java
----------------------------------------------------------------------
diff --git 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/test/java/org/apache/wicket/util/license/ApacheLicenceHeaderTest.java
 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/test/java/org/apache/wicket/util/license/ApacheLicenceHeaderTest.java
deleted file mode 100644
index 3c9df65..0000000
--- 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/test/java/org/apache/wicket/util/license/ApacheLicenceHeaderTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.
- */
-package org.apache.wicket.util.license;
-
-/**
- * Test that the license headers are in place in this project. The tests are 
run from
- * {@link ApacheLicenseHeaderTestCase}, but you can add project specific tests 
here if needed.
- */
-public class ApacheLicenceHeaderTest extends ApacheLicenseHeaderTestCase
-{
-       /**
-        * Construct.
-        */
-       public ApacheLicenceHeaderTest()
-       {
-               // addHeaders = true;
-       }
-}

http://git-wip-us.apache.org/repos/asf/wicket/blob/f54a2046/wicket-experimental/wicket-native-websocket/wicket-native-websocket-jetty/src/test/java/org/apache/wicket/protocol/ws/util/license/ApacheLicenceHeaderTest.java
----------------------------------------------------------------------
diff --git 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-jetty/src/test/java/org/apache/wicket/protocol/ws/util/license/ApacheLicenceHeaderTest.java
 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-jetty/src/test/java/org/apache/wicket/protocol/ws/util/license/ApacheLicenceHeaderTest.java
new file mode 100644
index 0000000..9e3759d
--- /dev/null
+++ 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-jetty/src/test/java/org/apache/wicket/protocol/ws/util/license/ApacheLicenceHeaderTest.java
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+package org.apache.wicket.protocol.ws.util.license;
+
+import org.apache.wicket.util.license.ApacheLicenseHeaderTestCase;
+
+/**
+ * Test that the license headers are in place in this project. The tests are 
run from
+ * {@link org.apache.wicket.util.license.ApacheLicenseHeaderTestCase}, but you 
can add project specific tests here if needed.
+ */
+public class ApacheLicenceHeaderTest extends ApacheLicenseHeaderTestCase
+{
+       /**
+        * Construct.
+        */
+       public ApacheLicenceHeaderTest()
+       {
+               // addHeaders = true;
+       }
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/f54a2046/wicket-experimental/wicket-native-websocket/wicket-native-websocket-jetty/src/test/java/org/apache/wicket/util/license/ApacheLicenceHeaderTest.java
----------------------------------------------------------------------
diff --git 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-jetty/src/test/java/org/apache/wicket/util/license/ApacheLicenceHeaderTest.java
 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-jetty/src/test/java/org/apache/wicket/util/license/ApacheLicenceHeaderTest.java
deleted file mode 100644
index 3c9df65..0000000
--- 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-jetty/src/test/java/org/apache/wicket/util/license/ApacheLicenceHeaderTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.
- */
-package org.apache.wicket.util.license;
-
-/**
- * Test that the license headers are in place in this project. The tests are 
run from
- * {@link ApacheLicenseHeaderTestCase}, but you can add project specific tests 
here if needed.
- */
-public class ApacheLicenceHeaderTest extends ApacheLicenseHeaderTestCase
-{
-       /**
-        * Construct.
-        */
-       public ApacheLicenceHeaderTest()
-       {
-               // addHeaders = true;
-       }
-}

http://git-wip-us.apache.org/repos/asf/wicket/blob/f54a2046/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/test/java/org/apache/wicket/protocol/ws/util/license/ApacheLicenceHeaderTest.java
----------------------------------------------------------------------
diff --git 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/test/java/org/apache/wicket/protocol/ws/util/license/ApacheLicenceHeaderTest.java
 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/test/java/org/apache/wicket/protocol/ws/util/license/ApacheLicenceHeaderTest.java
new file mode 100644
index 0000000..9e3759d
--- /dev/null
+++ 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/test/java/org/apache/wicket/protocol/ws/util/license/ApacheLicenceHeaderTest.java
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+package org.apache.wicket.protocol.ws.util.license;
+
+import org.apache.wicket.util.license.ApacheLicenseHeaderTestCase;
+
+/**
+ * Test that the license headers are in place in this project. The tests are 
run from
+ * {@link org.apache.wicket.util.license.ApacheLicenseHeaderTestCase}, but you 
can add project specific tests here if needed.
+ */
+public class ApacheLicenceHeaderTest extends ApacheLicenseHeaderTestCase
+{
+       /**
+        * Construct.
+        */
+       public ApacheLicenceHeaderTest()
+       {
+               // addHeaders = true;
+       }
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/f54a2046/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/test/java/org/apache/wicket/util/license/ApacheLicenceHeaderTest.java
----------------------------------------------------------------------
diff --git 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/test/java/org/apache/wicket/util/license/ApacheLicenceHeaderTest.java
 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/test/java/org/apache/wicket/util/license/ApacheLicenceHeaderTest.java
deleted file mode 100644
index 3c9df65..0000000
--- 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/test/java/org/apache/wicket/util/license/ApacheLicenceHeaderTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.
- */
-package org.apache.wicket.util.license;
-
-/**
- * Test that the license headers are in place in this project. The tests are 
run from
- * {@link ApacheLicenseHeaderTestCase}, but you can add project specific tests 
here if needed.
- */
-public class ApacheLicenceHeaderTest extends ApacheLicenseHeaderTestCase
-{
-       /**
-        * Construct.
-        */
-       public ApacheLicenceHeaderTest()
-       {
-               // addHeaders = true;
-       }
-}

Reply via email to