cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1466840 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ systests/jaxrs/src/test/java...
Date Thu, 11 Apr 2013 11:59:01 GMT
Author: sergeyb
Date: Thu Apr 11 11:59:00 2013
New Revision: 1466840

URL: http://svn.apache.org/r1466840
Log:
[CXF-4950] Avoiding checking Consumes in case of GET and few other minor updaes

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.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=1466840&r1=1466839&r2=1466840&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
Thu Apr 11 11:59:00 2013
@@ -123,7 +123,7 @@ public class JAXRSInInterceptor extends 
         
         String requestContentType = (String)message.get(Message.CONTENT_TYPE);
         if (requestContentType == null) {
-            requestContentType = "*/*";
+            requestContentType = MediaType.WILDCARD;
         }
         
         String rawPath = HttpUtils.getPathToMatch(message, true);

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java?rev=1466840&r1=1466839&r2=1466840&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
Thu Apr 11 11:59:00 2013
@@ -22,6 +22,7 @@ package org.apache.cxf.jaxrs.model;
 import java.util.Comparator;
 import java.util.List;
 
+import javax.ws.rs.HttpMethod;
 import javax.ws.rs.core.MediaType;
 
 import org.apache.cxf.endpoint.Endpoint;
@@ -31,15 +32,16 @@ import org.apache.cxf.message.Message;
 
 public class OperationResourceInfoComparator implements Comparator<OperationResourceInfo>
{
     
-    private static final String HEAD_METHOD = "HEAD";
-    private boolean headMethod;
+    private String httpMethod;
+    private boolean getMethod;
     private Message message;
     private ResourceComparator rc;  
     private MediaType contentType;
     private List<MediaType> acceptTypes;
 
     public OperationResourceInfoComparator(Message m, 
-                                           String method, 
+                                           String httpMethod,
+                                           boolean getMethod,
                                            MediaType contentType,
                                            List<MediaType> acceptTypes) {
         this.message = m;
@@ -49,9 +51,10 @@ public class OperationResourceInfoCompar
                 rc = (ResourceComparator)o;
             }
         }
-        headMethod = HEAD_METHOD.equals(method);
         this.contentType = contentType;
         this.acceptTypes = acceptTypes;
+        this.httpMethod = httpMethod;
+        this.getMethod = getMethod;
     }
     
     public int compare(OperationResourceInfo e1, OperationResourceInfo e2) {
@@ -63,10 +66,10 @@ public class OperationResourceInfoCompar
             }
         }
         
