cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1404293 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java test/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProviderTest.java
Date Wed, 31 Oct 2012 18:48:01 GMT
Author: sergeyb
Date: Wed Oct 31 18:48:01 2012
New Revision: 1404293

URL: http://svn.apache.org/viewvc?rev=1404293&view=rev
Log:
[CXF-4607] Updating RequestDispatcherProvider to support enums better

Added:
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProviderTest.java
  (with props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java?rev=1404293&r1=1404292&r2=1404293&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java
Wed Oct 31 18:48:01 2012
@@ -84,6 +84,7 @@ public class RequestDispatcherProvider e
     private String servletPath;
     private boolean saveParametersAsAttributes;
     private boolean logRedirects;
+    private boolean strictPathCheck;
     
     private MessageContext mc; 
 
@@ -91,6 +92,10 @@ public class RequestDispatcherProvider e
     public void setMessageContext(MessageContext context) {
         this.mc = context;
     }
+
+    public void setStrictPathCheck(boolean use) {
+        strictPathCheck = use;
+    }
     
     public void setUseClassNames(boolean use) {
         useClassNames = use;
@@ -118,13 +123,14 @@ public class RequestDispatcherProvider e
                                                      getBus()) != null) {
             return true;
         }
-        if (resourcePath != null || classResources.containsKey(type.getName())) {
+        if (resourcePath != null || classResourceSupported(type)) {
             return true;
         }
         if (!resourcePaths.isEmpty()) {
             String path = getRequestPath();
             for (String requestPath : resourcePaths.keySet()) {
-                if (path.endsWith(requestPath)) {
+                boolean result = strictPathCheck ? path.endsWith(requestPath) : path.contains(requestPath);
 
+                if (result) {
                     return true;
                 }
             }
@@ -132,12 +138,26 @@ public class RequestDispatcherProvider e
         return false;
     }
 
+    private boolean classResourceSupported(Class<?> type) {
+        String typeName = type.getName();
+        if (type.isEnum()) {
+            for (String name : classResources.keySet()) {
+                if (name.startsWith(typeName)) {
+                    return true;
+                }
+            }
+            return false;
+        } else {
+            return classResources.containsKey(typeName);
+        }
+    }
+    
     public void writeTo(Object o, Class<?> clazz, Type genericType, Annotation[] annotations,

                         MediaType type, MultivaluedMap<String, Object> headers, OutputStream
os)
         throws IOException {
         
         ServletContext sc = getServletContext();
-        String path = getResourcePath(clazz);
+        String path = getResourcePath(clazz, o);
         RequestDispatcher rd = getRequestDispatcher(sc, clazz, path);
         
         try {
@@ -173,11 +193,17 @@ public class RequestDispatcherProvider e
         }
     }
     
-    private String getResourcePath(Class<?> cls) {
+    String getResourcePath(Class<?> cls, Object o) {
         if (useClassNames) {
             return getClassResourceName(cls);     
         }
-        String clsResourcePath = classResources.get(cls.getName());
+        
+        String name = cls.getName();
+        if (cls.isEnum()) {
+            name += "." + o.toString();     
+        }
+        
+        String clsResourcePath = classResources.get(name);
         if (clsResourcePath != null) {
             return clsResourcePath;
         }

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProviderTest.java?rev=1404293&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProviderTest.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProviderTest.java
Wed Oct 31 18:48:01 2012
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.provider;
+
+import java.util.Collections;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class RequestDispatcherProviderTest extends Assert {
+    
+    @Test
+    public void testIsWriteableEnum() {
+        
+        RequestDispatcherProvider p = new RequestDispatcherProvider();
+        p.setClassResources(
+            Collections.singletonMap(TestEnum.class.getName() + "." + TestEnum.ONE, "/test.jsp"));
+        assertTrue(p.isWriteable(TestEnum.ONE.getClass(), null, null, null));
+        assertEquals("/test.jsp", p.getResourcePath(TestEnum.ONE.getClass(), TestEnum.ONE));
+    }
+    
+    private static enum TestEnum {
+        ONE,
+        TWO
+    }
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProviderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProviderTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message