incubator-wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r788908 [6/8] - in /incubator/wink/contrib/ibm-jaxrs: src/com/ibm/ws/jaxrs/annotations/ src/com/ibm/ws/jaxrs/context/ src/com/ibm/ws/jaxrs/core/ src/com/ibm/ws/jaxrs/engine/ src/com/ibm/ws/jaxrs/exception/ src/com/ibm/ws/jaxrs/ext/ src/com/...
Date Sat, 27 Jun 2009 00:02:34 GMT
Modified: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=788908&r1=788907&r2=788908&view=diff
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Sat Jun 27 00:02:26 2009
@@ -36,7 +36,6 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -51,6 +50,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.Consumes;
+import javax.ws.rs.HttpMethod;
 import javax.ws.rs.Produces;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
@@ -94,17 +94,15 @@
 import com.ibm.ws.jaxrs.integration.IntegrationRegistry;
 import com.ibm.ws.jaxrs.integration.OptionsResponseProvider;
 import com.ibm.ws.jaxrs.integration.ResponseWriter;
-import com.ibm.ws.jaxrs.io.ContentMonitor;
 import com.ibm.ws.jaxrs.io.LogInputStream;
+import com.ibm.ws.jaxrs.metadata.RESTMetaData;
+import com.ibm.ws.jaxrs.model.ReflectiveJAXRSInfoBuilder;
 import com.ibm.ws.jaxrs.provider.RESTDataSource;
 
 public final class JAXRSUtils {
 
     private static Log log = LogFactory.getLog(JAXRSUtils.class);
 
-    // private static final ResourceBundle BUNDLE =
-    // BundleUtils.getBundle(JAXRSUtils.class);
-
     private JAXRSUtils() {
     }
 
@@ -125,7 +123,7 @@
 
     public static List<MediaType> getMediaTypes(String[] values) {
         if (values == null) {
-            return Collections.singletonList(MediaType.WILDCARD_TYPE);
+            return wildcardTypeAsList;
         }
         List<MediaType> supportedMimeTypes = new ArrayList<MediaType>(
                 values.length);
@@ -135,56 +133,46 @@
         return supportedMimeTypes;
     }
 
-    public static ClassResourceInfo findSubResourceClass(ClassResourceInfo resource, Class subResourceClassType) {
-        for (ClassResourceInfo subCri : resource.getSubClassResourceInfo()) {
-            if (subCri.getResourceClass()
-                    .isAssignableFrom(subResourceClassType)) {
-                return subCri;
-            }
-        }
-        return null;
-    }
-
-    public static ClassResourceInfo selectResourceClass(List<ClassResourceInfo> resources, String path, MultivaluedMap<String, String> values) {
-
-        if (resources.size() == 1) {
-            return resources.get(0).getURITemplate().match(path, values) ? resources
-                    .get(0)
-                    : null;
-        }
-
-        SortedMap<ClassResourceInfo, MultivaluedMap<String, String>> candidateList = new TreeMap<ClassResourceInfo, MultivaluedMap<String, String>>(
-                new Comparator<ClassResourceInfo>() {
-
-                    public int compare(ClassResourceInfo cr1, ClassResourceInfo cr2) {
-
-                        String l1 = cr1.getURITemplate().getLiteralChars();
-                        String l2 = cr2.getURITemplate().getLiteralChars();
-                        if (!l1.equals(l2)) {
-                            // descending order
-                            return l1.length() < l2.length() ? 1 : -1;
-                        }
-
-                        int g1 = cr1.getURITemplate().getNumberOfGroups();
-                        int g2 = cr2.getURITemplate().getNumberOfGroups();
-                        // descending order
-                        return g1 < g2 ? 1 : g1 > g2 ? -1 : 0;
+    public static ClassResourceInfo selectResourceClass(RESTMetaData metadata, String path, MultivaluedMap<String, String> values) {
+        ClassResourceInfo bestMatchingResource = null;
+        MultivaluedMap<String, String> bestMatchingTemplateValues = null;
+
+        /*
+         * pickup from the thread local LRU cache
+         */
+        Map<String, ClassResourceInfo> classCache = metadata
+                .getClassInfoCache();
+        bestMatchingResource = classCache.get(path);
+        if (bestMatchingResource != null) {
+            bestMatchingTemplateValues = bestMatchingResource.getURITemplate()
+                    .match(path);
+        } else {
+            List<ClassResourceInfo> resources = metadata.getClassInfoList();
+            ClassResourceInfoComparator comparator = ClassResourceInfoComparator
+                    .getInstance();
+
+            for (ClassResourceInfo resource : resources) {
+                if (bestMatchingResource != null) {
+                    if (comparator.compare(resource, bestMatchingResource) > -1) {
+                        continue;
                     }
+                }
+                MultivaluedMap<String, String> tempMap = resource
+                        .getURITemplate().match(path);
+                if (tempMap != null) {
+                    bestMatchingResource = resource;
+                    bestMatchingTemplateValues = tempMap;
+                }
+            }
 
-                });
-
-        for (ClassResourceInfo resource : resources) {
-            MultivaluedMap<String, String> map = new MetadataMap<String, String>();
-            if (resource.getURITemplate().match(path, map)) {
-                candidateList.put(resource, map);
+            if (bestMatchingResource != null) {
+                classCache.put(path, bestMatchingResource);
             }
         }
 
-        if (!candidateList.isEmpty()) {
-            Map.Entry<ClassResourceInfo, MultivaluedMap<String, String>> firstEntry = candidateList
-                    .entrySet().iterator().next();
-            values.putAll(firstEntry.getValue());
-            return firstEntry.getKey();
+        if (bestMatchingResource != null) {
+            values.putAll(bestMatchingTemplateValues);
+            return bestMatchingResource;
         }
 
         return null;
@@ -200,24 +188,7 @@
 
         // sorted map for all URITemplates
         SortedMap<URITemplate, MultivaluedMap<String, String>> candidateList = new TreeMap<URITemplate, MultivaluedMap<String, String>>(
-                new Comparator<URITemplate>() {
-
-                    public int compare(URITemplate cr1, URITemplate cr2) {
-
-                        String l1 = cr1.getLiteralChars();
-                        String l2 = cr2.getLiteralChars();
-                        if (!l1.equals(l2)) {
-                            // descending order
-                            return l1.length() < l2.length() ? 1 : -1;
-                        }
-
-                        int g1 = cr1.getNumberOfGroups();
-                        int g2 = cr2.getNumberOfGroups();
-                        // descending order
-                        return g1 < g2 ? 1 : g1 > g2 ? -1 : 0;
-                    }
-
-                });
+                URITemplateComparator.getInstance());
 
         // remove any matrix parameters
         String matrixFreePath = path;
@@ -227,14 +198,15 @@
         }
 
         for (ClassResourceInfo resource : resources) {
-            MultivaluedMap<String, String> map = new MetadataMap<String, String>();
             List<URITemplate> templates = resource.getURIAliasTemplates();
             if (templates != null) {
                 for (URITemplate template : templates) {
 
                     // if we have a match, store the URITemplate and values map,
                     // also store mapping of URITemplate to ClassResourceInfo
-                    if (template.match(matrixFreePath, map)) {
+                    MultivaluedMap<String, String> map = template
+                            .match(matrixFreePath);
+                    if (map != null) {
                         candidateList.put(template, map);
                         templateMapping.put(template, resource);
                     }
@@ -256,23 +228,19 @@
         return null;
     }
 
+    final private static int PATH_CACHE_SIZE = 4;
+    final private static int HTTP_METHOD_CACHE_SIZE = 4;
+    final private static int REQUEST_TYPE_CACHE = 4;
+
     public static OperationResourceInfo findTargetMethod(ClassResourceInfo resource, String path, String httpMethod, MultivaluedMap<String, String> values, String requestContentType, List<MediaType> acceptContentTypes) {
-        SortedMap<OperationResourceInfo, MultivaluedMap<String, String>> candidateList = new TreeMap<OperationResourceInfo, MultivaluedMap<String, String>>(
-                new OperationResourceInfoComparator());
-        MediaType requestType = requestContentType == null ? null : MediaType
-                .valueOf(requestContentType);
-        boolean didMatchRequestType = false;
-        boolean didMatchMethodType = false;
-        boolean didMatchResource = false;
-        Set<String> possibleMethodOperations = new HashSet<String>();
-        if (resource.getMethodDispatcher().getOperationResourceInfos() == null
-                || resource.getMethodDispatcher().getOperationResourceInfos()
-                        .isEmpty()) {
+        List<OperationResourceInfo> opInfos = resource.getMethodDispatcher()
+                .getOperationResourceInfos();
+        if (opInfos == null || opInfos.isEmpty()) {
             if (StringUtils.isEmpty(path) || "/".equals(path)) {
                 // no operations exist at this level, fast fail
                 if (log.isErrorEnabled()) {
                     log.error(Messages.getMessage("resourceNotFound00",
-                            resource.getResourceClass().getName(), httpMethod,
+                            resource.getServiceClass().getName(), httpMethod,
                             path, (requestContentType == null) ? "UNKNOWN"
                                     : requestContentType));
                 }
@@ -281,39 +249,118 @@
             // did not match the final group yet so there didn't exist a subresource to match
             throw new WebApplicationException(Response.Status.NOT_FOUND);
         }
+
+        Map<String, Map<String, Map<String, Map<MediaType, OperationResourceInfo>>>> cache = resource
+                .getMethodDispatcher().getCache();
+        String pathCacheKey = (path == null) ? "" : path;
+        Map<String, Map<String, Map<MediaType, OperationResourceInfo>>> pathCache = cache
+                .get(pathCacheKey);
+        if (pathCache == null) {
+            pathCache = new LinkedHashMap<String, Map<String, Map<MediaType, OperationResourceInfo>>>(
+                    PATH_CACHE_SIZE) {
+
+                private static final long serialVersionUID = 1L;
+
+                @Override
+                public boolean removeEldestEntry(Map.Entry<String, Map<String, Map<MediaType, OperationResourceInfo>>> eldestEntry) {
+                    return size() > PATH_CACHE_SIZE;
+                }
+            };
+            cache.put(pathCacheKey, pathCache);
+        }
+        Map<String, Map<MediaType, OperationResourceInfo>> httpMethodCache = pathCache
+                .get(httpMethod);
+        if (httpMethodCache == null) {
+            httpMethodCache = new LinkedHashMap<String, Map<MediaType, OperationResourceInfo>>(
+                    HTTP_METHOD_CACHE_SIZE) {
+
+                private static final long serialVersionUID = 1L;
+
+                @Override
+                public boolean removeEldestEntry(Map.Entry<String, Map<MediaType, OperationResourceInfo>> eldestEntry) {
+                    return size() > HTTP_METHOD_CACHE_SIZE;
+                }
+            };
+            pathCache.put(httpMethod, httpMethodCache);
+        }
+
+        String requestContentTypeCacheKey = (requestContentType == null) ? ""
+                : requestContentType;
+        Map<MediaType, OperationResourceInfo> requestTypeCache = httpMethodCache
+                .get(requestContentTypeCacheKey);
+        if (requestTypeCache == null) {
+            requestTypeCache = new LinkedHashMap<MediaType, OperationResourceInfo>(
+                    REQUEST_TYPE_CACHE) {
+
+                private static final long serialVersionUID = 1L;
+
+                @Override
+                public boolean removeEldestEntry(Map.Entry<MediaType, OperationResourceInfo> eldestEntry) {
+                    return size() > REQUEST_TYPE_CACHE;
+                }
+            };
+            httpMethodCache.put(requestContentTypeCacheKey, requestTypeCache);
+        }
+
+        OperationResourceInfo bestMatchingORI = null;
+        MultivaluedMap<String, String> bestMatchingMapData = null;
+        final MediaType requestType = requestContentType == null ? null
+                : MediaType.valueOf(requestContentType);
+        boolean didMatchRequestType = false;
+        boolean didMatchMethodType = false;
         for (MediaType acceptType : acceptContentTypes) {
+            bestMatchingORI = requestTypeCache.get(acceptType);
+            if (bestMatchingORI != null) {
+                URITemplate uriTemplate = bestMatchingORI.getURITemplate();
+                bestMatchingMapData = uriTemplate.match(path);
+                values.putAll(bestMatchingMapData);
+                return bestMatchingORI;
+            }
+
+            final OperationResourceInfoComparator oriComparator = OperationResourceInfoComparator
+                    .getInstance(requestType, acceptType);
             // used to save off possible GET match for a HEAD request
-            for (OperationResourceInfo ori : resource.getMethodDispatcher()
-                    .getOperationResourceInfos()) {
-                URITemplate uriTemplate = ori.getURITemplate();
+            for (OperationResourceInfo ori : opInfos) {
+
+                boolean isHttpMethodsEqual = (ori.getHttpMethod() == null) ? false
+                        : ori.getHttpMethod().equals(httpMethod);
+                boolean isHttpMethodHead = HttpMethod.HEAD.equals(httpMethod);
+                boolean isSubResourceLocator = ori.isSubResourceLocator();
+                if (!isHttpMethodsEqual && !isSubResourceLocator
+                        && !isHttpMethodHead) {
+                    continue;
+                }
 
-                MultivaluedMap<String, String> map = cloneMap(values);
-                if (uriTemplate != null && uriTemplate.match(path, map)) {
+                if (bestMatchingORI != null
+                        && oriComparator.compare(ori, bestMatchingORI) > -1) {
+                    continue;
+                }
+
+                URITemplate uriTemplate = ori.getURITemplate();
+                MultivaluedMap<String, String> map = uriTemplate.match(path);
+                if (map != null) {
                     String finalGroup = map
                             .getFirst(URITemplate.FINAL_MATCH_GROUP);
-                    if (ori.isSubResourceLocator()) {
-                        candidateList.put(ori, map);
+                    if (isSubResourceLocator) {
+                        bestMatchingORI = ori;
+                        bestMatchingMapData = map;
                     } else if (finalGroup == null
                             || StringUtils.isEmpty(finalGroup)
-                            || finalGroup.equals("/")) {
-                        didMatchResource = true;
-
-                        possibleMethodOperations.add(ori.getHttpMethod()
-                                .toUpperCase());
-                        if (ori.getHttpMethod().equalsIgnoreCase(httpMethod)) {
+                            || "/".equals(finalGroup)) {
+                        if (isHttpMethodsEqual) {
                             didMatchMethodType = true;
-                            if (matchContentMediaMimeTypes(ori.getConsumes(),
-                                    requestType)) {
+                            if (ori
+                                    .isMediaTypeCompatibleWithConsumes(requestType)) {
                                 didMatchRequestType = true;
-                                if (matchContentMediaMimeTypes(ori
-                                        .getProduces(), acceptType)) {
+                                if (ori
+                                        .isMediaTypeCompatibleWithProduces(acceptType)) {
                                     if (log.isDebugEnabled()) {
                                         log
-                                                .debug("Added the "
+                                                .debug("Found the "
                                                         + ori
                                                                 .getMethodToInvoke()
                                                                 .getName()
-                                                        + " method to the candidate list for the request with path: "
+                                                        + " method to be the best for the request with path: "
                                                         + path
                                                         + " HTTP method: "
                                                         + httpMethod
@@ -324,45 +371,44 @@
                                                         + typesAsString(ori
                                                                 .getProduces()));
                                     }
-                                    candidateList.put(ori, map);
+                                    bestMatchingORI = ori;
+                                    bestMatchingMapData = map;
                                 }
                             }
-                        } else if (httpMethod.equalsIgnoreCase("HEAD")
-                                && ori.getHttpMethod().equalsIgnoreCase("GET")
-                                && matchContentMediaMimeTypes(
-                                        ori.getConsumes(), requestType)
-                                && matchContentMediaMimeTypes(
-                                        ori.getProduces(), acceptType)) {
-                            candidateList.put(ori, map);
+                        } else if (isHttpMethodHead
+                                && HttpMethod.GET.equals(ori.getHttpMethod())
+                                && ori
+                                        .isMediaTypeCompatibleWithConsumes(requestType)
+                                && ori
+                                        .isMediaTypeCompatibleWithProduces(acceptType)) {
+                            bestMatchingORI = ori;
+                            bestMatchingMapData = map;
                         }
                     }
                 }
             }
-            if (!candidateList.isEmpty()) {
-                Map.Entry<OperationResourceInfo, MultivaluedMap<String, String>> firstEntry = candidateList
-                        .entrySet().iterator().next();
-                values.clear();
-                values.putAll(firstEntry.getValue());
-                OperationResourceInfo ori = firstEntry.getKey();
+            if (bestMatchingORI != null) {
+                values.putAll(bestMatchingMapData);
+                OperationResourceInfo ori = bestMatchingORI;
                 if (log.isDebugEnabled()) {
                     log.debug("Found the " + ori.getMethodToInvoke().getName()
                             + " method for the " + "request with path: " + path
                             + " and HTTP method: " + httpMethod);
                 }
+                requestTypeCache.put(acceptType, bestMatchingORI);
                 return ori;
             }
         }
 
-        if (httpMethod.equalsIgnoreCase("OPTIONS")) {
+        if ("OPTIONS".equals(httpMethod)) {
             // check to see if there is an OPTIONS method, but the request
             // did not match
-            if (resource.getMethodDispatcher().getOperationResourceInfos() != null) {
-                for (OperationResourceInfo opInfo : resource
-                        .getMethodDispatcher().getOperationResourceInfos()) {
+            if (opInfos != null) {
+                for (OperationResourceInfo opInfo : opInfos) {
 
                     // if we find an @OPTIONS annotated method, but it did not match the request,
                     // it is time to return a 406
-                    if ("OPTIONS".equalsIgnoreCase(opInfo.getHttpMethod())) {
+                    if ("OPTIONS".equals(opInfo.getHttpMethod())) {
                         throw new WebApplicationException(
                                 Response.Status.NOT_ACCEPTABLE);
                     }
@@ -383,9 +429,42 @@
                     Response.Status.UNSUPPORTED_MEDIA_TYPE);
         }
 
+        /*
+         * this is an error penalty.  the idea is that we skipped needless pattern matching for optimal pathing until we get to here.
+         */
+        boolean didMatchResource = false;
+        Set<String> possibleMethodOperations = new HashSet<String>();
+        for (OperationResourceInfo ori : opInfos) {
+
+            boolean isSubResourceLocator = ori.isSubResourceLocator();
+            if (isSubResourceLocator) {
+                continue;
+            }
+
+            String methodName = ori.getHttpMethod();
+            if (methodName == null
+                    || possibleMethodOperations.contains(methodName)) {
+                continue;
+            }
+
+            URITemplate uriTemplate = ori.getURITemplate();
+            if (uriTemplate != null) {
+                MultivaluedMap<String, String> map = uriTemplate.match(path);
+                if (map != null) {
+                    String finalGroup = map
+                            .getFirst(URITemplate.FINAL_MATCH_GROUP);
+                    if (finalGroup == null || StringUtils.isEmpty(finalGroup)
+                            || finalGroup.equals("/")) {
+                        didMatchResource = true;
+                        possibleMethodOperations.add(ori.getHttpMethod());
+                    }
+                }
+            }
+        }
+
         if (didMatchResource) {
             // but did not match request httpmethod
-            possibleMethodOperations.add("HEAD");
+            possibleMethodOperations.add(HttpMethod.HEAD);
             possibleMethodOperations.add("OPTIONS");
             ResponseBuilder respBuilder = Response.status(405);
             for (String s : possibleMethodOperations) {
@@ -410,14 +489,15 @@
         return result;
     }
 
+    final static private List<MediaType> wildcardTypeAsList = Collections
+            .singletonList(MediaType.WILDCARD_TYPE);
+
     public static List<MediaType> getConsumeTypes(Consumes cm) {
-        return cm == null ? Collections.singletonList(MediaType.WILDCARD_TYPE)
-                : getMediaTypes(cm.value());
+        return cm == null ? wildcardTypeAsList : getMediaTypes(cm.value());
     }
 
     public static List<MediaType> getProduceTypes(Produces pm) {
-        return pm == null ? Collections.singletonList(MediaType.WILDCARD_TYPE)
-                : getMediaTypes(pm.value());
+        return pm == null ? wildcardTypeAsList : getMediaTypes(pm.value());
     }
 
     public static int compareMediaTypesQValue(MediaType mt1, MediaType mt2) {
@@ -428,46 +508,50 @@
     }
 
     public static int compareMediaTypes(MediaType mt1, MediaType mt2) {
+        final boolean isMT1WildcardType = mt1.isWildcardType();
+        final boolean isMT2WildcardType = mt2.isWildcardType();
 
-        if ((!mt1.isWildcardSubtype() && !mt1.isWildcardType()
-                && !mt2.isWildcardSubtype() && !mt2.isWildcardType())
-                || (mt1.isWildcardSubtype() && mt1.isWildcardType()
-                        && mt2.isWildcardSubtype() && mt2.isWildcardType())) {
-
-            float q1 = getMediaTypeQualityFactor(mt1.getParameters().get("q"));
-            float q2 = getMediaTypeQualityFactor(mt2.getParameters().get("q"));
-            int result = Float.compare(q1, q2);
-            if (result == 0) {
-                int mt1pSize = mt1.getParameters().size();
-                int mt2pSize = mt2.getParameters().size();
-                if (mt1pSize > mt2pSize) {
-                    return -1;
-                } else if (mt1pSize < mt2pSize) {
-                    return 1;
-                } else {
-                    return 0;
-                }
-            }
-            return -result;
-        }
-
-        if (mt1.isWildcardType() && !mt2.isWildcardType()) {
+        if (isMT1WildcardType && !isMT2WildcardType) {
             return 1;
         }
-        if (!mt1.isWildcardType() && mt2.isWildcardType()) {
+
+        if (!isMT1WildcardType && isMT2WildcardType) {
             return -1;
         }
 
+        final boolean isMT1WildcardSubtype = mt1.isWildcardSubtype();
+        final boolean isMT2WildcardSubtype = mt2.isWildcardSubtype();
         if (mt1.getType().equals(mt2.getType())) {
-            if (mt1.isWildcardSubtype() && !mt2.isWildcardSubtype()) {
+            if (isMT1WildcardSubtype && !isMT2WildcardSubtype) {
                 return 1;
             }
-            if (!mt1.isWildcardSubtype() && mt2.isWildcardSubtype()) {
+            if (!isMT1WildcardSubtype && isMT2WildcardSubtype) {
                 return -1;
             }
         }
-        return mt1.toString().compareTo(mt2.toString());
 
+        final float q1 = getMediaTypeQualityFactor(mt1.getParameters().get("q"));
+        final float q2 = getMediaTypeQualityFactor(mt2.getParameters().get("q"));
+        int result = Float.compare(q1, q2);
+        if (result != 0) {
+            return -result;
+        }
+
+        final int mt1pSize = mt1.getParameters().size();
+        final int mt2pSize = mt2.getParameters().size();
+        if (mt1pSize > mt2pSize) {
+            return -1;
+        } else if (mt1pSize < mt2pSize) {
+            return 1;
+        }
+        String mt1Str = mt1.toString();
+        String mt2Str = mt2.toString();
+        if (mt1Str.length() < mt2Str.length()) {
+            return -1;
+        } else if (mt1Str.length() > mt2Str.length()) {
+            return 1;
+        }
+        return mt1.toString().compareTo(mt2.toString());
     }
 
     public static float getMediaTypeQualityFactor(final String q) {
@@ -511,14 +595,8 @@
         InputStream is = (InputStream) context
                 .getProperty(ContextConstants.REQUEST_INPUT_STREAM);
 
-        MultivaluedMap<String, String> values = (MultivaluedMap<String, String>) context
-                .getProperty(ContextConstants.TEMPLATE_VALUES);
-
-        String path = (String) context
-                .getProperty(ContextConstants.HTTP_PATH_INFO);
-
-        boolean isJAXRSParamAnnotationsFound = false;
         if (parameterAnns != null && parameterAnns.length > 0) {
+            boolean isJAXRSParamAnnotationsFound = false;
             for (Annotation ann : parameterAnns) {
                 if (AnnotationUtils
                         .isParamAnnotationClass(ann.annotationType())) {
@@ -526,19 +604,22 @@
                     break;
                 }
             }
-        }
-
-        if (isJAXRSParamAnnotationsFound) {
 
-            for (Annotation ann : parameterAnns) {
-                if (ann.annotationType().equals(Context.class)) {
-                    return createContextValue(context, parameterType,
-                            parameterClass);
+            if (isJAXRSParamAnnotationsFound) {
+                for (Annotation ann : parameterAnns) {
+                    if (ann.annotationType().equals(Context.class)) {
+                        return createContextValue(context, parameterType,
+                                parameterClass);
+                    }
                 }
-            }
 
-            return createHttpParameterValue(parameterAnns, parameterClass,
-                    parameterType, context, values, path, ori);
+                MultivaluedMap<String, String> values = (MultivaluedMap<String, String>) context
+                        .getProperty(ContextConstants.TEMPLATE_VALUES);
+                String path = (String) context
+                        .getProperty(ContextConstants.HTTP_PATH_INFO);
+                return createHttpParameterValue(parameterAnns, parameterClass,
+                        parameterType, context, values, path, ori);
+            }
         }
 
         // we can't really limit it to just PUT and POST
@@ -553,9 +634,7 @@
         }
 
         if (ori.isFormParamFound()) {
-            return new MetadataMap<String, String>(
-                    (Map<String, List<String>>) context
-                            .getProperty(ContextConstants.FORM_VALUES));
+            return context.getProperty(ContextConstants.FORM_VALUES);
         }
 
         return readFromMessageBody(parameterClass, parameterType,
@@ -659,8 +738,10 @@
      * @param message
      * @return a Map of query parameters.
      */
-
     public static MultivaluedMap<String, String> getStructuredParams(String query, String sep, boolean decode) {
+        /*
+         * this LinkedHashMap keeps the keys in order
+         */
         MultivaluedMap<String, String> queries = new MetadataMap<String, String>(
                 new LinkedHashMap<String, List<String>>());
 
@@ -704,105 +785,22 @@
             throws IOException {
 
         // OperationResourceInfo is passed for error logging reasons.  We only use the consumesTypes for real function:
-        List<MediaType> consumeTypes = ori.getConsumes();
+        List<MediaType> consumeTypes = ori
+                .getConsumesIntersectedWithMediaType(contentType);
 
-        List<MediaType> types = JAXRSUtils.intersectMimeTypes(consumeTypes,
-                contentType);
+        MediaType finalMediaType = null;
         MessageBodyReader provider = null;
-        for (MediaType type : types) {
+        for (MediaType type : consumeTypes) {
+            finalMediaType = type;
+
             provider = ProviderFactory.getInstance(context)
                     .createMessageBodyReader(targetTypeClass, parameterType,
-                            parameterAnnotations, type, context);
+                            parameterAnnotations, finalMediaType, context);
 
-            // TODO : make the exceptions
             if (provider != null) {
                 break;
             }
         }
-        MultivaluedMap<String, String> headers = new MultivaluedMap<String, String>() {
-
-            private MultivaluedMap<String, String> delegate = (MultivaluedMap<String, String>) context
-                    .getProperty(ContextConstants.HTTP_HEADER_VALUES);
-
-            public void add(String arg0, String arg1) {
-                throw new UnsupportedOperationException();
-            }
-
-            public String getFirst(String arg0) {
-                return delegate.getFirst(arg0.toLowerCase());
-            }
-
-            public void putSingle(String arg0, String arg1) {
-                throw new UnsupportedOperationException();
-            }
-
-            public void clear() {
-                throw new UnsupportedOperationException();
-            }
-
-            public boolean containsKey(Object key) {
-                if (key instanceof String) {
-                    return delegate.containsKey(((String) key).toLowerCase());
-                }
-                return delegate.containsKey(key);
-            }
-
-            public boolean containsValue(Object value) {
-                return delegate.containsValue(value);
-            }
-
-            public Set<java.util.Map.Entry<String, List<String>>> entrySet() {
-                Set<java.util.Map.Entry<String, List<String>>> ret = delegate
-                        .entrySet();
-                if (ret == null) {
-                    return null;
-                }
-                return Collections.unmodifiableSet(ret);
-            }
-
-            public List<String> get(Object key) {
-                List<String> ret = null;
-                if (key instanceof String) {
-                    ret = delegate.get(((String) key).toLowerCase());
-                } else {
-                    ret = delegate.get(key);
-                }
-
-                if (ret != null) {
-                    return Collections.unmodifiableList(ret);
-                }
-                return ret;
-            }
-
-            public boolean isEmpty() {
-                return delegate.isEmpty();
-            }
-
-            public Set<String> keySet() {
-                return delegate.keySet();
-            }
-
-            public List<String> put(String key, List<String> value) {
-                throw new UnsupportedOperationException();
-            }
-
-            public void putAll(Map<? extends String, ? extends List<String>> map) {
-                throw new UnsupportedOperationException();
-            }
-
-            public List<String> remove(Object key) {
-                throw new UnsupportedOperationException();
-            }
-
-            public int size() {
-                return delegate.size();
-            }
-
-            public Collection<List<String>> values() {
-                return delegate.values();
-            }
-
-        };
 
         if (provider != null) {
             if (log.isDebugEnabled()) {
@@ -810,8 +808,15 @@
                         + " to read from message");
             }
             try {
-                Object obj = provider.readFrom(targetTypeClass, parameterType,
-                        parameterAnnotations, contentType, headers, is);
+                Object obj = provider
+                        .readFrom(
+                                targetTypeClass,
+                                parameterType,
+                                parameterAnnotations,
+                                finalMediaType,
+                                (MultivaluedMap<String, String>) context
+                                        .getProperty(ContextConstants.HTTP_HEADER_VALUES),
+                                is);
                 return obj;
             } finally {
                 // log the input if logging enabled
@@ -828,8 +833,9 @@
         }
 
         byte[] bytes = getBytesFromStream(is);
-        RESTDataSource source = new RESTDataSource(bytes, null, contentType
-                .toString());
+        RESTDataSource source = new RESTDataSource(bytes, null,
+                (finalMediaType == null) ? MediaType.WILDCARD : finalMediaType
+                        .toString());
         DataHandler handler = new DataHandler(source);
         Object obj = handler.getContent();
 
@@ -852,7 +858,7 @@
                     (String) context.getProperty(ContextConstants.HTTP_METHOD),
                     (String) context
                             .getProperty(ContextConstants.HTTP_REQUEST_URL),
-                    ori.getClassResourceInfo().getResourceClass().getName()
+                    ori.getClassResourceInfo().getServiceClass().getName()
                             + "." + ori.getMethodToInvoke().getName(),
                     parameterType.toString(), contentType.toString()));
         }
@@ -896,18 +902,6 @@
         return inputBytes;
     }
 
-    public static boolean matchContentMediaMimeTypes(List<MediaType> oriMediaTypes, MediaType contentType) {
-        if (contentType == null) {
-            if (oriMediaTypes == null
-                    || (oriMediaTypes.isEmpty() || oriMediaTypes
-                            .contains(MediaType.WILDCARD_TYPE))) {
-                return true;
-            }
-            return false;
-        }
-        return intersectMimeTypes(oriMediaTypes, contentType).size() != 0;
-    }
-
     public static List<MediaType> parseMediaTypes(String types) {
         List<MediaType> acceptValues = new ArrayList<MediaType>();
 
@@ -938,98 +932,165 @@
      * @param userMediaTypes
      * @return return a list of intersected mime types but which has no sorted order
      */
-    public static List<MediaType> intersectMimeTypes(List<MediaType> requiredMediaTypes, List<MediaType> userMediaTypes) {
-        Set<MediaType> supportedMimeTypeList = new LinkedHashSet<MediaType>();
+    public static List<MediaType> intersectMimeTypes(List<MediaType> requiredMediaTypes, List<MediaType> userMediaTypes, boolean isQFactorChecked) {
+        List<MediaType> supportedMimeTypeList = new ArrayList<MediaType>();
+
+        List<MediaType> userMediaTypesFiltered = userMediaTypes;
+        if (isQFactorChecked) {
+            userMediaTypesFiltered = new ArrayList<MediaType>();
+            for (MediaType mt : userMediaTypes) {
+                if (!isMediaTypeQFactorEqualTo0(mt)) {
+                    userMediaTypesFiltered.add(mt);
+                }
+            }
+        }
 
         for (MediaType requiredType : requiredMediaTypes) {
-            for (MediaType userType : userMediaTypes) {
-                if (requiredType.isCompatible(userType)) {
-                    /*
-                     * TODO: should not add types where the quality parameter is 0.0
-                     */
-                    String type = requiredType.getType().equals(
-                            MediaType.MEDIA_TYPE_WILDCARD) ? userType.getType()
-                            : requiredType.getType();
-                    String subtype = requiredType.getSubtype().equals(
-                            MediaType.MEDIA_TYPE_WILDCARD) ? userType
-                            .getSubtype() : requiredType.getSubtype();
-
-                    /*
-                     * go ahead and add in the userType parameters but go back
-                     * and add in any requiredType's parameters that do not
-                     * conflict
-                     */
-                    Map<String, String> typeParams = new HashMap<String, String>(
-                            userType.getParameters());
-                    Map<String, String> requiredTypeParameters = requiredType
-                            .getParameters();
-                    for (String key : requiredTypeParameters.keySet()) {
-                        if (!typeParams.containsKey(key)) {
-                            typeParams
-                                    .put(key, requiredTypeParameters.get(key));
-                        }
+            if (!isQFactorChecked || !isMediaTypeQFactorEqualTo0(requiredType)) {
+                for (MediaType userType : userMediaTypesFiltered) {
+                    if (requiredType.isCompatible(userType)) {
+                        String type = requiredType.getType().equals(
+                                MediaType.MEDIA_TYPE_WILDCARD) ? userType
+                                .getType() : requiredType.getType();
+                        String subtype = requiredType.getSubtype().equals(
+                                MediaType.MEDIA_TYPE_WILDCARD) ? userType
+                                .getSubtype() : requiredType.getSubtype();
+                        supportedMimeTypeList.add(new MediaType(type, subtype,
+                                userType.getParameters()));
                     }
-
-                    supportedMimeTypeList.add(new MediaType(type, subtype,
-                            typeParams));
                 }
             }
         }
 
-        return new ArrayList<MediaType>(supportedMimeTypeList);
+        return supportedMimeTypeList;
     }
 
-    public static List<MediaType> intersectMimeTypes(List<MediaType> mimeTypesA, MediaType mimeTypeB) {
-        return intersectMimeTypes(mimeTypesA, Collections
-                .singletonList(mimeTypeB));
+    public static MediaType findMostSpecificCompatibleMediaType(MediaType typeGiven, List<MediaType> availableTypes) {
+        if (typeGiven == null || availableTypes == null) {
+            return null;
+        }
+        MediaType mostSpecificCompatibleType = null;
+        for (MediaType mt : availableTypes) {
+            if (typeGiven.isCompatible(mt)
+                    && isMediaTypeParametersCompatible(typeGiven, mt)) {
+                if (mostSpecificCompatibleType == null) {
+                    mostSpecificCompatibleType = mt;
+                } else if (!mt.isWildcardType()) {
+                    if (mostSpecificCompatibleType.isWildcardType()) {
+                        mostSpecificCompatibleType = mt;
+                    } else if (!mt.isWildcardSubtype()) {
+                        if (mostSpecificCompatibleType.isWildcardSubtype()) {
+                            mostSpecificCompatibleType = mt;
+                        } else {
+                            if (compareMediaTypes(mt,
+                                    mostSpecificCompatibleType) < 0) {
+                                mostSpecificCompatibleType = mt;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return mostSpecificCompatibleType;
     }
 
-    public static List<MediaType> intersectMimeTypes(String mimeTypesA, String mimeTypesB) {
-        return intersectMimeTypes(parseMediaTypes(mimeTypesA),
-                parseMediaTypes(mimeTypesB));
+    /**
+     * Compares the two media types parameters.  If there's a collision across the two, then return false, otherwise ignore extra ones.
+     * @param typeGiven
+     * @param typeChecked
+     * @return
+     */
+    private static boolean isMediaTypeParametersCompatible(MediaType typeGiven, MediaType typeChecked) {
+        Map<String, String> typeCheckedParams = typeGiven.getParameters();
+        Map<String, String> typeGivenParams = typeGiven.getParameters();
+
+        if (typeGivenParams.isEmpty() || typeCheckedParams.isEmpty()) {
+            return true;
+        }
+
+        for (String s : typeGivenParams.keySet()) {
+            String typeCheckedParamValue = typeCheckedParams.get(s);
+            if (typeCheckedParamValue == null) {
+                continue;
+            }
+            String typeGivenParamValue = typeGivenParams.get(s);
+            if (!typeGivenParamValue.equals(typeCheckedParamValue)) {
+                return false;
+            }
+        }
+
+        return true;
     }
 
-    public static List<MediaType> sortMediaTypes(String mediaTypes) {
-        return sortMediaTypes(JAXRSUtils.parseMediaTypes(mediaTypes));
+    public static boolean isMediaTypeInList(List<MediaType> mimeTypesA, MediaType mimeTypeB, boolean isQFactorChecked) {
+        if (isQFactorChecked && isMediaTypeQFactorEqualTo0(mimeTypeB)) {
+            return false;
+        }
+
+        for (int c = mimeTypesA.size() - 1; c > -1; --c) {
+            MediaType requiredType = mimeTypesA.get(c);
+            if (requiredType.isCompatible(mimeTypeB)) {
+                if (!isQFactorChecked
+                        || !isMediaTypeQFactorEqualTo0(requiredType)) {
+                    return true;
+                }
+            }
+        }
+        return false;
     }
 
-    public static List<MediaType> sortMediaTypesQValue(String mediaTypes) {
-        return sortMediaTypesQValue(JAXRSUtils.parseMediaTypes(mediaTypes));
+    private static boolean isMediaTypeQFactorEqualTo0(MediaType mt) {
+        Map<String, String> params = mt.getParameters();
+        String qstr = params.get("q");
+        if (qstr != null) {
+            try {
+                double q = Double.parseDouble(qstr);
+                if (q == 0.0) {
+                    return true;
+                }
+            } catch (NumberFormatException e) {
+                /* ignore */
+            }
+        }
+        return false;
     }
 
     public static List<MediaType> sortMediaTypes(List<MediaType> types) {
         if (types.size() > 1) {
-            Collections.sort(types, new Comparator<MediaType>() {
+            Collections.sort(types, mediaTypeComparator);
+        }
+        return types;
+    }
 
-                public int compare(MediaType mt1, MediaType mt2) {
-                    return JAXRSUtils.compareMediaTypes(mt1, mt2);
-                }
+    final private static MediaTypeComparator mediaTypeComparator = new MediaTypeComparator();
 
-            });
+    final private static class MediaTypeComparator implements Comparator<MediaType> {
+        private MediaTypeComparator() {
+            /* do nothing */
+        }
+
+        public int compare(MediaType mt1, MediaType mt2) {
+            return JAXRSUtils.compareMediaTypes(mt1, mt2);
         }
-        return types;
     }
 
     public static List<MediaType> sortMediaTypesQValue(List<MediaType> types) {
         if (types.size() > 1) {
-            Collections.sort(types, new Comparator<MediaType>() {
-
-                public int compare(MediaType mt1, MediaType mt2) {
-                    return JAXRSUtils.compareMediaTypesQValue(mt1, mt2);
-                }
-
-            });
+            Collections.sort(types, mediaTypeQValueComparator);
         }
         return types;
     }
 
-    private static <K, V> MultivaluedMap<K, V> cloneMap(MultivaluedMap<K, V> map1) {
+    final private static MediaTypeQValueComparator mediaTypeQValueComparator = new MediaTypeQValueComparator();
+
+    final private static class MediaTypeQValueComparator implements Comparator<MediaType> {
+        private MediaTypeQValueComparator() {
+            /* do nothing */
+        }
 
-        MultivaluedMap<K, V> map2 = new MetadataMap<K, V>();
-        for (Map.Entry<K, List<V>> entry : map1.entrySet()) {
-            map2.put(entry.getKey(), new ArrayList<V>(entry.getValue()));
+        public int compare(MediaType mt1, MediaType mt2) {
+            return JAXRSUtils.compareMediaTypesQValue(mt1, mt2);
         }
-        return map2;
     }
 
     /**
@@ -1050,22 +1111,16 @@
         }
 
         // grab the needed objects
-        Object responseObj = context
-                .getProperty(ContextConstants.INVOCATION_RESULT);
-        OperationResourceInfo operation = (OperationResourceInfo) context
-                .getProperty(ContextConstants.OPERATION_RESOURCE);
-        List<MediaType> acceptContentTypes = (List<MediaType>) context
-                .getProperty(ContextConstants.ACCEPT_CONTENT_TYPES);
+        Object responseObj = null;
 
         Response response = (Response) context
                 .getProperty(ContextConstants.RESPONSE);
 
-        ContentMonitor monitor = (ContentMonitor) context
-                .getProperty(ContextConstants.CONTENT_MONITOR);
-
         // in some cases, such as error flows, the response may already have been
         // built and set on the RESTContext
         if (response == null) {
+            responseObj = context
+                    .getProperty(ContextConstants.INVOCATION_RESULT);
             if (responseObj instanceof Response) {
                 response = (Response) responseObj;
             } else if (responseObj == null) {
@@ -1073,16 +1128,9 @@
             } else {
                 response = Response.ok(responseObj).build();
             }
+            context.setProperty(ContextConstants.RESPONSE, response);
         }
 
-        String path = (String) context
-                .getProperty(ContextConstants.HTTP_PATH_INFO);
-        String httpMethod = (String) context
-                .getProperty(ContextConstants.HTTP_METHOD);
-
-        String contentType = (String) response.getMetadata().getFirst(
-                HttpHeaders.CONTENT_TYPE);
-        context.setProperty(ContextConstants.RESPONSE, response);
         context.setProperty(ContextConstants.HTTP_HEADER_VALUES, response
                 .getMetadata());
         OutputStream os = (OutputStream) context
@@ -1108,6 +1156,12 @@
             return;
         }
 
+        OperationResourceInfo operation = (OperationResourceInfo) context
+                .getProperty(ContextConstants.OPERATION_RESOURCE);
+        String contentType = (String) response.getMetadata().getFirst(
+                HttpHeaders.CONTENT_TYPE);
+        List<MediaType> acceptContentTypes = (List<MediaType>) context
+                .getProperty(ContextConstants.ACCEPT_CONTENT_TYPES);
         List<MediaType> availableContentTypes = computeAvailableContentTypes(
                 contentType, response, operation, acceptContentTypes);
 
@@ -1116,13 +1170,13 @@
         // that to the content type if it is present, otherwise, the */* type
         // becomes the content type
         if (availableContentTypes == null || availableContentTypes.isEmpty()) {
-
-            if ("OPTIONS".equalsIgnoreCase(httpMethod)) {
+            String httpMethod = (String) context
+                    .getProperty(ContextConstants.HTTP_METHOD);
+            if ("OPTIONS".equals(httpMethod)) {
                 if (acceptContentTypes != null && !acceptContentTypes.isEmpty()) {
                     availableContentTypes = acceptContentTypes;
                 } else {
-                    availableContentTypes = new ArrayList<MediaType>();
-                    availableContentTypes.add(MediaType.WILDCARD_TYPE);
+                    availableContentTypes = wildcardTypeAsList;
                 }
             }
         }
@@ -1152,60 +1206,69 @@
         MediaType responseType = null;
 
         boolean written = false;
-        try {
-            for (MediaType type : availableContentTypes) {
-                writer = ProviderFactory.getInstance(context)
-                        .createMessageBodyWriter(
-                                targetType,
-                                genericType,
-                                invoked != null ? invoked.getAnnotations()
-                                        : new Annotation[] {}, type, context);
-
-                if (writer != null) {
-                    responseType = (MediaType) context
-                            .getProperty(ContextConstants.RESPONSE_CONTENT_TYPE);
-                    break;
+        if (availableContentTypes != null) {
+            try {
+                for (MediaType type : availableContentTypes) {
+                    writer = ProviderFactory.getInstance(context)
+                            .createMessageBodyWriter(
+                                    targetType,
+                                    genericType,
+                                    invoked != null ? invoked.getAnnotations()
+                                            : new Annotation[] {}, type,
+                                    context);
+
+                    if (writer != null) {
+                        responseType = (MediaType) context
+                                .getProperty(ContextConstants.RESPONSE_CONTENT_TYPE);
+                        break;
+                    }
                 }
-            }
 
-            if (writer != null) {
-                responseType = checkFinalContentType(responseType);
-                responseWriter.writeWithEntityProvider(context, writer,
-                        objToInvokeWriterWith, targetType, genericType,
-                        (invoked != null ? invoked.getAnnotations()
-                                : new Annotation[] {}), responseType, response
-                                .getMetadata(), os);
-                written = true;
-            }
-            // if we could not find a MessageBodyWriter via JAF, let's find a
-            // DataHandler via the JAF
-            else if (!written) {
-                for (MediaType type : availableContentTypes) {
-                    DataContentHandler dch = CommandMap.getDefaultCommandMap()
-                            .createDataContentHandler(type.toString());
-                    if (dch != null) {
-                        if (log.isDebugEnabled()) {
-                            log
-                                    .debug("Writing application response with DataHandler for mimeType: "
-                                            + type.toString());
+                if (writer != null) {
+                    responseType = checkFinalContentType(responseType);
+                    responseWriter.writeWithEntityProvider(context, writer,
+                            objToInvokeWriterWith, targetType, genericType,
+                            (invoked != null ? invoked.getAnnotations()
+                                    : new Annotation[] {}), responseType,
+                            response.getMetadata(), os);
+                    written = true;
+                }
+                // if we could not find a MessageBodyWriter via JAF, let's find a
+                // DataHandler via the JAF
+                else {
+                    for (MediaType type : availableContentTypes) {
+                        DataContentHandler dch = CommandMap
+                                .getDefaultCommandMap()
+                                .createDataContentHandler(type.toString());
+                        if (dch != null) {
+                            if (log.isDebugEnabled()) {
+                                log
+                                        .debug("Writing application response with DataHandler for mimeType: "
+                                                + type.toString());
+                            }
+                            responseWriter.writeWithDataHandler(context,
+                                    responseObj, type.toString(), dch, os);
+                            written = true;
+                            break;
                         }
-                        responseWriter.writeWithDataHandler(context,
-                                responseObj, type.toString(), dch, os);
-                        written = true;
-                        break;
                     }
                 }
+            } catch (Throwable t) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Throwable caught during processResponse: " + t,
+                            t);
+                }
+                written = processWriteException(context, t);
             }
-        } catch (Throwable t) {
-            if (log.isDebugEnabled()) {
-                log.debug("Throwable caught during processResponse: " + t, t);
-            }
-            written = processWriteException(context, t);
         }
 
         if (!written) {
             // give as much info in the log as possible so app developer knows what needs to be implemented
             String invokedString = getMethodInfoForErrorLog(invoked);
+            String path = (String) context
+                    .getProperty(ContextConstants.HTTP_PATH_INFO);
+            String httpMethod = (String) context
+                    .getProperty(ContextConstants.HTTP_METHOD);
             log.error(Messages.getMessage("writerNotFound", httpMethod, path,
                     invokedString, targetType.getName()));
             context.setProperty(ContextConstants.RESPONSE, Response.status(
@@ -1213,15 +1276,6 @@
             processResponse(context);
         }
 
-        // let's try to set the content length of the response
-        if (monitor != null) {
-            Integer contentLength = monitor.getContentLength();
-            if (log.isDebugEnabled()) {
-                log.debug("Setting response content length: " + contentLength);
-            }
-            context.setProperty(ContextConstants.RESPONSE_CONTENT_LENGTH,
-                    contentLength);
-        }
         responseWriter.postWrite(context);
     }
 
@@ -1318,34 +1372,46 @@
      * @return a list of media types that are acceptable
      */
     public static List<MediaType> computeAvailableContentTypes(String contentType, Response response, OperationResourceInfo operation, List<MediaType> acceptContentTypes) {
-        List<MediaType> produceTypes = null;
-        List<MediaType> operationProduces = (operation != null) ? operation
-                .getProduces() : null;
         if (contentType != null) {
             return Collections.singletonList(MediaType.valueOf(contentType
                     .toString()));
-        } else if (operationProduces != null) {
-            produceTypes = operationProduces;
-        } else {
-            produceTypes = Collections.singletonList(MediaType.WILDCARD_TYPE);
         }
+
         List<MediaType> acceptTypes = acceptContentTypes;
         if (acceptTypes == null) {
-            acceptTypes = Collections.singletonList(MediaType.WILDCARD_TYPE);
+            acceptTypes = wildcardTypeAsList;
         }
-        return JAXRSUtils.intersectMimeTypes(acceptTypes, produceTypes);
 
+        if (operation == null) {
+            return JAXRSUtils.sortMediaTypesQValue(JAXRSUtils
+                    .intersectMimeTypes(wildcardTypeAsList, acceptTypes, true));
+        }
+
+        if (acceptTypes.size() == 1) {
+            /*
+             * don't need to sort since it's already in the best order
+             */
+            return operation.getProducesIntersectedWithMediaType(acceptTypes
+                    .get(0));
+        }
+        List<MediaType> returnAccumulator = new ArrayList<MediaType>();
+        for (MediaType mt : acceptTypes) {
+            returnAccumulator.addAll(operation
+                    .getProducesIntersectedWithMediaType(mt));
+        }
+        return JAXRSUtils.sortMediaTypesQValue(returnAccumulator);
     }
 
     public static MediaType checkFinalContentType(MediaType mt) {
-        if (mt.isWildcardType() && mt.isWildcardSubtype()) {
-            return MediaType.APPLICATION_OCTET_STREAM_TYPE;
-        } else if ("application".equals(mt.getType())
-                && "*".equals(mt.getSubtype())) {
-            return MediaType.APPLICATION_OCTET_STREAM_TYPE;
-        } else {
-            return mt;
+        boolean isWildCardSubType = mt.isWildcardSubtype();
+        if (isWildCardSubType) {
+            if (mt.isWildcardType()) {
+                return MediaType.APPLICATION_OCTET_STREAM_TYPE;
+            } else if ("application".equals(mt.getType())) {
+                return MediaType.APPLICATION_OCTET_STREAM_TYPE;
+            }
         }
+        return mt;
     }
 
     /**
@@ -1353,19 +1419,18 @@
      * looking at all the subresources on the ClassResourceInfo list supplied.
      *
      */
-    public static ClassResourceInfo getSubResourceInfo(String className, List<ClassResourceInfo> classInfoList) {
+    public static ClassResourceInfo getSubResourceInfo(Object subresourceInstance, ClassResourceInfo classInfo) {
         ClassResourceInfo targetInfo = null;
-        for (ClassResourceInfo classInfo : classInfoList) {
-            List<ClassResourceInfo> subInfoList = classInfo
-                    .getSubClassResourceInfo();
-            if (subInfoList != null) {
-                for (ClassResourceInfo subResource : subInfoList) {
-                    if (subResource.getServiceClass().getName().equals(
-                            className)) {
-                        targetInfo = subResource;
-                        break;
-                    }
-                }
+        if (classInfo != null) {
+            targetInfo = classInfo.getSubClassResourceInfo(subresourceInstance
+                    .getClass().getName());
+        }
+
+        if (targetInfo == null) {
+            targetInfo = ReflectiveJAXRSInfoBuilder.processResourceClass(
+                    subresourceInstance.getClass(), null, null, false);
+            if (classInfo != null) {
+                classInfo.addSubClassResourceInfo(targetInfo);
             }
         }
         return targetInfo;
@@ -1502,5 +1567,4 @@
         }
         return methodSignatureString;
     }
-
 }

Propchange: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
------------------------------------------------------------------------------
    svn:executable = *

Copied: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/utils/URITemplateComparator.java (from r788296, incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/core/CaseInsensitiveComparator.java)
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/utils/URITemplateComparator.java?p2=incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/utils/URITemplateComparator.java&p1=incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/core/CaseInsensitiveComparator.java&r1=788296&r2=788908&rev=788908&view=diff
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/core/CaseInsensitiveComparator.java (original)
+++ incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/utils/URITemplateComparator.java Sat Jun 27 00:02:26 2009
@@ -17,27 +17,35 @@
  * under the License.
  */
 
-package com.ibm.ws.jaxrs.core;
+package org.apache.cxf.jaxrs.utils;
 
 import java.util.Comparator;
 
+import org.apache.cxf.jaxrs.model.URITemplate;
+
 /**
- * This is a comparator used to compare String objects in a
- * case-insensitive manner. This is helpful when providing
- * user access to the HTTP request headers via the HttpHeaders
- * interface.
  *
  */
-public class CaseInsensitiveComparator implements Comparator<String> {
+public class URITemplateComparator implements Comparator<URITemplate> {
 
-    public int compare(String object1, String object2) {
-        if (object1 != null && object2 != null) {
-            return object1.compareToIgnoreCase(object2);
-        } else if (object1 != null) {
-            return 1;
-        } else {
-            return -1;
-        }
+    final private static URITemplateComparator comparator = new URITemplateComparator();
+
+    public static URITemplateComparator getInstance() {
+        return comparator;
     }
 
+    public int compare(URITemplate cr1, URITemplate cr2) {
+
+        String l1 = cr1.getLiteralChars();
+        String l2 = cr2.getLiteralChars();
+        if (!l1.equals(l2)) {
+            // descending order
+            return l1.length() < l2.length() ? 1 : -1;
+        }
+
+        int g1 = cr1.getNumberOfGroups();
+        int g2 = cr2.getNumberOfGroups();
+        // descending order
+        return g1 < g2 ? 1 : g1 > g2 ? -1 : 0;
+    }
 }

Propchange: incubator/wink/contrib/ibm-jaxrs/src/org/apache/cxf/jaxrs/utils/URITemplateComparator.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/wink/contrib/ibm-jaxrs/tests/test-resources/1040_2007.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/test-resources/1040_2007.xml?rev=788908&r1=788907&r2=788908&view=diff
==============================================================================
    (empty)

Propchange: incubator/wink/contrib/ibm-jaxrs/tests/test-resources/1040_2007.xml
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/wink/contrib/ibm-jaxrs/tests/test-resources/1040_2008.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/test-resources/1040_2008.xml?rev=788908&r1=788907&r2=788908&view=diff
==============================================================================
    (empty)

Propchange: incubator/wink/contrib/ibm-jaxrs/tests/test-resources/1040_2008.xml
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/wink/contrib/ibm-jaxrs/tests/test-resources/modelddtests/league/ibm-jaxrs.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/test-resources/modelddtests/league/ibm-jaxrs.xml?rev=788908&r1=788907&r2=788908&view=diff
==============================================================================
    (empty)

Propchange: incubator/wink/contrib/ibm-jaxrs/tests/test-resources/modelddtests/league/ibm-jaxrs.xml
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/wink/contrib/ibm-jaxrs/tests/test-resources/modelddtests/newsstory/ibm-jaxrs.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/test-resources/modelddtests/newsstory/ibm-jaxrs.xml?rev=788908&r1=788907&r2=788908&view=diff
==============================================================================
    (empty)

Propchange: incubator/wink/contrib/ibm-jaxrs/tests/test-resources/modelddtests/newsstory/ibm-jaxrs.xml
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/wink/contrib/ibm-jaxrs/tests/test-resources/modelddtests_merge/league/ibm-jaxrs.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/test-resources/modelddtests_merge/league/ibm-jaxrs.xml?rev=788908&r1=788907&r2=788908&view=diff
==============================================================================
    (empty)

Propchange: incubator/wink/contrib/ibm-jaxrs/tests/test-resources/modelddtests_merge/league/ibm-jaxrs.xml
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/wink/contrib/ibm-jaxrs/tests/test-resources/modelddtests_merge/newsstory/ibm-jaxrs.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/test-resources/modelddtests_merge/newsstory/ibm-jaxrs.xml?rev=788908&r1=788907&r2=788908&view=diff
==============================================================================
    (empty)

Propchange: incubator/wink/contrib/ibm-jaxrs/tests/test-resources/modelddtests_merge/newsstory/ibm-jaxrs.xml
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/wink/contrib/ibm-jaxrs/tests/test-resources/phonebook/ibm-jaxrs.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/test-resources/phonebook/ibm-jaxrs.xml?rev=788908&r1=788907&r2=788908&view=diff
==============================================================================
    (empty)

Propchange: incubator/wink/contrib/ibm-jaxrs/tests/test-resources/phonebook/ibm-jaxrs.xml
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/rest/test/utils/TestUtils.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/rest/test/utils/TestUtils.java?rev=788908&r1=788907&r2=788908&view=diff
==============================================================================
    (empty)

Propchange: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/rest/test/utils/TestUtils.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/annotations/AnnotationTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/annotations/AnnotationTests.java?rev=788908&r1=788907&r2=788908&view=diff
==============================================================================
    (empty)

Propchange: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/annotations/AnnotationTests.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/annotations/LaborApplication.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/annotations/LaborApplication.java?rev=788908&r1=788907&r2=788908&view=diff
==============================================================================
    (empty)

Propchange: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/annotations/LaborApplication.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/context/RESTContextFactoryTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/context/RESTContextFactoryTests.java?rev=788908&r1=788907&r2=788908&view=diff
==============================================================================
    (empty)

Propchange: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/context/RESTContextFactoryTests.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/core/HttpHeadersTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/core/HttpHeadersTests.java?rev=788908&r1=788907&r2=788908&view=diff
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/core/HttpHeadersTests.java (original)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/core/HttpHeadersTests.java Sat Jun 27 00:02:26 2009
@@ -37,6 +37,7 @@
 
 import com.ibm.ws.jaxrs.context.ContextConstants;
 import com.ibm.ws.jaxrs.context.RESTContext;
+import com.ibm.ws.jaxrs.context.RESTContextImpl;
 import com.ibm.ws.jaxrs.web.ServletTestFramework;
 import com.ibm.ws.jaxrs.web.mock.LocaleEnumeration;
 import com.ibm.ws.jaxrs.web.mock.ServletRequest;
@@ -51,14 +52,14 @@
     public void testGetAcceptableLanguages() throws Exception {
         String url = "http://localhost:7070/resources/someresource";
         MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
-        RESTContext context = new RESTContext();
         Enumeration localeEnumeration = getLocaleEnumeration("da", "en",
                 "en-gb");
         Map<String, Object> props = new HashMap<String, Object>();
         props.put(ServletRequest.LOCALES, localeEnumeration);
         ServletRequest request = new ServletRequest(url, null, props);
         ServletResponse response = new ServletResponse(new StringWriter());
-        ServletTestFramework.initContext(request, response, context);
+        RESTContext context = ServletTestFramework.initContext(request,
+                response);
         context.setProperty(ContextConstants.SERVLET_REQUEST, request);
         context.setProperty(ContextConstants.HTTP_HEADER_VALUES, headers);
         HttpHeaders httpHeaders = new HttpHeadersImpl(context);
@@ -78,13 +79,12 @@
 
         // try slightly different ordering
         headers = new MetadataMap<String, String>();
-        context = new RESTContext();
         localeEnumeration = getLocaleEnumeration("en-gb", "da", "en");
         props = new HashMap<String, Object>();
         props.put(ServletRequest.LOCALES, localeEnumeration);
         request = new ServletRequest(url, null, props);
         response = new ServletResponse(new StringWriter());
-        ServletTestFramework.initContext(request, response, context);
+        context = ServletTestFramework.initContext(request, response);
         context.setProperty(ContextConstants.SERVLET_REQUEST, request);
         context.setProperty(ContextConstants.HTTP_HEADER_VALUES, headers);
         httpHeaders = new HttpHeadersImpl(context);
@@ -106,12 +106,12 @@
     public void testGetAcceptableLanguagesWithLocale() throws Exception {
         String url = "http://localhost:7070/resources/someresource";
         MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
-        RESTContext context = new RESTContext();
         Map<String, Object> props = new HashMap<String, Object>();
         props.put(ServletRequest.LOCALE, new Locale("en-us"));
         ServletRequest request = new ServletRequest(url, null, props);
         ServletResponse response = new ServletResponse(new StringWriter());
-        ServletTestFramework.initContext(request, response, context);
+        RESTContext context = ServletTestFramework.initContext(request,
+                response);
         context.setProperty(ContextConstants.SERVLET_REQUEST, request);
         context.setProperty(ContextConstants.HTTP_HEADER_VALUES, headers);
         HttpHeaders httpHeaders = new HttpHeadersImpl(context);
@@ -123,7 +123,7 @@
 
     public void testGetAcceptableMediaTypes() throws Exception {
         MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
-        RESTContext context = new RESTContext();
+        RESTContext context = new RESTContextImpl();
         Map<String, Object> props = new HashMap<String, Object>();
         ServletRequest request = new ServletRequest(props);
         context.setProperty(ContextConstants.SERVLET_REQUEST, request);
@@ -142,7 +142,7 @@
 
         // now let's try with some wildcards
         headers = new MetadataMap<String, String>();
-        context = new RESTContext();
+        context = new RESTContextImpl();
         props = new HashMap<String, Object>();
         request = new ServletRequest(props);
         context.setProperty(ContextConstants.SERVLET_REQUEST, request);
@@ -161,7 +161,7 @@
 
         // another wildcard test
         headers = new MetadataMap<String, String>();
-        context = new RESTContext();
+        context = new RESTContextImpl();
         props = new HashMap<String, Object>();
         request = new ServletRequest(props);
         context.setProperty(ContextConstants.SERVLET_REQUEST, request);
@@ -182,12 +182,12 @@
     public void testGetAcceptableMediaTypesWithAccept() throws Exception {
         String url = "http://localhost:7070/resources/someresource";
         MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
-        RESTContext context = new RESTContext();
         Map<String, Object> props = new HashMap<String, Object>();
         props.put(ServletRequest.CONTENT_TYPE, "text/html");
         ServletRequest request = new ServletRequest(url, null, props);
         ServletResponse response = new ServletResponse(new StringWriter());
-        ServletTestFramework.initContext(request, response, context);
+        RESTContext context = ServletTestFramework.initContext(request,
+                response);
         context.setProperty(ContextConstants.SERVLET_REQUEST, request);
         context.setProperty(ContextConstants.HTTP_HEADER_VALUES, headers);
         HttpHeaders httpHeaders = new HttpHeadersImpl(context);
@@ -198,7 +198,7 @@
 
     public void testGetCookies() throws Exception {
         MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
-        RESTContext context = new RESTContext();
+        RESTContext context = new RESTContextImpl();
         javax.ws.rs.core.Cookie cookie1 = new javax.ws.rs.core.Cookie(
                 "myCookie1", "myCookieValue1");
         javax.ws.rs.core.Cookie cookie2 = new javax.ws.rs.core.Cookie(
@@ -226,11 +226,11 @@
 
     public void testGetLanguage() throws Exception {
         String url = "http://localhost:7070/resources/someresource";
-        RESTContext context = new RESTContext();
         Map<String, Object> props = new HashMap<String, Object>();
         ServletRequest request = new ServletRequest(url, null, props);
         ServletResponse response = new ServletResponse(new StringWriter());
-        ServletTestFramework.initContext(request, response, context);
+        RESTContext context = ServletTestFramework.initContext(request,
+                response);
         context.setProperty(ContextConstants.SERVLET_REQUEST, request);
         context.setProperty(ContextConstants.CONTENT_LANGUAGE, "en");
         HttpHeaders httpHeaders = new HttpHeadersImpl(context);
@@ -241,7 +241,7 @@
         props.put(ServletRequest.LOCALE, null);
         request = new ServletRequest(url, null, props);
         response = new ServletResponse(new StringWriter());
-        ServletTestFramework.initContext(request, response, context);
+        context = ServletTestFramework.initContext(request, response);
         context.setProperty(ContextConstants.SERVLET_REQUEST, request);
         httpHeaders = new HttpHeadersImpl(context);
         lang = httpHeaders.getLanguage();
@@ -250,7 +250,7 @@
 
     public void testGetMediaType() {
         MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
-        RESTContext context = new RESTContext();
+        RESTContext context = new RESTContextImpl();
         Map<String, Object> props = new HashMap<String, Object>();
         ServletRequest request = new ServletRequest(props);
         context.setProperty(ContextConstants.SERVLET_REQUEST, request);
@@ -271,8 +271,10 @@
     }
 
     public void testGetRequestHeader() {
-        MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
-        RESTContext context = new RESTContext();
+        MultivaluedMap<String, String> headers = new MetadataMap<String, String>(
+                new HashMap<String, List<String>>(),
+                new CaseInsensitiveComparator());
+        RESTContext context = new RESTContextImpl();
         Map<String, Object> props = new HashMap<String, Object>();
         ServletRequest request = new ServletRequest(props);
         context.setProperty(ContextConstants.SERVLET_REQUEST, request);
@@ -287,7 +289,7 @@
 
     public void testGetRequestHeaders() {
         MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
-        RESTContext context = new RESTContext();
+        RESTContext context = new RESTContextImpl();
         headers.add("SomeCustomHeader1", "SomeCustomValue1");
         headers.add("SomeCustomHeader1", "SomeCustomValue1a");
         headers.add("SomeCustomHeader1", "SomeCustomValue1b");

Propchange: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/core/HttpHeadersTests.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/core/RequestTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/core/RequestTests.java?rev=788908&r1=788907&r2=788908&view=diff
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/core/RequestTests.java (original)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/core/RequestTests.java Sat Jun 27 00:02:26 2009
@@ -43,6 +43,7 @@
 
 import com.ibm.ws.jaxrs.context.ContextConstants;
 import com.ibm.ws.jaxrs.context.RESTContext;
+import com.ibm.ws.jaxrs.context.RESTContextImpl;
 import com.ibm.ws.jaxrs.web.ServletTestFramework;
 import com.ibm.ws.jaxrs.web.mock.ServletRequest;
 import com.ibm.ws.jaxrs.web.mock.ServletResponse;
@@ -55,15 +56,20 @@
 public class RequestTests extends TestCase {
 
     public void testLastModifiedPreconditionDate() throws Exception {
-        RESTContext context = new RESTContext();
-        MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
+        RESTContext context = new RESTContextImpl();
+        MultivaluedMap<String, String> headers = new MetadataMap<String, String>(
+                new HashMap<String, List<String>>(),
+                new CaseInsensitiveComparator());
         Map<String, Object> properties = new HashMap<String, Object>();
 
         // test when everything is okay that we get null
         Calendar calendar = Calendar.getInstance();
         Date compareDate = DateHandler.getCurrentDate("America/Austin");
+        compareDate = new Date(
+                (compareDate.getTime() - (compareDate.getTime() % 1000)));
         headers.putSingle("If-Modified-Since".toLowerCase(), DateHandler
-                .formatDateInRFC1123Format(compareDate));
+                .formatDateInRFC1123Format(new Date(
+                        compareDate.getTime() - 1000)));
         ServletRequest servletRequest = new ServletRequest(properties);
         context.setProperty(ContextConstants.HTTP_HEADER_VALUES, headers);
         context.setProperty(ContextConstants.SERVLET_REQUEST, servletRequest);
@@ -94,8 +100,10 @@
     }
 
     public void testLastModifiedPreconditionETag() throws Exception {
-        RESTContext context = new RESTContext();
-        MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
+        RESTContext context = new RESTContextImpl();
+        MultivaluedMap<String, String> headers = new MetadataMap<String, String>(
+                new HashMap<String, List<String>>(),
+                new CaseInsensitiveComparator());
         Map<String, Object> properties = new HashMap<String, Object>();
         headers.putSingle("If-Match".toLowerCase(), "\"testerId\"");
 
@@ -125,8 +133,10 @@
     }
 
     public void testLastModifiedPreconditionETagAndDate() throws Exception {
-        RESTContext context = new RESTContext();
-        MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
+        RESTContext context = new RESTContextImpl();
+        MultivaluedMap<String, String> headers = new MetadataMap<String, String>(
+                new HashMap<String, List<String>>(),
+                new CaseInsensitiveComparator());
         Map<String, Object> properties = new HashMap<String, Object>();
         headers.putSingle("If-Match".toLowerCase(), "\"testerId\"");
 
@@ -134,7 +144,8 @@
         Calendar calendar = Calendar.getInstance();
         Date compareDate = calendar.getTime();
         headers.putSingle("If-Modified-Since".toLowerCase(), DateHandler
-                .formatDateInRFC1123Format(compareDate));
+                .formatDateInRFC1123Format(new Date(
+                        compareDate.getTime() - 1000)));
         EntityTag compareTag = new EntityTag("testerId");
         ServletRequest servletRequest = new ServletRequest(properties);
         context.setProperty(ContextConstants.HTTP_HEADER_VALUES, headers);
@@ -161,7 +172,8 @@
         // now let's mess up the EntityTag
         compareDate = calendar.getTime();
         headers.putSingle("If-Modified-Since".toLowerCase(), DateHandler
-                .formatDateInRFC1123Format(compareDate));
+                .formatDateInRFC1123Format(new Date(
+                        compareDate.getTime() - 1000)));
         compareTag = new EntityTag("userId");
         servletRequest = new ServletRequest(properties);
         context.setProperty(ContextConstants.HTTP_HEADER_VALUES, headers);
@@ -179,7 +191,6 @@
     }
 
     public void testGetMethod() throws Exception {
-        RESTContext context = new RESTContext();
         String url = "http://localhost:7070/resource/someresource";
         Map<String, List<String>> headers = new HashMap<String, List<String>>();
         Map<String, Object> properties = new HashMap<String, Object>();
@@ -188,7 +199,8 @@
         ServletRequest servletRequest = new ServletRequest(url, null,
                 properties);
         ServletResponse response = new ServletResponse(new StringWriter());
-        ServletTestFramework.initContext(servletRequest, response, context);
+        RESTContext context = ServletTestFramework.initContext(servletRequest,
+                response);
         context.setProperty(ContextConstants.SERVLET_REQUEST, servletRequest);
         Request request = new RequestImpl(context);
 
@@ -233,8 +245,9 @@
      */
     public void testSelectVariantSingle() throws Exception {
         String url = "http://localhost:7070/resource/someresource";
-        RESTContext context = new RESTContext();
-        MultivaluedMap<String, String> mValuedHeaders = new MetadataMap<String, String>();
+        MultivaluedMap<String, String> mValuedHeaders = new MetadataMap<String, String>(
+                new HashMap<String, List<String>>(),
+                new CaseInsensitiveComparator());
         mValuedHeaders.putSingle("Accept".toLowerCase(), "text/xml");
         mValuedHeaders.putSingle("Accept-Language".toLowerCase(), "en");
         mValuedHeaders.putSingle("Accept-Charset".toLowerCase(), "chunked");
@@ -242,7 +255,8 @@
         ServletRequest servletRequest = new ServletRequest(url, null,
                 properties);
         ServletResponse response = new ServletResponse(new StringWriter());
-        ServletTestFramework.initContext(servletRequest, response, context);
+        RESTContext context = ServletTestFramework.initContext(servletRequest,
+                response);
         context.setProperty(ContextConstants.SERVLET_REQUEST, servletRequest);
         context
                 .setProperty(ContextConstants.HTTP_HEADER_VALUES,
@@ -276,7 +290,6 @@
      */
     public void testSelectVariantMulti() throws Exception {
         String url = "http://localhost:7070/resource/someresource";
-        RESTContext context = new RESTContext();
         MultivaluedMap<String, String> mValuedHeaders = new MetadataMap<String, String>();
         Map<String, Object> properties = new HashMap<String, Object>();
         Map<String, List<String>> headers = new HashMap<String, List<String>>();
@@ -294,7 +307,8 @@
         ServletRequest servletRequest = new ServletRequest(url, null,
                 properties);
         ServletResponse response = new ServletResponse(new StringWriter());
-        ServletTestFramework.initContext(servletRequest, response, context);
+        RESTContext context = ServletTestFramework.initContext(servletRequest,
+                response);
         context.setProperty(ContextConstants.SERVLET_REQUEST, servletRequest);
         List<MediaType> acceptedContentTypes = new ArrayList<MediaType>();
         acceptedContentTypes.add(new MediaType("text", "xml"));
@@ -341,7 +355,7 @@
         properties.put(ServletRequest.HTTP_HEADERS, headers);
         servletRequest = new ServletRequest(url, null, properties);
         response = new ServletResponse(new StringWriter());
-        ServletTestFramework.initContext(servletRequest, response, context);
+        context = ServletTestFramework.initContext(servletRequest, response);
         context.setProperty(ContextConstants.SERVLET_REQUEST, servletRequest);
         acceptedContentTypes = new ArrayList<MediaType>();
         acceptedContentTypes.add(new MediaType("something", "xml"));
@@ -383,7 +397,7 @@
         properties.put(ServletRequest.HTTP_HEADERS, headers);
         servletRequest = new ServletRequest(url, null, properties);
         response = new ServletResponse(new StringWriter());
-        ServletTestFramework.initContext(servletRequest, response, context);
+        context = ServletTestFramework.initContext(servletRequest, response);
         context.setProperty(ContextConstants.SERVLET_REQUEST, servletRequest);
         acceptedContentTypes = new ArrayList<MediaType>();
         acceptedContentTypes.add(new MediaType("text", "*"));
@@ -418,7 +432,6 @@
      */
     public void testSelectVariantMinimal() throws Exception {
         String url = "http://localhost:7070/resource/someresource";
-        RESTContext context = new RESTContext();
         MultivaluedMap<String, String> mValuedHeaders = new MetadataMap<String, String>();
         Map<String, Object> properties = new HashMap<String, Object>();
         Map<String, List<String>> headers = new HashMap<String, List<String>>();
@@ -432,7 +445,8 @@
         ServletRequest servletRequest = new ServletRequest(url, null,
                 properties);
         ServletResponse response = new ServletResponse(new StringWriter());
-        ServletTestFramework.initContext(servletRequest, response, context);
+        RESTContext context = ServletTestFramework.initContext(servletRequest,
+                response);
         context.setProperty(ContextConstants.SERVLET_REQUEST, servletRequest);
         List<MediaType> acceptedContentTypes = new ArrayList<MediaType>();
         acceptedContentTypes.add(new MediaType("text", "xml"));

Propchange: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/core/RequestTests.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message