001/*
002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Nuxeo
016 */
017package org.nuxeo.elasticsearch.web.sync;
018
019import static org.jboss.seam.ScopeType.APPLICATION;
020
021import java.io.IOException;
022
023import javax.servlet.FilterChain;
024import javax.servlet.ServletException;
025import javax.servlet.ServletRequest;
026import javax.servlet.ServletResponse;
027
028import org.jboss.seam.annotations.Name;
029import org.jboss.seam.annotations.Scope;
030import org.jboss.seam.annotations.intercept.BypassInterceptors;
031import org.jboss.seam.annotations.web.Filter;
032import org.jboss.seam.web.AbstractFilter;
033import org.nuxeo.elasticsearch.listener.ElasticSearchInlineListener;
034
035@Scope(APPLICATION)
036@Filter(within = "org.jboss.seam.web.ajax4jsfFilter")
037@BypassInterceptors
038@Name("UIThreadMarker")
039public class UIThreadMarker extends AbstractFilter {
040
041    @Override
042    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
043            ServletException {
044        ElasticSearchInlineListener.useSyncIndexing.set(true);
045        try {
046            chain.doFilter(request, response);
047        } finally {
048            ElasticSearchInlineListener.useSyncIndexing.set(false);
049        }
050    }
051
052}