/* Copyright 2012 Adam Bien, adam-bien.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package org.lightfish.presentation.publication.escalation; import java.io.IOException; import java.util.logging.Logger; import javax.enterprise.event.Event; import javax.inject.Inject; import javax.servlet.AsyncContext; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.lightfish.presentation.publication.BrowserWindow; /** * * @author Adam Bien, blog.adam-bien.com */ @WebServlet(name = "CometEscalator", urlPatterns = {"/escalations/*"}, asyncSupported = true) public class CometEscalator extends HttpServlet { @Inject @EscalationWindow Event<BrowserWindow> events; private final static Logger LOG = Logger.getLogger(CometEscalator.class.getName()); @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { AsyncContext startAsync = request.startAsync(); String channel = extractChannel(request.getRequestURI()); events.fire(new BrowserWindow(startAsync, channel)); LOG.fine("Event sent for channel " + channel); } String extractChannel(String uri) { int lastIndexOf = uri.lastIndexOf("/"); return uri.substring(lastIndexOf + 1); } }