Note that there are some explanatory texts on larger screens.

plurals
  1. POCometD / jQuery Client Error 402::Unknown Client
    text
    copied!<p>I'm trying to get started with CometD as I need some empirical background for a technical comparision between various push technologies.</p> <p>I finally managed to get an example code running in my Tomcat (v7.0). </p> <p>Now I'm having strange behavior and I'm desperately trying to find out what I did wrong. </p> <p><strong>Here are my observations:</strong></p> <ul> <li><p>Connection Loops:</p> <p>I'm running in an endless connection loop with the client.</p> <p>Request:</p> <pre><code>[{"channel":"/meta/connect","connectionType":"long-polling","id":"19","clientId":"f1le33y91f6pa71f39z52km87yp"}] </code></pre> <p>Response:</p> <pre><code>[{"id":"19","successful":true,"advice":{"interval":2000,"reconnect":"retry","multiple-clients":true,"timeout":60000},"channel":"/meta/connect"}] </code></pre> <p>The interesting thing about this is, that the Listener-callback event actually occures</p> <pre><code> cometd.addListener('/meta/handshake', _metaHandshake); </code></pre></li> <li><p>Client connection request stucks</p> <p>This mostly occurs after a fresh restart of my Tomcat server. I can see a successful subscription to 2 channels:</p> <p>Request</p> <pre><code>[{"version":"1.0","minimumVersion":"0.9","channel":"/meta/handshake","supportedConnectionTypes":["long-polling","callback-polling"],"advice":{"timeout":60000,"interval":0},"id":"1"}] </code></pre> <p>Response</p> <pre><code>[{"id":"1","minimumVersion":"1.0","supportedConnectionTypes":["callback-polling","long-polling"],"successful":true,"channel":"/meta/handshake","clientId":"11tnpjnmkqo3tf64zcvufuqbtv","version":"1.0"}] </code></pre> <p>Request</p> <pre><code>[{"channel":"/meta/subscribe","subscription":"/hello","id":"2","clientId":"11tnpjnmkqo3tf64zcvufuqbtv"},{"channel":"/service/hello","data":{"name":"World"},"id":"3","clientId":"11tnpjnmkqo3tf64zcvufuqbtv"}] </code></pre> <p>Response</p> <pre><code>[{"id":"2","subscription":"/hello","successful":true,"channel":"/meta/subscribe"},{"id":"3","successful":true,"channel":"/service/hello"}] </code></pre> <p>The call after this one stucks and takes forever.</p></li> </ul> <p><strong>... abd here is my Code</strong></p> <ul> <li><p>Client</p> <pre><code>(function($) { var cometd = $.cometd; $(document).ready(function() { function _connectionEstablished() { $('#body').append('&lt;div&gt;CometD Connection Established&lt;/div&gt;'); } function _connectionBroken() { $('#body').append('&lt;div&gt;CometD Connection Broken&lt;/div&gt;'); } function _connectionClosed() { $('#body').append('&lt;div&gt;CometD Connection Closed&lt;/div&gt;'); } // Function that manages the connection status with the Bayeux server var _connected = false; function _metaConnect(message) { if (cometd.isDisconnected()) { _connected = false; _connectionClosed(); return; } var wasConnected = _connected; _connected = message.successful === true; if (!wasConnected &amp;&amp; _connected) { _connectionEstablished(); } else if (wasConnected &amp;&amp; !_connected) { _connectionBroken(); } } // Function invoked when first contacting the server and // when the server has lost the state of this client function _metaHandshake(handshake) { if (handshake.successful === true) { // interesting enough: that event is triggered alert('event occured'); cometd.batch(function() { // that function is called and produces a corresponding request to the server cometd.subscribe('/hello', function(message) { // that one never happens... $('#body').append('&lt;div&gt;Server Says: ' + message.data.greeting + '&lt;/div&gt;'); }); // Publish on a service channel since the message is for the server only cometd.publish('/service/hello', { name: 'World' }); }); } } // Disconnect when the page unloads $(window).unload(function() { cometd.disconnect(true); }); var cometURL = location.protocol + "//" + location.host + config.contextPath + "/cometd"; cometd.configure({ url: cometURL, logLevel: 'debug' }); cometd.addListener('/meta/handshake', _metaHandshake); cometd.addListener('/meta/connect', _metaConnect); cometd.handshake(); }); })(jQuery); </code></pre></li> <li><p>Server</p> <p>Notice that this is almost 1:1 from the example from the distribution package!</p> <pre><code>public class HelloService extends AbstractService { public HelloService(BayeuxServer bayeux) { super(bayeux, "hello"); addService("/service/hello", "processHello"); } public void processHello(ServerSession remote, Message message) { Map&lt;String, Object&gt; input = message.getDataAsMap(); String name = (String)input.get("name"); Map&lt;String, Object&gt; output = new HashMap&lt;String, Object&gt;(); output.put("greeting", "Hello, " + name); remote.deliver(getServerSession(), "/hello", output, null); } </code></pre> <p>}</p></li> <li><p>Web.xml File</p> <p> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"></p> <pre><code>&lt;servlet&gt; &lt;servlet-name&gt;cometd&lt;/servlet-name&gt; &lt;servlet-class&gt;org.cometd.server.CometdServlet&lt;/servlet-class&gt; &lt;async-supported&gt;true&lt;/async-supported&gt; &lt;init-param&gt; &lt;param-name&gt;timeout&lt;/param-name&gt; &lt;param-value&gt;60000&lt;/param-value&gt; &lt;/init-param&gt; &lt;init-param&gt; &lt;param-name&gt;logLevel&lt;/param-name&gt; &lt;param-value&gt;3&lt;/param-value&gt; &lt;/init-param&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;cometd&lt;/servlet-name&gt; &lt;url-pattern&gt;/cometd/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre> <p></p></li> </ul> <p>Maybe I'm just doing something completely wrong, but I'm starting to get a bit desperate on this. Help would be highly appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload