Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-663

Comet server push not working with Servlet 3 server if web.xml's schema is Servlet 2.4

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Normal Normal
    • 6.0.0
    • Freshly
    • General
    • 6.0.0.FL.20111207

      The following two files demonstrate the problem:

      index.zul

      <?page title="test" contentType="text/html;charset=UTF-8"?>
      <zk>
         <window title="test" border="normal" apply="org.zkoss.bind.BindComposer" viewModel="@bind('TestVM')" onCreate="@bind('doServerPush')" />
      </zk>
      

      TestVM.java

      import org.zkoss.lang.Threads;
      import org.zkoss.zk.ui.Desktop;
      import org.zkoss.zk.ui.DesktopUnavailableException;
      import org.zkoss.zk.ui.Executions;
      
      public class TestVM {
      
      	public void doServerPush() {
      		Desktop desktop = Executions.getCurrent().getDesktop();
      		desktop.enableServerPush(true);
      
      		new WorkingThread(desktop).start();
      	}
      
      	private class WorkingThread extends Thread {
      
      		private Desktop desktop;
      
      		public WorkingThread(Desktop desktop) {
      			this.desktop = desktop;
      		}
      
      		public void run() {
      			while (true) {				
      				try {
      					Executions.activate(desktop);
      					System.out.println("Hello There");
      					Executions.deactivate(desktop);
      				} catch (DesktopUnavailableException e) {
      					System.out.println("The server push thread could not locate the desktop");
      					return;
      				} catch (InterruptedException e) {
      					System.out.println("The server push thread interrupted");
      					return;
      				}
      
      				Threads.sleep(1000);
      			}
      		}
      	}
      
      }
      

      In ZK6 RC1, the code above correctly starts printing out "Hello There" every second.

      After upgrading to the latest freshly build, the example above no longer works. Below are the changes needed to accommodate the new RC2 features:

      index.zul (changed to use new syntax)

      <?page title="test" contentType="text/html;charset=UTF-8"?>
      <zk>
         <window title="test" border="normal" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('TestVM')" onCreate="@command('doServerPush')" />
      </zk>
      

      TestVM.java (changed to use new @Command annotation)

      [snip]
      
      public class TestVM {
      
      	@Command
      	public void doServerPush() {
      		Desktop desktop = Executions.getCurrent().getDesktop();
      		desktop.enableServerPush(true);
      
      		new WorkingThread(desktop).start();
      	}
      [snip]
      

      Now "Hello World" is never printed out. Stepping through the code in a debugger shows that it gets up to "Executions.activate(desktop);", but it never goes past that line as if it cannot ever get exclusive access to the desktop.

            Unassigned Unassigned
            derepentigny derepentigny
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 3 hours
                3h