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 java.util.Collections; 023import java.util.Enumeration; 024import java.util.Hashtable; 025import java.util.LinkedList; 026import java.util.List; 027import java.util.NoSuchElementException; 028 029import javax.servlet.ServletConfig; 030import javax.servlet.ServletException; 031import javax.servlet.http.HttpServletRequest; 032import javax.servlet.http.HttpServletRequestWrapper; 033import javax.servlet.http.HttpServletResponse; 034import javax.ws.rs.core.HttpHeaders; 035 036import org.nuxeo.ecm.webengine.jaxrs.Activator; 037import org.nuxeo.ecm.webengine.jaxrs.servlet.ApplicationServlet; 038 039/** 040 * WebEngine integration with OSGi JAX-RS model from ECR. 041 * 042 * @author <a href="mailto:[email protected]">Bogdan Stefanescu</a> 043 */ 044public class WebEngineServlet extends ApplicationServlet { 045 046 private static final long serialVersionUID = 1L; 047 048 @Override 049 public void init(ServletConfig config) throws ServletException { 050 bundle = Activator.getInstance().getContext().getBundle(); 051 super.init(config); 052 } 053 054 @Override 055 public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 056 containerService(request, response); 057 } 058 059 @Override 060 protected void containerService(HttpServletRequest request, HttpServletResponse response) throws ServletException, 061 IOException { 062 if (isDirty) { 063 reloadContainer(); 064 } 065 String method = request.getMethod().toUpperCase(); 066 if (!"GET".equals(method)) { 067 // force reading properties because jersey is consuming one 068 // character 069 // from the input stream - see WebComponent.isEntityPresent. 070 request.getParameterMap(); 071 } 072 container.service(request, response); 073 } 074}