cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1506005 - /cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
Date Tue, 23 Jul 2013 12:05:18 GMT
Author: sergeyb
Date: Tue Jul 23 12:05:18 2013
New Revision: 1506005

URL: http://svn.apache.org/r1506005
Log:
Using reflection to get FilterRegistration

Modified:
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java?rev=1506005&r1=1506004&r2=1506005&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
Tue Jul 23 12:05:18 2013
@@ -19,9 +19,12 @@
 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;
@@ -35,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;
@@ -196,6 +200,8 @@ public class CXFNonSpringServlet extends
     
     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;
@@ -203,25 +209,43 @@ public class CXFNonSpringServlet extends
         
         @Override
         public String getServletPath() {
-            javax.servlet.FilterRegistration fr = super.getServletContext().getFilterRegistration(filterName);
-            if (fr != null && !fr.getUrlPatternMappings().isEmpty()) {
-                String mapping = fr.getUrlPatternMappings().iterator().next();
-                if (mapping.endsWith("/*")) {
-                    return mapping.substring(0, mapping.length() - 2);
+            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 "";
+            
+            return servletPath;
         }
         
         @Override
         public String getPathInfo() {
-            String pathInfo = super.getPathInfo();
             if (pathInfo == null) {
-                pathInfo = getRequestURI();
-            }
-            String prefix = super.getContextPath() + this.getServletPath();
-            if (pathInfo.startsWith(prefix)) {
-                pathInfo = pathInfo.substring(prefix.length());
+                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;
         }



Mime
View raw message