Created
August 5, 2014 14:18
-
-
Save Sennahoi/c695c3d2cf7163082477 to your computer and use it in GitHub Desktop.
Tomcat Comet Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NIOServlet extends HttpServlet implements CometProcessor { | |
@Override | |
public void event(CometEvent event) throws IOException, ServletException { | |
HttpServletResponse response = event.getHttpServletResponse(); | |
if (event.getEventType() == CometEvent.EventType.BEGIN) { | |
new HandlerThread(event, response).start(); | |
} else if (event.getEventType() == CometEvent.EventType.ERROR) { | |
event.close(); | |
} else if (event.getEventType() == CometEvent.EventType.END) { | |
event.close(); | |
} else if (event.getEventType() == CometEvent.EventType.READ) { | |
// noop | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Send data | |
response.getWriter().write("<html><body>OK</body></html>"); | |
response.getWriter().close(); | |
// Send redirect | |
response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); | |
response.setHeader("Location", "http://www.google.de"); | |
event.close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment