Author: sergeyb Date: Wed Oct 31 18:57:30 2012 New Revision: 1404298 URL: http://svn.apache.org/viewvc?rev=1404298&view=rev Log: Merged revisions 1404294 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes
................ r1404294 | sergeyb | 2012-10-31 18:50:31 +0000 (Wed, 31 Oct 2012) | 9 lines Merged revisions 1404293 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r1404293 | sergeyb | 2012-10-31 18:48:01 +0000 (Wed, 31 Oct 2012) | 1 line [CXF-4607] Updating RequestDispatcherProvider to support enums better ........ ................ Added: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProviderTest.java - copied unchanged from r1404294, cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProviderTest.java Modified: cxf/branches/2.5.x-fixes/ (props changed) cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java Propchange: cxf/branches/2.5.x-fixes/ ------------------------------------------------------------------------------ Merged /cxf/trunk:r1404293 Merged /cxf/branches/2.6.x-fixes:r1404294 Propchange: cxf/branches/2.5.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java?rev=1404298&r1=1404297&r2=1404298&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java (original) +++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java Wed Oct 31 18:57:30 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; }
