001/*
002 * (C) Copyright 2006-2017 Nuxeo (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     bstefanescu
018 */
019package org.nuxeo.ecm.webengine.app.jersey;
020
021import java.io.IOException;
022import javax.servlet.ServletConfig;
023import javax.servlet.ServletException;
024import javax.servlet.http.HttpServletRequest;
025import javax.servlet.http.HttpServletResponse;
026import org.nuxeo.ecm.webengine.jaxrs.Activator;
027import org.nuxeo.ecm.webengine.jaxrs.servlet.ApplicationServlet;
028
029/**
030 * WebEngine integration with OSGi JAX-RS model from ECR.
031 *
032 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
033 */
034public class WebEngineServlet extends ApplicationServlet {
035
036    private static final long serialVersionUID = 1L;
037
038    @Override
039    public void init(ServletConfig config) throws ServletException {
040        bundle = Activator.getInstance().getContext().getBundle();
041        super.init(config);
042    }
043
044    @Override
045    public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
046        containerService(request, response);
047    }
048
049    @Override
050    protected void containerService(HttpServletRequest request, HttpServletResponse response) throws ServletException,
051            IOException {
052        if (isDirty) {
053            reloadContainer();
054        }
055        String method = request.getMethod().toUpperCase();
056        if (!"GET".equals(method)) {
057            // force reading properties because jersey is consuming one
058            // character
059            // from the input stream - see WebComponent.isEntityPresent.
060            request.getParameterMap();
061        }
062        container.service(request, response);
063    }
064}