title: Server-sent event does not work with jersey SSE
body: <p>I am trying to use JavaScript SSE from Jersey. I have Following code in my resource. I am hosting on Java7 and Tomcat 7. I dont get any error. But I don't see data either on page.</p>
  
  <p>I call <code>/broadcast</code> to post data. It does show message. But nothing comes on client. In Firefox, I do see <code>/broadcast</code> event fired multiple times.</p>
  
  <p>This is reference I used.
  <a href="https://jersey.java.net/documentation/latest/sse.html" rel="nofollow">https://jersey.java.net/documentation/latest/sse.html</a></p>
  
  <pre><code>    package net.jigarshah.dse.tracker;
  
      import javax.inject.Singleton;
      import javax.ws.rs.Consumes;
      import javax.ws.rs.GET;
      import javax.ws.rs.POST;
      import javax.ws.rs.Path;
      import javax.ws.rs.Produces;
      import javax.ws.rs.core.MediaType;
  
      import org.glassfish.jersey.media.sse.EventOutput;
      import org.glassfish.jersey.media.sse.OutboundEvent;
      import org.glassfish.jersey.media.sse.SseBroadcaster;
      import org.glassfish.jersey.media.sse.SseFeature;
  
  
  @Singleton
  @Path("broadcast")
  public class SSEResource {
      private SseBroadcaster broadcaster = new SseBroadcaster();
  
      @POST
      @Produces(MediaType.TEXT_PLAIN)
      @Consumes(MediaType.TEXT_PLAIN)    
      public String broadcastMessage(String message) {
          OutboundEvent.Builder eventBuilder = new OutboundEvent.Builder();
          message = message + "\n\n";
          OutboundEvent event = eventBuilder.name("message")
              .mediaType(MediaType.TEXT_PLAIN_TYPE)
              .data(String.class, message)
              .build();
  
          broadcaster.broadcast(event);
          System.out.println("broadcasting listen [" +message+ "]");
  
          return "Message was '" + message + "' broadcast.";
      }
  
      @GET
      @Produces(SseFeature.SERVER_SENT_EVENTS)
      public EventOutput listenToBroadcast() {
          System.out.println("will listen");
          final EventOutput eventOutput = new EventOutput();
          this.broadcaster.add(eventOutput);
          return eventOutput;
      }
  }
  </code></pre>
  
  <p>My Index.html code is as below.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  var url = "webapi/broadcast";
  //var url="http://localhost:8080/trackapp/webapi/broadcast/listen";
  var source=new EventSource(url);
  source.onerror=function(event)
  {
  console.log("error [" + source.readyState + "]");
  };
  
  source.onopen = function(event){
      console.log("eventsource opened!");
      };
  
  source.onmessage=function(event)
    {
      console.log(event.data);
  
    document.getElementById("result").innerHTML+=event.data + "&lt;br&gt;";
    };
  &lt;/script&gt;
  </code></pre>