-        if (headMethod) {
-            if (HEAD_METHOD.equals(e1.getHttpMethod())) {
+        if (!getMethod && HttpMethod.HEAD.equals(httpMethod)) {
+            if (HttpMethod.HEAD.equals(e1.getHttpMethod())) {
                 return -1;
-            } else if (HEAD_METHOD.equals(e2.getHttpMethod())) {
+            } else if (HttpMethod.HEAD.equals(e2.getHttpMethod())) {
                 return 1;
             }
         }
@@ -81,7 +84,7 @@ public class OperationResourceInfoCompar
             return e1.getHttpMethod() != null ? -1 : 1;
         }
         
-        if (result == 0) {
+        if (result == 0 && !getMethod) {
         
             result = JAXRSUtils.compareSortedConsumesMediaTypes(
                           e1.getConsumeTypes(), 

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=1466840&r1=1466839&r2=1466840&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 Thu
Apr 11 11:59:00 2013
@@ -396,17 +396,19 @@ public final class JAXRSUtils {
         boolean throwException) {
         
         final boolean isFineLevelLoggable = LOG.isLoggable(Level.FINE); 
-                
+        final boolean getMethod = HttpMethod.GET.equals(httpMethod);
+        
         MediaType requestType;
         try {
-            requestType = toMediaType(requestContentType);
+            requestType = getMethod ? MediaType.WILDCARD_TYPE : toMediaType(requestContentType);
         } catch (IllegalArgumentException ex) {
             throw new NotSupportedException(ex);
         }
         
         SortedMap<OperationResourceInfo, MultivaluedMap<String, String>> candidateList
= 
             new TreeMap<OperationResourceInfo, MultivaluedMap<String, String>>(
-                new OperationResourceInfoComparator(message, httpMethod, requestType, acceptContentTypes));
+                new OperationResourceInfoComparator(message, httpMethod, 
+                                                    getMethod, requestType, acceptContentTypes));
 
         int pathMatched = 0;
         int methodMatched = 0;
@@ -442,22 +444,10 @@ public final class JAXRSUtils {
                             if (matchHttpMethod(ori.getHttpMethod(), httpMethod)) {
                                 methodMatched++;
                                 //CHECKSTYLE:OFF
-                                if (matchConsumeTypes(requestType, ori)) {
+                                if (getMethod || matchConsumeTypes(requestType, ori)) {
                                     consumeMatched++;
                                     for (MediaType acceptType : acceptContentTypes) {
-                                        MediaType pMediaType = matchProduceTypes(acceptType,
ori);
-                                        if (pMediaType != null) {
-                                            if (acceptContentTypes.size() > 1 
-                                                || ori.getProduceTypes().size() > 1) {
-                                                pMediaType = intersectSortMediaTypes(acceptContentTypes,
-                                                                                     ori.getProduceTypes(),
-                                                                                     false).get(0);
-                                            }
-                                            map.putSingle(Message.CONTENT_TYPE, 
-                                                          mediaTypeToString(pMediaType, 
-                                                                            MEDIA_TYPE_Q_PARAM,

-                                                                            MEDIA_TYPE_QS_PARAM));
-                                            
+                                        if (matchProduceTypes(acceptType, ori)) {
                                             candidateList.put(ori, map);
                                             added = true;
                                             break;
@@ -498,10 +488,12 @@ public final class JAXRSUtils {
                                ori.getClassResourceInfo().getServiceClass().getName()).toString());
             }
             if (!ori.isSubResourceLocator()) {
-                List<String> responseContentType = matchedValues.remove(Message.CONTENT_TYPE);
-                if (responseContentType != null) {
-                    message.getExchange().put(Message.CONTENT_TYPE, responseContentType.get(0));
-                }
+                MediaType responseMediaType = intersectSortMediaTypes(acceptContentTypes,
+                                                                      ori.getProduceTypes(),
+                                                                      false).get(0);
+                message.getExchange().put(Message.CONTENT_TYPE, mediaTypeToString(responseMediaType,

+                                                                                  MEDIA_TYPE_Q_PARAM,

+                                                                                  MEDIA_TYPE_QS_PARAM));
             }
             return ori;
         }
@@ -1389,13 +1381,10 @@ public final class JAXRSUtils {
         return !intersectMimeTypes(ori.getConsumeTypes(), requestContentType).isEmpty();
     }
     
-    public static MediaType matchProduceTypes(MediaType acceptContentType, 
+    public static boolean matchProduceTypes(MediaType acceptContentType, 
                                               OperationResourceInfo ori) {
         
-        List<MediaType> types = intersectMimeTypes(ori.getProduceTypes(), 
-                                                   Collections.singletonList(acceptContentType),
-                                                   true);
-        return types.isEmpty() ? null : types.get(0);
+        return !intersectMimeTypes(ori.getProduceTypes(), acceptContentType).isEmpty();
     }
     
     public static boolean matchMimeTypes(MediaType requestContentType, 

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1466840&r1=1466839&r2=1466840&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Thu
Apr 11 11:59:00 2013
@@ -887,7 +887,7 @@ public class BookStore {
     
     @GET
     @Path("/books/{bookId}/")
-    @Produces("application/json;q=0.9")
+    @Produces("application/json;qs=0.9")
     public Book getBookAsJSON() throws BookNotFoundFault {
         return doGetBook(currentBookId);
     }



Mime
View raw message