You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2008/08/12 20:45:22 UTC
svn commit: r685261 -
/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
Author: dkulp
Date: Tue Aug 12 11:45:22 2008
New Revision: 685261
URL: http://svn.apache.org/viewvc?rev=685261&view=rev
Log:
[CXF-1730] More attempts at getting the needed information into the message
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java?rev=685261&r1=685260&r2=685261&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java Tue Aug 12 11:45:22 2008
@@ -75,6 +75,20 @@
}
+ private static String updatePath(String path, String address) {
+ if (path.startsWith(address)) {
+ path = path.substring(address.length());
+ if (!path.startsWith("/")) {
+ path = "/" + path;
+ }
+ }
+
+ if (!path.endsWith("/")) {
+ path = path + "/";
+ }
+ return path;
+ }
+
private void processRequest(Message message) {
RequestPreprocessor rp =
ProviderFactory.getInstance().getRequestPreprocessor();
@@ -96,18 +110,7 @@
address = address.substring(idx);
}
}
-
- if (path.startsWith(address)) {
- path = path.substring(address.length());
- if (!path.startsWith("/")) {
- path = "/" + path;
- }
- }
-
- if (!path.endsWith("/")) {
- path = path + "/";
- }
-
+ path = updatePath(path, address);
//1. Matching target resource class
Service service = message.getExchange().get(Service.class);
@@ -118,6 +121,8 @@
acceptTypes = "*/*";
message.put(Message.ACCEPT_CONTENT_TYPE, acceptTypes);
}
+ List<MediaType> acceptContentTypes = JAXRSUtils.sortMediaTypes(acceptTypes);
+ message.getExchange().put(Message.ACCEPT_CONTENT_TYPE, acceptContentTypes);
MultivaluedMap<String, String> values = new MetadataMap<String, String>();
ClassResourceInfo resource = JAXRSUtils.selectResourceClass(resources, path, values);
@@ -127,47 +132,58 @@
BUNDLE,
path);
LOG.severe(errorMsg.toString());
- acceptTypes = (String)message.get(Message.ACCEPT_CONTENT_TYPE);
- List<MediaType> acceptContentTypes = JAXRSUtils.sortMediaTypes(acceptTypes);
- message.getExchange().put(Message.ACCEPT_CONTENT_TYPE, acceptContentTypes);
throw new WebApplicationException(404);
}
message.getExchange().put(ROOT_RESOURCE_CLASS, resource);
+ OperationResourceInfo ori = null;
+
List<ProviderInfo<RequestHandler>> shs =
ProviderFactory.getInstance().getRequestHandlers();
for (ProviderInfo<RequestHandler> sh : shs) {
+ String newAcceptTypes = (String)message.get(Message.ACCEPT_CONTENT_TYPE);
+ if (!acceptTypes.equals(newAcceptTypes) || ori == null) {
+ acceptTypes = newAcceptTypes;
+ acceptContentTypes = JAXRSUtils.sortMediaTypes(newAcceptTypes);
+ message.getExchange().put(Message.ACCEPT_CONTENT_TYPE, acceptContentTypes);
+
+ if (ori != null) {
+ values = new MetadataMap<String, String>();
+ resource = JAXRSUtils.selectResourceClass(resources, path, values);
+ }
+ ori = JAXRSUtils.findTargetMethod(resource, values.getFirst(URITemplate.FINAL_MATCH_GROUP),
+ httpMethod, values, requestContentType, acceptContentTypes);
+ message.getExchange().put(OperationResourceInfo.class, ori);
+ }
Response response = sh.getProvider().handleRequest(message, resource);
if (response != null) {
message.getExchange().put(Response.class, response);
- acceptTypes = (String)message.get(Message.ACCEPT_CONTENT_TYPE);
- List<MediaType> acceptContentTypes = JAXRSUtils.sortMediaTypes(acceptTypes);
- message.getExchange().put(Message.ACCEPT_CONTENT_TYPE, acceptContentTypes);
- OperationResourceInfo ori =
- JAXRSUtils.findTargetMethod(resource, values.getFirst(URITemplate.FINAL_MATCH_GROUP),
- httpMethod, values, requestContentType, acceptContentTypes);
- message.getExchange().put(OperationResourceInfo.class, ori);
-
return;
}
}
- acceptTypes = (String)message.get(Message.ACCEPT_CONTENT_TYPE);
- List<MediaType> acceptContentTypes = JAXRSUtils.sortMediaTypes(acceptTypes);
- message.getExchange().put(Message.ACCEPT_CONTENT_TYPE, acceptContentTypes);
+ String newAcceptTypes = (String)message.get(Message.ACCEPT_CONTENT_TYPE);
+ if (!acceptTypes.equals(newAcceptTypes) || ori == null) {
+ acceptTypes = newAcceptTypes;
+ acceptContentTypes = JAXRSUtils.sortMediaTypes(acceptTypes);
+ message.getExchange().put(Message.ACCEPT_CONTENT_TYPE, acceptContentTypes);
+ if (ori != null) {
+ values = new MetadataMap<String, String>();
+ resource = JAXRSUtils.selectResourceClass(resources, path, values);
+ }
+ ori = JAXRSUtils.findTargetMethod(resource, values.getFirst(URITemplate.FINAL_MATCH_GROUP),
+ httpMethod, values, requestContentType, acceptContentTypes);
+ message.getExchange().put(OperationResourceInfo.class, ori);
+ }
+
LOG.fine("Request path is: " + path);
LOG.fine("Request HTTP method is: " + httpMethod);
LOG.fine("Request contentType is: " + requestContentType);
LOG.fine("Accept contentType is: " + acceptTypes);
-
- OperationResourceInfo ori =
- JAXRSUtils.findTargetMethod(resource, values.getFirst(URITemplate.FINAL_MATCH_GROUP),
- httpMethod, values, requestContentType, acceptContentTypes);
-
if (ori == null) {
org.apache.cxf.common.i18n.Message errorMsg =
new org.apache.cxf.common.i18n.Message("NO_OP_EXC",