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 2013/04/08 16:11:23 UTC

svn commit: r1465648 - /cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java

Author: sergeyb
Date: Mon Apr  8 14:11:23 2013
New Revision: 1465648

URL: http://svn.apache.org/r1465648
Log:
[CXF-4950] Minor code updates, preparing for the actual refctoring

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1465648&r1=1465647&r2=1465648&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Mon Apr  8 14:11:23 2013
@@ -162,6 +162,7 @@ public final class JAXRSUtils {
     
     private static final Logger LOG = LogUtils.getL7dLogger(JAXRSUtils.class);
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JAXRSUtils.class);
+    private static final String PATH_SEGMENT_SEP = "/";
     private static final String PROPAGATE_EXCEPTION = "org.apache.cxf.propagate.exception";
     private static final String REPORT_FAULT_MESSAGE_PROPERTY = "org.apache.cxf.jaxrs.report-fault-message";
     private static final String  SUPPORT_WAE_SPEC_OPTIMIZATION = "support.wae.spec.optimization";
@@ -407,7 +408,6 @@ public final class JAXRSUtils {
         int pathMatched = 0;
         int methodMatched = 0;
         int consumeMatched = 0;
-        int produceMatched = 0;
         
         for (Map.Entry<ClassResourceInfo, MultivaluedMap<String, String>> rEntry : matchedResources.entrySet()) {
             ClassResourceInfo resource = rEntry.getKey();
@@ -426,43 +426,45 @@ public final class JAXRSUtils {
             boolean subresourcesOnly = true;
             for (MediaType acceptType : acceptContentTypes) {
                 for (OperationResourceInfo ori : resource.getMethodDispatcher().getOperationResourceInfos()) {
+                    boolean added = false;
+                    
                     URITemplate uriTemplate = ori.getURITemplate();
                     MultivaluedMap<String, String> map = new MetadataMap<String, String>(values);
                     if (uriTemplate != null && uriTemplate.match(path, map)) {
-                        boolean added = false;
                         if (ori.isSubResourceLocator()) {
                             candidateList.put(ori, map);
                             added = true;
                         } else {
                             String finalGroup = map.getFirst(URITemplate.FINAL_MATCH_GROUP);
-                            if (finalGroup == null || StringUtils.isEmpty(finalGroup)
-                                || finalGroup.equals("/")) {
+                            //CHECKSTYLE:OFF
+                            if (StringUtils.isEmpty(finalGroup) || PATH_SEGMENT_SEP.equals(finalGroup)) {
                                 pathMatched++;
-                                boolean mMatched = matchHttpMethod(ori.getHttpMethod(), httpMethod);
-                                boolean cMatched = matchConsumeTypes(requestType, ori);
-                                MediaType pMediaType = matchProduceTypes(acceptType, ori);
-                                if (mMatched && cMatched && pMediaType != null) {
-                                    subresourcesOnly = false;
-                                    map.putSingle(Message.CONTENT_TYPE, mediaTypeToString(pMediaType));
-                                    candidateList.put(ori, map);
-                                    added = true;
-                                } else {
-                                    methodMatched = mMatched ? methodMatched + 1 : methodMatched;
-                                    produceMatched = pMediaType != null ? produceMatched + 1 : produceMatched;
-                                    consumeMatched = cMatched ? consumeMatched + 1 : consumeMatched;
-                                    logNoMatchMessage(ori, path, httpMethod, requestType, acceptContentTypes);
+                                if (matchHttpMethod(ori.getHttpMethod(), httpMethod)) {
+                                    methodMatched++;
+                                    if (matchConsumeTypes(requestType, ori)) {
+                                        consumeMatched++;
+                                        MediaType pMediaType = matchProduceTypes(acceptType, ori);
+                                        if (pMediaType != null) {
+                                            map.putSingle(Message.CONTENT_TYPE, mediaTypeToString(pMediaType));
+                                            
+                                            subresourcesOnly = false;
+                                            candidateList.put(ori, map);
+                                            added = true;
+                                        }
+                                    }
                                 }
-                            } else {
-                                logNoMatchMessage(ori, path, httpMethod, requestType, acceptContentTypes);
                             }
+                            //CHECKSTYLE:ON
                         }
-                        if (added && isFineLevelLoggable) {
+                    } 
+                    if (isFineLevelLoggable) {
+                        if (added) {
                             LOG.fine(new org.apache.cxf.common.i18n.Message("OPER_SELECTED_POSSIBLY", 
                                       BUNDLE, 
                                       ori.getMethodToInvoke().getName()).toString());
+                        } else {
+                            logNoMatchMessage(ori, path, httpMethod, requestType, acceptContentTypes);
                         }
-                    } else {
-                        logNoMatchMessage(ori, path, httpMethod, requestType, acceptContentTypes);
                     }
                 }
                 if (!candidateList.isEmpty() && !subresourcesOnly) {
@@ -507,9 +509,10 @@ public final class JAXRSUtils {
             status = 404;
         } else if (methodMatched == 0) {
             status = 405;
-        } else if (consumeMatched <= produceMatched) {
+        } else if (consumeMatched == 0) {
             status = 415;
         } else {
+            // Not a single Produces match
             status = 406;
         }
         Map.Entry<ClassResourceInfo, MultivaluedMap<String, String>> firstCri = 
@@ -549,9 +552,6 @@ public final class JAXRSUtils {
     
     private static void logNoMatchMessage(OperationResourceInfo ori, 
         String path, String httpMethod, MediaType requestType, List<MediaType> acceptContentTypes) {
-        if (!LOG.isLoggable(Level.FINE)) {
-            return;
-        }
         org.apache.cxf.common.i18n.Message errorMsg = 
             new org.apache.cxf.common.i18n.Message("OPER_NO_MATCH", 
                                                    BUNDLE,
@@ -1298,16 +1298,16 @@ public final class JAXRSUtils {
     public static boolean matchConsumeTypes(MediaType requestContentType, 
                                             OperationResourceInfo ori) {
         
-        return intersectMimeTypes(ori.getConsumeTypes(), requestContentType).size() != 0;
+        return !intersectMimeTypes(ori.getConsumeTypes(), requestContentType).isEmpty();
     }
     
     public static MediaType matchProduceTypes(MediaType acceptContentType, 
-                                            OperationResourceInfo ori) {
+                                              OperationResourceInfo ori) {
         
-        List<MediaType> intersected = intersectMimeTypes(ori.getProduceTypes(), 
-                                                         Collections.singletonList(acceptContentType), 
-                                                         true);
-        return intersected.isEmpty() ? null : intersected.get(0);
+        List<MediaType> types = intersectMimeTypes(ori.getProduceTypes(), 
+                                                   Collections.singletonList(acceptContentType),
+                                                   true);
+        return types.isEmpty() ? null : types.get(0);
     }
     
     public static boolean matchMimeTypes(MediaType requestContentType,