Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8F23ACE22 for ; Tue, 23 Jul 2013 12:22:06 +0000 (UTC) Received: (qmail 87412 invoked by uid 500); 23 Jul 2013 12:22:06 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 87286 invoked by uid 500); 23 Jul 2013 12:22:04 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 87278 invoked by uid 99); 23 Jul 2013 12:22:03 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Jul 2013 12:22:03 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Jul 2013 12:22:00 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 2139C2388900; Tue, 23 Jul 2013 12:21:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1506009 - in /cxf/branches/2.7.x-fixes: ./ rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ systests/jaxrs/src/test/resources/servlet_as_filter/ systests/jaxrs/sr... Date: Tue, 23 Jul 2013 12:21:39 -0000 To: commits@cxf.apache.org From: sergeyb@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130723122139.2139C2388900@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sergeyb Date: Tue Jul 23 12:21:38 2013 New Revision: 1506009 URL: http://svn.apache.org/r1506009 Log: Merged revisions 1505957,1505965,1506005 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r1505957 | sergeyb | 2013-07-23 11:15:53 +0100 (Tue, 23 Jul 2013) | 1 line [CXF-4377] Some more work to do with running CXFServlet as Filter ........ r1505965 | sergeyb | 2013-07-23 11:45:28 +0100 (Tue, 23 Jul 2013) | 1 line Moving FilterDeclaration package name closer to the relevant code to protect more from pre-3.0 servlet API being linked to; the reflection can be introduced if really needed ........ r1506005 | sergeyb | 2013-07-23 13:05:18 +0100 (Tue, 23 Jul 2013) | 1 line Using reflection to get FilterRegistration ........ Added: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerServletFilter.java - copied unchanged from r1505965, cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerServletFilter.java cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSServletFilterTest.java - copied unchanged from r1505965, cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSServletFilterTest.java cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/resources/servlet_as_filter/ - copied from r1505965, cxf/trunk/systests/jaxrs/src/test/resources/servlet_as_filter/ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/resources/servlet_as_filter/WEB-INF/ - copied from r1505965, cxf/trunk/systests/jaxrs/src/test/resources/servlet_as_filter/WEB-INF/ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/resources/servlet_as_filter/WEB-INF/beans.xml - copied unchanged from r1505965, cxf/trunk/systests/jaxrs/src/test/resources/servlet_as_filter/WEB-INF/beans.xml cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/resources/servlet_as_filter/WEB-INF/web.xml - copied unchanged from r1505965, cxf/trunk/systests/jaxrs/src/test/resources/servlet_as_filter/WEB-INF/web.xml Modified: cxf/branches/2.7.x-fixes/ (props changed) cxf/branches/2.7.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SpringServletConfigStore.java Propchange: cxf/branches/2.7.x-fixes/ ------------------------------------------------------------------------------ Merged /cxf/trunk:r1505957-1505965,1506005 Propchange: cxf/branches/2.7.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.7.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java?rev=1506009&r1=1506008&r2=1506009&view=diff ============================================================================== --- cxf/branches/2.7.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java (original) +++ cxf/branches/2.7.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java Tue Jul 23 12:21:38 2013 @@ -19,14 +19,18 @@ package org.apache.cxf.transport.servlet; import java.io.IOException; +import java.lang.reflect.Method; +import java.util.Collection; import javax.servlet.FilterChain; import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletResponse; import org.apache.cxf.Bus; @@ -34,6 +38,7 @@ import org.apache.cxf.BusException; import org.apache.cxf.BusFactory; import org.apache.cxf.common.classloader.ClassLoaderUtils; import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder; +import org.apache.cxf.helpers.CastUtils; import org.apache.cxf.resource.ResourceManager; import org.apache.cxf.transport.DestinationFactory; import org.apache.cxf.transport.DestinationFactoryManager; @@ -131,7 +136,10 @@ public class CXFNonSpringServlet extends if (bus != null) { origBus = BusFactory.getAndSetThreadDefaultBus(bus); } - if (controller.filter((HttpServletRequest)request, (HttpServletResponse)response)) { + HttpServletRequest httpRequest = (HttpServletRequest)request; + if (controller.filter(new HttpServletRequestFilter(httpRequest, + super.getServletName()), + (HttpServletResponse)response)) { return; } } finally { @@ -189,4 +197,57 @@ public class CXFNonSpringServlet extends bus = null; } } + + private static class HttpServletRequestFilter extends HttpServletRequestWrapper { + private String filterName; + private String servletPath; + private String pathInfo; + public HttpServletRequestFilter(HttpServletRequest request, String filterName) { + super(request); + this.filterName = filterName; + } + + @Override + public String getServletPath() { + if (servletPath == null) { + try { + Method m = ServletContext.class.getMethod("getFilterRegistration", new Class[] {String.class}); + Object registration = m.invoke(super.getServletContext(), new Object[]{filterName}); + if (registration != null) { + m = registration.getClass().getMethod("getUrlPatternMappings", new Class[] {}); + Collection mappings = + CastUtils.cast((Collection)m.invoke(registration, new Object[]{})); + if (!mappings.isEmpty()) { + String mapping = mappings.iterator().next(); + if (mapping.endsWith("/*")) { + servletPath = mapping.substring(0, mapping.length() - 2); + } + } + } + } catch (Throwable ex) { + // ignore + } + if (servletPath == null) { + servletPath = ""; + } + } + + return servletPath; + } + + @Override + public String getPathInfo() { + if (pathInfo == null) { + pathInfo = super.getPathInfo(); + if (pathInfo == null) { + pathInfo = getRequestURI(); + } + String prefix = super.getContextPath() + this.getServletPath(); + if (pathInfo.startsWith(prefix)) { + pathInfo = pathInfo.substring(prefix.length()); + } + } + return pathInfo; + } + } } Modified: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SpringServletConfigStore.java URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SpringServletConfigStore.java?rev=1506009&r1=1506008&r2=1506009&view=diff ============================================================================== --- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SpringServletConfigStore.java (original) +++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SpringServletConfigStore.java Tue Jul 23 12:21:38 2013 @@ -23,6 +23,7 @@ import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import org.springframework.web.context.ServletConfigAware; @@ -39,4 +40,11 @@ public class SpringServletConfigStore im public String getServletConfigInitParam(@PathParam("name") String name) { return servletConfig.getInitParameter(name); } + + @GET + @Produces("text/plain") + @Path("config/query") + public String getServletConfigInitParamQuery(@QueryParam("name") String name) { + return servletConfig.getInitParameter(name); + } }