title: Jersey SSE client not working
body: <p>Am new to Jersey SSE Client API, I have a servlet which continuously send the events. I see it working when i invoke the URL from the browser. When tried to invoke the same using Jersey SSE client, its not working as expected, i don't see any exceptions being thrown.</p>
  
  <p>Here is the code am using for this.</p>
  
  <p><strong>SERVLET:</strong></p>
  
  <pre><code>    package com.abc.test;
  
      import java.io.IOException;
      import java.io.PrintWriter;
      import java.util.Calendar;
  
      import javax.servlet.ServletException;
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
  
      public class TestStream extends HttpServlet {
  
      private static final long serialVersionUID = 1L;
  
      protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException {
          res.setContentType("text/event-stream");
          res.setCharacterEncoding("UTF-8");
          PrintWriter printWriter = null;
  
          while(true)
          {
              try {
                  printWriter = res.getWriter();
                  printWriter.print("data: Thread Will wait for 10 seconds and push the notifications \n\n");
                  printWriter.print("data: " + Calendar.getInstance().getTime() +"\n\n");
                  res.flushBuffer();
                  Thread.sleep(10000);
              }
              catch(IOException ie) {
                  printWriter.close();
                  break;
              }
              catch(InterruptedException ie){
                  printWriter.close();
                  break;
              }
          }
  
      }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Jersey SSE Client code:</strong></p>
  
  <pre><code>package com.abc.test;
  
  import javax.ws.rs.client.Client;
  import javax.ws.rs.client.ClientBuilder;
  import javax.ws.rs.client.WebTarget;
  import javax.ws.rs.core.Response;
  
  import org.glassfish.jersey.media.sse.EventSource;
  import org.glassfish.jersey.media.sse.InboundEvent;
  import org.glassfish.jersey.media.sse.SseFeature;
  
  
  public class ListenerThread implements Runnable {
  
  private int i = 0;
  private Thread t;
  
  public void start() {
      if (t == null) {
          t = new Thread(this);
          t.start();
      }
  }
  
  @Override
  public void run() {
      EventSource eventSource = null;
      try {
          // TODO Auto-generated method stub
          Client client = ClientBuilder.newBuilder()
                  .register(SseFeature.class).build();
          WebTarget target = client.target("http://172.20.14.19:8080/TestStream/SSE");
          eventSource = new EventSource(target) {
              @Override
              public void onEvent(InboundEvent inboundEvent) {
                      System.out.println(inboundEvent.getName() + "; "
                              + inboundEvent.readData(String.class));
              }
          };
  
          while (i &lt;= 10) {
              try {
                  Thread.sleep(6000);
                  System.out.println("Printing I value : " + i);
                  System.out.println("Is Event Source OPEN : " + eventSource.isOpen());
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      } catch (Throwable t) {
          System.out.println("Inside Throwable");
          t.printStackTrace();
      } finally {
          if (null != eventSource)
              eventSource.close();
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Jersey Client onEvent never triggered. Will appreciate any help on this. Let me know, if am missing anything.  </p>
  
  <p>Thanks,
  Pradeep</p>