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 2011/10/20 00:11:21 UTC
svn commit: r1186533 -
/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java
Author: sergeyb
Date: Wed Oct 19 22:11:21 2011
New Revision: 1186533
URL: http://svn.apache.org/viewvc?rev=1186533&view=rev
Log:
Minor updates to RequestDispatcherProvider
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=1186533&r1=1186532&r2=1186533&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 19 22:11:21 2011
@@ -46,6 +46,8 @@ 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.message.Message;
+import org.apache.cxf.phase.PhaseInterceptorChain;
import org.apache.cxf.transport.http.AbstractHTTPDestination;
@Produces("text/html")
@@ -65,10 +67,12 @@ public class RequestDispatcherProvider e
private String servletContextPath;
private String resourcePath;
+ private Map<String, String> resourcePaths = Collections.emptyMap();
private Map<String, String> classResources = Collections.emptyMap();
private String scope = REQUEST_SCOPE;
private Map<String, String> beanNames = Collections.emptyMap();
+ private String beanName;
private String dispatcherName;
private String servletPath;
@@ -80,7 +84,18 @@ public class RequestDispatcherProvider e
}
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) {
- return resourcePath != null || classResources.containsKey(type.getName());
+ if (resourcePath != null || classResources.containsKey(type.getName())) {
+ return true;
+ }
+ if (!resourcePaths.isEmpty()) {
+ String path = getRequestPath();
+ for (String requestPath : resourcePaths.keySet()) {
+ if (path.endsWith(requestPath)) {
+ return true;
+ }
+ }
+ }
+ return false;
}
public void writeTo(Object o, Class<?> clazz, Type genericType, Annotation[] annotations,
@@ -88,7 +103,7 @@ public class RequestDispatcherProvider e
throws IOException {
ServletContext sc = getServletContext();
- String path = resourcePath != null ? resourcePath : classResources.get(clazz.getName());
+ String path = getResourcePath(clazz.getName());
RequestDispatcher rd = getRequestDispatcher(sc, clazz, path);
try {
@@ -111,6 +126,29 @@ public class RequestDispatcherProvider e
}
}
+ private String getResourcePath(String clsName) {
+ String clsResourcePath = classResources.get(clsName);
+ if (clsResourcePath != null) {
+ return clsResourcePath;
+ }
+ if (resourcePath != null) {
+ return resourcePath;
+ }
+ String path = getRequestPath();
+ for (String requestPath : resourcePaths.keySet()) {
+ if (path.endsWith(requestPath)) {
+ return resourcePaths.get(requestPath);
+ }
+ }
+ // won't happen given that isWriteable() returned true
+ return null;
+ }
+
+ private String getRequestPath() {
+ Message inMessage = PhaseInterceptorChain.getCurrentMessage().getExchange().getInMessage();
+ return (String)inMessage.get(Message.REQUEST_URI);
+ }
+
protected ServletContext getServletContext() {
ServletContext sc = mc.getServletContext();
if (servletContextPath != null) {
@@ -156,7 +194,14 @@ public class RequestDispatcherProvider e
this.beanNames = beanNames;
}
+ public void setBeanName(String beanName) {
+ this.beanName = beanName;
+ }
+
protected String getBeanName(Object bean) {
+ if (beanName != null) {
+ return beanName;
+ }
String name = beanNames.get(bean.getClass().getName());
return name != null ? name : bean.getClass().getSimpleName().toLowerCase();
}
@@ -200,6 +245,10 @@ public class RequestDispatcherProvider e
this.servletPath = path;
}
+ public void setResourcePaths(Map<String, String> resourcePaths) {
+ this.resourcePaths = resourcePaths;
+ }
+
protected static class HttpServletRequestFilter extends HttpServletRequestWrapper {
private Map<String, String[]> params;