Author: sergeyb Date: Fri May 18 11:30:41 2012 New Revision: 1340071 URL: http://svn.apache.org/viewvc?rev=1340071&view=rev Log: Merged revisions 1340066 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.5.x-fixes
................ r1340066 | sergeyb | 2012-05-18 12:18:33 +0100 (Fri, 18 May 2012) | 9 lines Merged revisions 1340065 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r1340065 | sergeyb | 2012-05-18 12:12:03 +0100 (Fri, 18 May 2012) | 1 line [CXF-4322] Minor update to RequestDispatcherProvider to check if view handlers are available for a given class ........ ................ Modified: cxf/branches/2.4.x-fixes/ (props changed) cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java Propchange: cxf/branches/2.4.x-fixes/ ------------------------------------------------------------------------------ Merged /cxf/branches/2.5.x-fixes:r1340066 Merged /cxf/trunk:r1340065 Propchange: cxf/branches/2.4.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java?rev=1340071&r1=1340070&r2=1340071&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java (original) +++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java Fri May 18 11:30:41 2012 @@ -47,6 +47,7 @@ import javax.ws.rs.ext.Provider; import org.apache.cxf.common.i18n.BundleUtils; import org.apache.cxf.common.logging.LogUtils; import org.apache.cxf.jaxrs.ext.MessageContext; +import org.apache.cxf.jaxrs.utils.ResourceUtils; import org.apache.cxf.message.Message; import org.apache.cxf.phase.PhaseInterceptorChain; import org.apache.cxf.transport.http.AbstractHTTPDestination; @@ -67,10 +68,14 @@ public class RequestDispatcherProvider e private static final String REQUEST_SCOPE = "request"; private static final String SESSION_SCOPE = "session"; + private static final String DEFAULT_RESOURCE_EXTENSION = ".jsp"; + private static final String DEFAULT_LOCATION_PREFIX = "/WEB-INF/"; + private String servletContextPath; private String resourcePath; private Map<String, String> resourcePaths = Collections.emptyMap(); private Map<String, String> classResources = Collections.emptyMap(); + private boolean useClassNames; private String scope = REQUEST_SCOPE; private Map<String, String> beanNames = Collections.emptyMap(); @@ -80,14 +85,39 @@ public class RequestDispatcherProvider e private boolean saveParametersAsAttributes; private boolean logRedirects; - @Context private MessageContext mc; + @Context + public void setMessageContext(MessageContext context) { + this.mc = context; + } + + public void setUseClassNames(boolean use) { + useClassNames = use; + } + public long getSize(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) { return -1; } + private String getClassResourceName(Class<?> type) { + String simpleName = type.getSimpleName(); + StringBuilder sb = new StringBuilder(); + sb.append(Character.toLowerCase(simpleName.charAt(0))); + if (simpleName.length() > 1) { + sb.append(simpleName.substring(1)); + } + return DEFAULT_LOCATION_PREFIX + sb.toString() + DEFAULT_RESOURCE_EXTENSION; + } + public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) { + + if (useClassNames + && ResourceUtils.getClasspathResourceURL(getClassResourceName(type), + RequestDispatcherProvider.class, + getBus()) != null) { + return true; + } if (resourcePath != null || classResources.containsKey(type.getName())) { return true; } @@ -107,7 +137,7 @@ public class RequestDispatcherProvider e throws IOException { ServletContext sc = getServletContext(); - String path = getResourcePath(clazz.getName()); + String path = getResourcePath(clazz); RequestDispatcher rd = getRequestDispatcher(sc, clazz, path); try { @@ -143,8 +173,11 @@ public class RequestDispatcherProvider e } } - private String getResourcePath(String clsName) { - String clsResourcePath = classResources.get(clsName); + private String getResourcePath(Class<?> cls) { + if (useClassNames) { + return getClassResourceName(cls); + } + String clsResourcePath = classResources.get(cls.getName()); if (clsResourcePath != null) { return clsResourcePath; }
