title: Firebase Server Sent Events - How to build a Java / JavaScript client
body: <p>I am new to Firebase and building a prototype to test if suitable for our needs. I've got a chat example up and running, so far so good. </p>
  
  <p>Next is the need to listen for changes. I have tried connecting to the REST API supporting server sent events using both Java and JavaScript, but I can not make it work. </p>
  
  <p>In Java I have written the following code: </p>
  
  <pre><code>public class FirebaseApplication {
    @Test
    public void test() throws Exception{
      Client client = ClientBuilder.newBuilder()
        .register(SseFeature.class).build();
      WebTarget webTarget = client.target(new URI(
        "http://incandescent-torch-xxxx.firebaseio.com/logs.json"));
      EventSource eventSource = new EventSource(webTarget) {
        @Override
        public void onEvent(InboundEvent inboundEvent) {
          System.out.println("Data " + inboundEvent.readData());
        }
      };
      Thread.sleep(20000);
      System.out.println("Exit");
      eventSource.close();
    }
  }
  </code></pre>
  
  <p>I do however not receive any events even though I am in parallel with the execution of the little program. </p>
  
  <p>Next I tried using a JavaScript client, but with the same result. I never receive any events.  </p>
  
  <pre><code>var source = new EventSource(
    "http://incandescent-torch-xxxx.firebaseio.com/logs.json");
  
  source.addEventListener('message', function(e) {
    console.log(e.data);
  }, false);
  
  source.addEventListener('open', function(e) {
    console.log("open");
    // Connection was opened.
  }, false);
  
  source.addEventListener('error', function(e) {
    if (e.readyState == EventSource.CLOSED) {
      console.log("close");
      // Connection was closed.
    }else{
      console.log("error");
      console.log(e);
    }
  
  }, false);
  </code></pre>
  
  <p>Does anyone having a clue of what I am doing wrong ? </p>