You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2013/07/23 14:21:39 UTC
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...
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<String> 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);
+ }
}