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 [3/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/com/ibm/ws/jaxrs/model/reflective/OperationResourceInfoImpl.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/OperationResourceInfoImpl.java?rev=788908&r1=788907&r2=788908&view=diff
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/OperationResourceInfoImpl.java (original)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/OperationResourceInfoImpl.java Sat Jun 27 00:02:26 2009
@@ -20,7 +20,9 @@
 package com.ibm.ws.jaxrs.model.reflective;
 
 import java.lang.reflect.Method;
-import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -39,81 +41,155 @@
 
 public class OperationResourceInfoImpl implements OperationResourceInfo {
 
-    protected URITemplate uriTemplate;
+    final protected URITemplate uriTemplate;
 
-    protected ClassResourceInfo classResourceInfo;
+    final protected ClassResourceInfo classResourceInfo;
 
-    protected Method methodToInvoke;
+    final protected Method methodToInvoke;
 
-    protected Method annotatedMethod;
+    final protected Method annotatedMethod;
 
-    protected String httpMethod;
+    final protected String httpMethod;
 
-    protected List<MediaType> produceMimes;
+    final protected List<MediaType> produceMimes;
 
-    protected List<MediaType> consumeMimes;
+    final protected List<MediaType> consumeMimes;
 
-    private String path;
+    final boolean isConsumeMimesEmpty;
 
-    private boolean pathInit = false;
+    final boolean isProducesMimesEmpty;
 
-    protected boolean encoded;
+    final private String path;
 
-    protected String defaultParamValue;
+    final protected boolean isEncoded;
 
-    protected boolean subResourceMethod;
+    final protected String defaultParamValue;
 
-    protected boolean subResourceLocator;
+    final protected boolean subResourceMethod;
 
-    protected Map<Property, Object> values = new HashMap<Property, Object>();
+    final protected boolean subResourceLocator;
 
     protected boolean isFormParamFound;
 
-    public OperationResourceInfoImpl(Method m, ClassResourceInfo cri) {
-        methodToInvoke = m;
-        annotatedMethod = m;
-        classResourceInfo = cri;
+    final private ThreadLocal<LinkedHashMap<String, Boolean>> consumesMediaTypeCompatibleCache = new ThreadLocalMediaTypeCompatibleCache();
+
+    final private ThreadLocal<LinkedHashMap<String, Boolean>> producesMediaTypeCompatibleCache = new ThreadLocalMediaTypeCompatibleCache();
+
+    final private ThreadLocal<LinkedHashMap<MediaType, List<MediaType>>> consumesMediaTypeIntersectionCache = new ThreadLocalMediaTypeIntersectionCache();
+
+    final private ThreadLocal<LinkedHashMap<MediaType, List<MediaType>>> producesMediaTypeIntersectionCache = new ThreadLocalMediaTypeIntersectionCache();
+
+    final private ThreadLocal<LinkedHashMap<String, MediaType>> consumesTypesMostSpecificCompatibleWithMediaTypeCache = new ThreadLocalMostSpecificCompatibleMediaTypeCache();
+
+    final private ThreadLocal<LinkedHashMap<String, MediaType>> producesTypesMostSpecificCompatibleWithMediaTypeCache = new ThreadLocalMostSpecificCompatibleMediaTypeCache();
+
+    public OperationResourceInfoImpl(Method m, ClassResourceInfo cri, String httpMethod, boolean isSubResourceMethod, boolean isSubLocatorMethod) {
+        this(m, cri, httpMethod, isSubResourceMethod, isSubLocatorMethod,
+                processPath(m), processDefaultParameterValue(m, cri),
+                processEncoded(m, cri), processConsumeTypes(m, cri),
+                processProduceTypes(m, cri));
+    }
+
+    public OperationResourceInfoImpl(Method m, ClassResourceInfo cri, String httpMethod, boolean isSubResourceMethod, boolean isSubLocatorMethod, String path, String defaultParamValue, boolean encoded, List<MediaType> consumeMimes, List<MediaType> produceMimes) {
+        /*
+         * the following 3 variables must be set
+         */
+        this.methodToInvoke = m;
+        this.annotatedMethod = m;
+        this.classResourceInfo = cri;
+
+        this.httpMethod = (httpMethod == null) ? null : httpMethod
+                .toUpperCase();
+
+        this.subResourceMethod = isSubResourceMethod;
+        this.subResourceLocator = isSubLocatorMethod;
+        this.path = path;
+
+        this.defaultParamValue = (defaultParamValue == null) ? processDefaultParameterValue(
+                m, cri)
+                : defaultParamValue;
+        this.isEncoded = (encoded) ? true : processEncoded(m, cri);
+
+        if (consumeMimes == null) {
+            List<MediaType> mimes = processConsumeTypes(m, cri);
+            if (mimes != null && !mimes.isEmpty()) {
+                this.consumeMimes = Collections.unmodifiableList(JAXRSUtils
+                        .sortMediaTypes(new ArrayList<MediaType>(mimes)));
+            } else {
+                this.consumeMimes = cri.getConsumes();
+            }
+        } else {
+            this.consumeMimes = Collections.unmodifiableList(JAXRSUtils
+                    .sortMediaTypes(new ArrayList<MediaType>(consumeMimes)));
+        }
+
+        isConsumeMimesEmpty = this.consumeMimes == null
+                || this.consumeMimes.isEmpty()
+                || this.consumeMimes.contains(MediaType.WILDCARD_TYPE);
+
+        if (produceMimes == null) {
+            List<MediaType> mimes = processProduceTypes(m, cri);
+            if (mimes != null && !mimes.isEmpty()) {
+                this.produceMimes = Collections.unmodifiableList(JAXRSUtils
+                        .sortMediaTypes(new ArrayList<MediaType>(mimes)));
+            } else {
+                this.produceMimes = cri.getProduces();
+            }
+        } else {
+            this.produceMimes = Collections.unmodifiableList(JAXRSUtils
+                    .sortMediaTypes(new ArrayList<MediaType>(produceMimes)));
+        }
+
+        isProducesMimesEmpty = this.produceMimes == null
+                || this.produceMimes.isEmpty()
+                || this.produceMimes.contains(MediaType.WILDCARD_TYPE);
+
+        this.uriTemplate = URITemplate.createTemplate(this.path);
         isFormParamFound = false;
-        checkMediaTypes();
-        checkEncoded();
-        checkDefaultParameterValue();
     }
 
     public URITemplate getURITemplate() {
         return uriTemplate;
     }
 
-    public void setURITemplate(URITemplate u) {
-        uriTemplate = u;
-    }
-
     public ClassResourceInfo getClassResourceInfo() {
         return classResourceInfo;
     }
 
-    public void setClassResourceInfo(ClassResourceInfo c) {
-        classResourceInfo = c;
-    }
-
     public Method getMethodToInvoke() {
         return methodToInvoke;
     }
 
-    public void setMethodToInvoke(Method m) {
-        methodToInvoke = m;
-    }
-
     public String getHttpMethod() {
         return httpMethod;
     }
 
-    public void setHttpMethod(String m) {
-        httpMethod = m;
+    private static List<MediaType> processConsumeTypes(Method m, ClassResourceInfo info) {
+        Consumes cm = (Consumes) AnnotationUtils.getMethodAnnotation(m,
+                Consumes.class);
+        List<MediaType> mimes = null;
+        if (cm != null) {
+            mimes = JAXRSUtils.sortMediaTypes(JAXRSUtils.getMediaTypes(cm
+                    .value()));
+        } else if (info != null) {
+            mimes = JAXRSUtils.sortMediaTypes(new ArrayList<MediaType>(info
+                    .getConsumes()));
+        }
+        return mimes;
     }
 
-    public void setAnnotatedMethod(Method m) {
-        annotatedMethod = m;
-        checkMediaTypes();
+    private static List<MediaType> processProduceTypes(Method m, ClassResourceInfo info) {
+        Produces pm = (Produces) AnnotationUtils.getMethodAnnotation(m,
+                Produces.class);
+        List<MediaType> mimes = null;
+        if (pm != null) {
+            mimes = JAXRSUtils.sortMediaTypes(JAXRSUtils.getMediaTypes(pm
+                    .value()));
+        } else if (info != null) {
+            mimes = JAXRSUtils.sortMediaTypes(new ArrayList<MediaType>(info
+                    .getProduces()));
+        }
+        return mimes;
     }
 
     public Method getAnnotatedMethod() {
@@ -124,102 +200,61 @@
         return subResourceLocator;
     }
 
-    public void setIsSubResourceLocator(boolean subResourceLocator) {
-        this.subResourceLocator = subResourceLocator;
-    }
-
     public boolean isSubResourceMethod() {
         return subResourceMethod;
     }
 
-    public void setIsSubResourceMethod(boolean subResourceMethod) {
-        this.subResourceMethod = subResourceMethod;
-    }
-
     public List<MediaType> getProduces() {
-        if (values.containsKey(Property.PRODUCES)) {
-            return (List<MediaType>) values.get(Property.PRODUCES);
-        }
         return produceMimes;
     }
 
     public List<MediaType> getConsumes() {
-        if (values.containsKey(Property.CONSUMES)) {
-            return (List<MediaType>) values.get(Property.CONSUMES);
-        }
         return consumeMimes;
     }
 
-    protected void checkMediaTypes() {
-        Consumes cm = (Consumes) AnnotationUtils.getMethodAnnotation(
-                annotatedMethod, Consumes.class);
-        if (cm != null) {
-            consumeMimes = JAXRSUtils.sortMediaTypes(JAXRSUtils
-                    .getMediaTypes(cm.value()));
-        } else if (classResourceInfo != null) {
-            consumeMimes = JAXRSUtils.sortMediaTypes(classResourceInfo
-                    .getConsumes());
-        }
-
-        Produces pm = (Produces) AnnotationUtils.getMethodAnnotation(
-                annotatedMethod, Produces.class);
-        if (pm != null) {
-            produceMimes = JAXRSUtils.sortMediaTypes(JAXRSUtils
-                    .getMediaTypes(pm.value()));
-        } else if (classResourceInfo != null) {
-            produceMimes = JAXRSUtils.sortMediaTypes(classResourceInfo
-                    .getProduces());
-        }
-    }
-
     public String getPath() {
-        if (values.containsKey(Property.PATH)) {
-            path = (String) values.get(Property.PATH);
-        } else if (!pathInit) {
-            Path pathAnnot = (Path) AnnotationUtils.getMethodAnnotation(
-                    annotatedMethod, Path.class);
-            path = pathAnnot != null ? pathAnnot.value() : null;
-        }
         return path;
     }
 
+    private static String processPath(Method m) {
+        Path pathAnnot = (Path) AnnotationUtils.getMethodAnnotation(m,
+                Path.class);
+        return pathAnnot != null ? pathAnnot.value() : null;
+    }
+
     public boolean isEncodedEnabled() {
-        if (values.containsKey(Property.ENCODED)) {
-            encoded = ((Boolean) values.get(Property.ENCODED)).booleanValue();
+        return isEncoded;
+    }
+
+    private static boolean processEncoded(Method m, ClassResourceInfo info) {
+        boolean encoded = AnnotationUtils.getMethodAnnotation(m, Encoded.class) != null;
+        if (!encoded && info != null) {
+            encoded = AnnotationUtils.getClassAnnotation(
+                    info.getServiceClass(), Encoded.class) != null;
         }
         return encoded;
     }
 
     public String getDefaultParameterValue() {
-        if (values.containsKey(Property.DEFAULT_VALUE)) {
-            defaultParamValue = (String) values.get(Property.DEFAULT_VALUE);
-        }
         return defaultParamValue;
     }
 
-    protected void checkEncoded() {
-        encoded = AnnotationUtils.getMethodAnnotation(annotatedMethod,
-                Encoded.class) != null;
-        if (!encoded && classResourceInfo != null) {
-            encoded = AnnotationUtils.getClassAnnotation(classResourceInfo
-                    .getServiceClass(), Encoded.class) != null;
-        }
-    }
+    private static String processDefaultParameterValue(Method m, ClassResourceInfo info) {
+        DefaultValue dv = (DefaultValue) AnnotationUtils.getMethodAnnotation(m,
+                DefaultValue.class);
+        if (dv == null) {
+            if (info != null) {
+                dv = (DefaultValue) AnnotationUtils.getClassAnnotation(info
+                        .getServiceClass(), DefaultValue.class);
 
-    protected void checkDefaultParameterValue() {
-        DefaultValue dv = (DefaultValue) AnnotationUtils.getMethodAnnotation(
-                annotatedMethod, DefaultValue.class);
-        if (dv == null && classResourceInfo != null) {
-            dv = (DefaultValue) AnnotationUtils.getClassAnnotation(
-                    classResourceInfo.getServiceClass(), DefaultValue.class);
+            }
         }
+
         if (dv != null) {
-            defaultParamValue = dv.value();
+            return dv.value();
         }
-    }
 
-    public void setValue(Property property, Object value) {
-        values.put(property, value);
+        return null;
     }
 
     public boolean isFormParamFound() {
@@ -230,4 +265,114 @@
         this.isFormParamFound = isFormParamFound;
     }
 
+    public boolean isMediaTypeCompatibleWithConsumes(MediaType mediaType) {
+        if (mediaType == null) {
+            if (isConsumeMimesEmpty) {
+                return true;
+            }
+            return false;
+        }
+        String key = mediaType.getType() + "/" + mediaType.getSubtype();
+        LinkedHashMap<String, Boolean> cache = consumesMediaTypeCompatibleCache
+                .get();
+        Boolean isCompatible = cache.get(key);
+        if (isCompatible != null) {
+            return isCompatible.booleanValue();
+        }
+
+        isCompatible = Boolean.valueOf(JAXRSUtils.isMediaTypeInList(
+                consumeMimes, mediaType, false));
+        cache.put(key, isCompatible);
+        return isCompatible.booleanValue();
+    }
+
+    public boolean isMediaTypeCompatibleWithProduces(MediaType mediaType) {
+        if (mediaType == null) {
+            if (produceMimes == null
+                    || (produceMimes.isEmpty() || produceMimes
+                            .contains(MediaType.WILDCARD_TYPE))) {
+                return true;
+            }
+            return false;
+        }
+        String key = mediaType.getType() + "/" + mediaType.getSubtype();
+        LinkedHashMap<String, Boolean> cache = producesMediaTypeCompatibleCache
+                .get();
+        Boolean isCompatible = cache.get(key);
+        if (isCompatible != null) {
+            return isCompatible.booleanValue();
+        }
+        isCompatible = Boolean.valueOf(JAXRSUtils.isMediaTypeInList(
+                produceMimes, mediaType, true));
+        cache.put(key, isCompatible);
+        return isCompatible.booleanValue();
+    }
+
+    public List<MediaType> getConsumesIntersectedWithMediaType(MediaType mediaType) {
+        LinkedHashMap<MediaType, List<MediaType>> cache = consumesMediaTypeIntersectionCache
+                .get();
+        List<MediaType> intersectedTypes = cache.get(mediaType);
+        if (intersectedTypes != null) {
+            return intersectedTypes;
+        }
+
+        intersectedTypes = JAXRSUtils.sortMediaTypes(JAXRSUtils
+                .intersectMimeTypes(consumeMimes, Collections
+                        .singletonList(mediaType), false));
+        intersectedTypes = Collections.unmodifiableList(intersectedTypes);
+        cache.put(mediaType, intersectedTypes);
+        return intersectedTypes;
+    }
+
+    public List<MediaType> getProducesIntersectedWithMediaType(MediaType mediaType) {
+        LinkedHashMap<MediaType, List<MediaType>> cache = producesMediaTypeIntersectionCache
+                .get();
+        List<MediaType> intersectedTypes = cache.get(mediaType);
+        if (intersectedTypes != null) {
+            return intersectedTypes;
+        }
+
+        intersectedTypes = JAXRSUtils.sortMediaTypes(JAXRSUtils
+                .intersectMimeTypes(produceMimes, Collections
+                        .singletonList(mediaType), true));
+        intersectedTypes = Collections.unmodifiableList(intersectedTypes);
+        cache.put(mediaType, intersectedTypes);
+        return intersectedTypes;
+    }
+
+    public MediaType getConsumesTypesMostSpecificCompatibleWithMediaType(MediaType aMediaType) {
+        String key = aMediaType.getType() + "/" + aMediaType.getSubtype();
+        LinkedHashMap<String, MediaType> cache = consumesTypesMostSpecificCompatibleWithMediaTypeCache
+                .get();
+        MediaType mt = cache.get(key);
+        if (mt != null) {
+            return mt;
+        }
+
+        mt = JAXRSUtils.findMostSpecificCompatibleMediaType(aMediaType,
+                consumeMimes);
+        if (mt == null) {
+            return null;
+        }
+        cache.put(key, mt);
+        return mt;
+    }
+
+    public MediaType getProducesTypesMostSpecificCompatibleWithMediaType(MediaType aMediaType) {
+        String key = aMediaType.getType() + "/" + aMediaType.getSubtype();
+        LinkedHashMap<String, MediaType> cache = producesTypesMostSpecificCompatibleWithMediaTypeCache
+                .get();
+        MediaType mt = cache.get(key);
+        if (mt != null) {
+            return mt;
+        }
+
+        mt = JAXRSUtils.findMostSpecificCompatibleMediaType(aMediaType,
+                produceMimes);
+        if (mt == null) {
+            return null;
+        }
+        cache.put(key, mt);
+        return mt;
+    }
 }

Propchange: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/OperationResourceInfoImpl.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ProviderInfoImpl.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ProviderInfoImpl.java?rev=788908&r1=788907&r2=788908&view=diff
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ProviderInfoImpl.java (original)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ProviderInfoImpl.java Sat Jun 27 00:02:26 2009
@@ -23,6 +23,7 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -34,8 +35,6 @@
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.MessageBodyWriter;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.cxf.jaxrs.model.ProviderInfo;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
@@ -44,7 +43,7 @@
 
     final private Class providerClass;
 
-    final private static Log log = LogFactory.getLog(ProviderInfoImpl.class);
+    //    final private static Log log = LogFactory.getLog(ProviderInfoImpl.class);
 
     final protected List<Type> providerTypes;
 
@@ -56,18 +55,36 @@
 
     final private Map<Type, java.lang.reflect.Type> reflectedTypes;
 
+    final private static int cacheSize = 16;
+
+    final private ThreadLocal<LinkedHashMap<String, Boolean>> consumesMediaTypeCompatibleCache = new ThreadLocalMediaTypeCompatibleCache();
+
+    final private ThreadLocal<LinkedHashMap<String, Boolean>> producesMediaTypeCompatibleCache = new ThreadLocalMediaTypeCompatibleCache();
+
+    final private ThreadLocal<LinkedHashMap<MediaType, List<MediaType>>> producesTypesIntersectedWithMediaTypeCache = new ThreadLocalMediaTypeIntersectionCache();
+
+    final private ThreadLocal<LinkedHashMap<MediaType, List<MediaType>>> consumesTypesIntersectedWithMediaTypeCache = new ThreadLocalMediaTypeIntersectionCache();
+
+    final private ThreadLocal<LinkedHashMap<String, MediaType>> consumesTypesMostSpecificCompatibleWithMediaTypeCache = new ThreadLocalMostSpecificCompatibleMediaTypeCache();
+
+    final private ThreadLocal<LinkedHashMap<String, MediaType>> producesTypesMostSpecificCompatibleWithMediaTypeCache = new ThreadLocalMostSpecificCompatibleMediaTypeCache();
+
+    final private ThreadLocal<Map<Type, Map<java.lang.reflect.Type, Boolean>>> typeCompatibilityCache = new ThreadLocalTypeCompatibilityCache();
+
+    //    final private ConcurrentMap<Type, ThreadLocal<LinkedHashMap<java.lang.reflect.Type, Boolean>>> typeCompatibilityCache = new ConcurrentHashMap<Type, ThreadLocal<LinkedHashMap<java.lang.reflect.Type, Boolean>>>();
+
     public ProviderInfoImpl(Class<T> providerClass) {
         this(providerClass,
-                (providerClass == null) ? new ArrayList<MediaType>()
-                        : JAXRSUtils.getConsumeTypes((providerClass
+                (providerClass == null) ? null : JAXRSUtils
+                        .getConsumeTypes((providerClass
                                 .getAnnotation(Consumes.class))),
-                (providerClass == null) ? new ArrayList<MediaType>()
-                        : JAXRSUtils.getProduceTypes(providerClass
+                (providerClass == null) ? null : JAXRSUtils
+                        .getProduceTypes(providerClass
                                 .getAnnotation(Produces.class)));
     }
 
     public ProviderInfoImpl(Class<T> providerClass, List<MediaType> consumes, List<MediaType> produces) {
-        super(providerClass, providerClass, true);
+        super(providerClass, true);
         this.providerClass = providerClass;
         this.providerInstance = null;
         if (consumes == null) {
@@ -75,14 +92,16 @@
         } else {
             List<MediaType> temp = new ArrayList<MediaType>();
             temp.addAll(consumes);
-            this.consumes = Collections.unmodifiableList(temp);
+            this.consumes = Collections.unmodifiableList(JAXRSUtils
+                    .sortMediaTypes(temp));
         }
         if (produces == null) {
             this.produces = Collections.singletonList(MediaType.WILDCARD_TYPE);
         } else {
             List<MediaType> temp = new ArrayList<MediaType>();
             temp.addAll(produces);
-            this.produces = Collections.unmodifiableList(temp);
+            this.produces = Collections.unmodifiableList(JAXRSUtils
+                    .sortMediaTypes(temp));
         }
         if (providerClass != null) {
             this.providerTypes = Collections.unmodifiableList(JAXRSUtils
@@ -102,7 +121,7 @@
     }
 
     public ProviderInfoImpl(T providerInstance, List<MediaType> consumes, List<MediaType> produces) {
-        super(providerInstance.getClass(), providerInstance.getClass(), true);
+        super(providerInstance.getClass(), true);
         this.providerClass = providerInstance.getClass();
         this.providerInstance = providerInstance;
         if (consumes == null) {
@@ -110,14 +129,16 @@
         } else {
             List<MediaType> temp = new ArrayList<MediaType>();
             temp.addAll(consumes);
-            this.consumes = Collections.unmodifiableList(temp);
+            this.consumes = Collections.unmodifiableList(JAXRSUtils
+                    .sortMediaTypes(temp));
         }
         if (produces == null) {
             this.produces = Collections.singletonList(MediaType.WILDCARD_TYPE);
         } else {
             List<MediaType> temp = new ArrayList<MediaType>();
             temp.addAll(produces);
-            this.produces = Collections.unmodifiableList(temp);
+            this.produces = Collections.unmodifiableList(JAXRSUtils
+                    .sortMediaTypes(temp));
         }
         this.providerTypes = Collections.unmodifiableList(JAXRSUtils
                 .getProviderTypes(providerClass));
@@ -170,6 +191,67 @@
         return reflectedTypes;
     }
 
+    private static class JavaTypeCompatibilityCache extends LinkedHashMap<java.lang.reflect.Type, Boolean> {
+        private static final long serialVersionUID = 1L;
+
+        public JavaTypeCompatibilityCache() {
+            super(cacheSize, 0.75f, true);
+        }
+
+        @Override
+        public boolean removeEldestEntry(Map.Entry<java.lang.reflect.Type, Boolean> eldestEntry) {
+            return size() > cacheSize;
+        }
+    }
+
+    public boolean isParameterizedTypeCompatible(Type providerType, java.lang.reflect.Type genericType) {
+        Map<Type, Map<java.lang.reflect.Type, Boolean>> bigCache = typeCompatibilityCache
+                .get();
+        Map<java.lang.reflect.Type, Boolean> cache = bigCache.get(providerType);
+        if (cache == null) {
+            cache = new JavaTypeCompatibilityCache();
+            bigCache.put(providerType, cache);
+        }
+        Boolean isCompatible = cache.get(genericType);
+        if (isCompatible == null) {
+            boolean b = isTypeCompatible(genericType, reflectedTypes
+                    .get(providerType));
+            cache.put(genericType, Boolean.valueOf(b));
+            return b;
+        }
+        return isCompatible.booleanValue();
+    }
+
+    public boolean isMediaTypeCompatibleWithProduces(MediaType aMediaType) {
+        String key = aMediaType.getType() + "/" + aMediaType.getSubtype();
+        LinkedHashMap<String, Boolean> cache = producesMediaTypeCompatibleCache
+                .get();
+        Boolean isCompatible = cache.get(key);
+        if (isCompatible != null) {
+            return isCompatible.booleanValue();
+        }
+
+        isCompatible = Boolean.valueOf(JAXRSUtils.isMediaTypeInList(produces,
+                aMediaType, true));
+        cache.put(key, isCompatible);
+        return isCompatible.booleanValue();
+    }
+
+    public boolean isMediaTypeCompatibleWithConsumes(MediaType aMediaType) {
+        String key = aMediaType.getType() + "/" + aMediaType.getSubtype();
+        LinkedHashMap<String, Boolean> cache = consumesMediaTypeCompatibleCache
+                .get();
+        Boolean isCompatible = cache.get(key);
+        if (isCompatible != null) {
+            return isCompatible.booleanValue();
+        }
+
+        isCompatible = Boolean.valueOf(JAXRSUtils.isMediaTypeInList(consumes,
+                aMediaType, true));
+        cache.put(key, isCompatible);
+        return isCompatible.booleanValue();
+    }
+
     final static private Map<Type, java.lang.reflect.Type> initParameterizedType(Class<?> clazz) {
         Class<?> inspectedClass = clazz;
         Map<Type, java.lang.reflect.Type> mappedTypes = new HashMap<Type, java.lang.reflect.Type>();
@@ -230,4 +312,93 @@
         return types;
     }
 
+    public List<MediaType> getConsumesTypesIntersectedWithMediaType(MediaType mediaType) {
+        LinkedHashMap<MediaType, List<MediaType>> cache = consumesTypesIntersectedWithMediaTypeCache
+                .get();
+        List<MediaType> intersectedTypes = cache.get(mediaType);
+        if (intersectedTypes != null) {
+            return intersectedTypes;
+        }
+
+        intersectedTypes = JAXRSUtils.sortMediaTypes(JAXRSUtils
+                .intersectMimeTypes(consumes, Collections
+                        .singletonList(mediaType), false));
+        intersectedTypes = Collections.unmodifiableList(intersectedTypes);
+        cache.put(mediaType, intersectedTypes);
+        return intersectedTypes;
+    }
+
+    public List<MediaType> getProducesTypesIntersectedWithMediaType(MediaType mediaType) {
+        LinkedHashMap<MediaType, List<MediaType>> cache = producesTypesIntersectedWithMediaTypeCache
+                .get();
+        List<MediaType> intersectedTypes = cache.get(mediaType);
+        if (intersectedTypes != null) {
+            return intersectedTypes;
+        }
+
+        intersectedTypes = JAXRSUtils.sortMediaTypes(JAXRSUtils
+                .intersectMimeTypes(produces, Collections
+                        .singletonList(mediaType), false));
+        intersectedTypes = Collections.unmodifiableList(intersectedTypes);
+        cache.put(mediaType, intersectedTypes);
+        return intersectedTypes;
+    }
+
+    public MediaType getConsumesTypesMostSpecificCompatibleWithMediaType(MediaType mediaType) {
+        String key = mediaType.toString();
+        LinkedHashMap<String, MediaType> cache = consumesTypesMostSpecificCompatibleWithMediaTypeCache
+                .get();
+        MediaType mt = cache.get(key);
+        if (mt != null) {
+            return mt;
+        }
+
+        mt = JAXRSUtils
+                .findMostSpecificCompatibleMediaType(mediaType, consumes);
+        if (mt == null) {
+            return null;
+        }
+        cache.put(key, mt);
+        return mt;
+    }
+
+    public MediaType getProducesTypesMostSpecificCompatibleWithMediaType(MediaType mediaType) {
+        String key = mediaType.toString();
+        LinkedHashMap<String, MediaType> cache = producesTypesMostSpecificCompatibleWithMediaTypeCache
+                .get();
+        MediaType mt = cache.get(key);
+        if (mt != null) {
+            return mt;
+        }
+
+        mt = JAXRSUtils
+                .findMostSpecificCompatibleMediaType(mediaType, produces);
+        if (mt == null) {
+            return null;
+        }
+        cache.put(key, mt);
+        return mt;
+    }
+
+    private final static boolean isTypeCompatible(java.lang.reflect.Type returnType, java.lang.reflect.Type providerTypeArgument) {
+        if (returnType == providerTypeArgument
+                || returnType.equals(providerTypeArgument)) {
+            return true;
+        } else if ((providerTypeArgument instanceof Class)
+                && (returnType instanceof Class)) {
+            Class<?> argsType = (Class<?>) providerTypeArgument;
+            Class<?> retTypeClass = (Class<?>) returnType;
+            if (argsType.isAssignableFrom(retTypeClass)) {
+                return true;
+            }
+        } else if (providerTypeArgument instanceof ParameterizedType) {
+            Class<?> argsType = (Class<?>) ((ParameterizedType) providerTypeArgument)
+                    .getRawType();
+            Class<?> retTypeClass = (Class<?>) returnType;
+            if (argsType.isAssignableFrom(retTypeClass)) {
+                return true;
+            }
+        }
+        return false;
+    }
 }

Propchange: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ProviderInfoImpl.java
------------------------------------------------------------------------------
    svn:executable = *

Copied: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ThreadLocalMediaTypeCompatibleCache.java (from r788296, incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/CarDatabase.java)
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ThreadLocalMediaTypeCompatibleCache.java?p2=incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ThreadLocalMediaTypeCompatibleCache.java&p1=incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/CarDatabase.java&r1=788296&r2=788908&rev=788908&view=diff
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/CarDatabase.java (original)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ThreadLocalMediaTypeCompatibleCache.java Sat Jun 27 00:02:26 2009
@@ -17,26 +17,26 @@
  * under the License.
  */
 
-package com.ibm.ws.jaxrs.sample.customcontent;
+package com.ibm.ws.jaxrs.model.reflective;
 
-import java.util.HashMap;
-import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.Map;
 
-public class CarDatabase {
-
-    private static Map<String, Car> cars = new HashMap<String, Car>();
-
-    public static void addCar(Car car) {
-        cars.put(car.getLicenseNumber(), car);
-    }
-
-    public static Car getCar(String licenseNumber) {
-        return cars.get(licenseNumber);
-    }
+/**
+ *
+ */
+class ThreadLocalMediaTypeCompatibleCache extends ThreadLocal<LinkedHashMap<String, Boolean>> {
+    final private static int cacheSize = 16;
 
-    public static Iterator<Car> getCars() {
-        return cars.values().iterator();
+    @Override
+    public LinkedHashMap<String, Boolean> initialValue() {
+        return new LinkedHashMap<String, Boolean>(cacheSize, 0.75f, true) {
+            private static final long serialVersionUID = 3802888905777490396L;
+
+            @Override
+            protected boolean removeEldestEntry(Map.Entry<String, Boolean> eldestEntry) {
+                return size() > cacheSize;
+            }
+        };
     }
-
-}
+}
\ No newline at end of file

Propchange: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ThreadLocalMediaTypeCompatibleCache.java
------------------------------------------------------------------------------
    svn:executable = *

Copied: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ThreadLocalMediaTypeIntersectionCache.java (from r788296, incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/integration/ApplicationProvider.java)
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ThreadLocalMediaTypeIntersectionCache.java?p2=incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ThreadLocalMediaTypeIntersectionCache.java&p1=incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/integration/ApplicationProvider.java&r1=788296&r2=788908&rev=788908&view=diff
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/integration/ApplicationProvider.java (original)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ThreadLocalMediaTypeIntersectionCache.java Sat Jun 27 00:02:26 2009
@@ -17,25 +17,30 @@
  * under the License.
  */
 
-package com.ibm.ws.jaxrs.integration;
+package com.ibm.ws.jaxrs.model.reflective;
 
+import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Map;
 
-import javax.ws.rs.core.Application;
-
-import com.ibm.ws.jaxrs.context.RESTContext;
+import javax.ws.rs.core.MediaType;
 
 /**
- * Implementations of this interface will provide a list of JAX-RS
- * Application subclasses to the JAX-RS runtime.
  *
  */
-public interface ApplicationProvider {
+class ThreadLocalMediaTypeIntersectionCache extends ThreadLocal<LinkedHashMap<MediaType, List<MediaType>>> {
 
-    /**
-     * Called by the JAX-RS runtime to get a list of JAX-RS Application subclasses.
-     */
-    public List<Application> getApplicationClasses(RESTContext context)
-            throws Exception;
+    final private static int cacheSize = 16;
 
+    @Override
+    public LinkedHashMap<MediaType, List<MediaType>> initialValue() {
+        return new LinkedHashMap<MediaType, List<MediaType>>(16, 0.75f, true) {
+            private static final long serialVersionUID = 3802888905777490396L;
+
+            @Override
+            protected boolean removeEldestEntry(Map.Entry<MediaType, List<MediaType>> eldestEntry) {
+                return size() > cacheSize;
+            }
+        };
+    }
 }

Propchange: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ThreadLocalMediaTypeIntersectionCache.java
------------------------------------------------------------------------------
    svn:executable = *

Copied: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ThreadLocalMostSpecificCompatibleMediaTypeCache.java (from r788296, incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/CarDatabase.java)
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ThreadLocalMostSpecificCompatibleMediaTypeCache.java?p2=incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ThreadLocalMostSpecificCompatibleMediaTypeCache.java&p1=incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/CarDatabase.java&r1=788296&r2=788908&rev=788908&view=diff
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/CarDatabase.java (original)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ThreadLocalMostSpecificCompatibleMediaTypeCache.java Sat Jun 27 00:02:26 2009
@@ -17,26 +17,29 @@
  * under the License.
  */
 
-package com.ibm.ws.jaxrs.sample.customcontent;
+package com.ibm.ws.jaxrs.model.reflective;
 
-import java.util.HashMap;
-import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.Map;
 
-public class CarDatabase {
+import javax.ws.rs.core.MediaType;
 
-    private static Map<String, Car> cars = new HashMap<String, Car>();
+/**
+ *
+ */
+class ThreadLocalMostSpecificCompatibleMediaTypeCache extends ThreadLocal<LinkedHashMap<String, MediaType>> {
 
-    public static void addCar(Car car) {
-        cars.put(car.getLicenseNumber(), car);
-    }
+    final private static int cacheSize = 16;
 
-    public static Car getCar(String licenseNumber) {
-        return cars.get(licenseNumber);
+    @Override
+    public LinkedHashMap<String, MediaType> initialValue() {
+        return new LinkedHashMap<String, MediaType>(cacheSize, 0.75f, true) {
+            private static final long serialVersionUID = 3802888905777490396L;
+
+            @Override
+            protected boolean removeEldestEntry(Map.Entry<String, MediaType> eldestEntry) {
+                return size() > cacheSize;
+            }
+        };
     }
-
-    public static Iterator<Car> getCars() {
-        return cars.values().iterator();
-    }
-
 }

Propchange: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ThreadLocalMostSpecificCompatibleMediaTypeCache.java
------------------------------------------------------------------------------
    svn:executable = *

Copied: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ThreadLocalTypeCompatibilityCache.java (from r788296, incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/metadata/MetadataRegistry.java)
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ThreadLocalTypeCompatibilityCache.java?p2=incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ThreadLocalTypeCompatibilityCache.java&p1=incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/metadata/MetadataRegistry.java&r1=788296&r2=788908&rev=788908&view=diff
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/metadata/MetadataRegistry.java (original)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ThreadLocalTypeCompatibilityCache.java Sat Jun 27 00:02:26 2009
@@ -17,34 +17,30 @@
  * under the License.
  */
 
-package com.ibm.ws.jaxrs.metadata;
+package com.ibm.ws.jaxrs.model.reflective;
 
-import java.util.Hashtable;
+import java.util.LinkedHashMap;
 import java.util.Map;
 
-import com.ibm.ws.jaxrs.model.JAXRSInfoBuilderFactory;
-import com.ibm.ws.jaxrs.model.JAXRSInfoBuilderFactoryImpl;
+import org.apache.cxf.jaxrs.model.ProviderInfo.Type;
 
 /**
- * This will be a registry that contains implementations of plug points
- * defined within the metadata processing layer.
  *
  */
-public class MetadataRegistry {
+public class ThreadLocalTypeCompatibilityCache extends ThreadLocal<Map<Type, Map<java.lang.reflect.Type, Boolean>>> {
 
-    private static Map<Class<?>, Object> registry = new Hashtable<Class<?>, Object>();
+    final private static int cacheSize = 16;
 
-    static {
-        registry.put(JAXRSInfoBuilderFactory.class,
-                new JAXRSInfoBuilderFactoryImpl());
+    @Override
+    public Map<Type, Map<java.lang.reflect.Type, Boolean>> initialValue() {
+        return new LinkedHashMap<Type, Map<java.lang.reflect.Type, Boolean>>(
+                cacheSize, 0.75f, true) {
+            private static final long serialVersionUID = 3802888905777490396L;
+
+            @Override
+            protected boolean removeEldestEntry(Map.Entry<Type, Map<java.lang.reflect.Type, Boolean>> eldestEntry) {
+                return size() > cacheSize;
+            }
+        };
     }
-
-    public static void registerImplementation(Class<?> clazz, Object implementation) {
-        registry.put(clazz, implementation);
-    }
-
-    public static Object getImplementation(Class<?> clazz) {
-        return registry.get(clazz);
-    }
-
 }

Propchange: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/model/reflective/ThreadLocalTypeCompatibilityCache.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/provider/DataSourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/provider/DataSourceProvider.java?rev=788908&r1=788907&r2=788908&view=diff
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/provider/DataSourceProvider.java (original)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/provider/DataSourceProvider.java Sat Jun 27 00:02:26 2009
@@ -33,6 +33,8 @@
 import javax.ws.rs.ext.MessageBodyWriter;
 import javax.ws.rs.ext.Provider;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.cxf.helpers.IOUtils;
 
 /**
@@ -43,6 +45,8 @@
 @Provider
 public class DataSourceProvider implements MessageBodyReader<DataSource>, MessageBodyWriter<DataSource> {
 
+    private static final Log log = LogFactory.getLog(DataSourceProvider.class);
+
     public long getSize(DataSource dataSource, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
         long size = -1;
 
@@ -56,8 +60,8 @@
                 }
                 size = count;
             }
-        } catch (Exception e) {
-            e.printStackTrace();
+        } catch (IOException e) {
+            log.debug("Could not get the size", e);
         }
 
         return size;

Propchange: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/provider/DataSourceProvider.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/provider/JAXBOptionsResponseProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/provider/JAXBOptionsResponseProvider.java?rev=788908&r1=788907&r2=788908&view=diff
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/provider/JAXBOptionsResponseProvider.java (original)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/provider/JAXBOptionsResponseProvider.java Sat Jun 27 00:02:26 2009
@@ -111,7 +111,7 @@
             for (ClassResourceInfo classInfo : infos) {
                 if (log.isDebugEnabled()) {
                     log.debug("Adding resource metadata for "
-                            + classInfo.getResourceClass().getName()
+                            + classInfo.getServiceClass().getName()
                             + " to OPTIONS response");
                 }
                 Resource resource = classInfo.isRoot() ? new Resource()

Propchange: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/provider/JAXBOptionsResponseProvider.java
------------------------------------------------------------------------------
    svn:executable = *

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

Propchange: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/provider/RESTDataSource.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/resolver/JAXBContextResolver.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/resolver/JAXBContextResolver.java?rev=788908&r1=788907&r2=788908&view=diff
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/resolver/JAXBContextResolver.java (original)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/resolver/JAXBContextResolver.java Sat Jun 27 00:02:26 2009
@@ -19,8 +19,8 @@
 
 package com.ibm.ws.jaxrs.resolver;
 
+import java.util.LinkedHashMap;
 import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
 
 import javax.ws.rs.ext.ContextResolver;
 import javax.ws.rs.ext.Provider;
@@ -43,16 +43,32 @@
 
     private static final Log log = LogFactory.getLog(JAXBContextResolver.class);
 
-    private Map<String, JAXBContext> contextMap = new ConcurrentHashMap<String, JAXBContext>();
+    final private static int cacheSize = 128;
+
+    private ThreadLocal<Map<String, JAXBContext>> contextMap = new ThreadLocal<Map<String, JAXBContext>>() {
+
+        @Override
+        public LinkedHashMap<String, JAXBContext> initialValue() {
+            return new LinkedHashMap<String, JAXBContext>(16, 0.75f, true) {
+                private static final long serialVersionUID = 3802888905777490396L;
+
+                @Override
+                protected boolean removeEldestEntry(Map.Entry<String, JAXBContext> eldestEntry) {
+                    return size() > cacheSize;
+                }
+            };
+        }
+    };
 
     public JAXBContext getContext(Class<?> clazz) {
         JAXBContext context = null;
         try {
             String packageName = clazz.getPackage().getName();
-            context = contextMap.get(packageName);
+            Map<String, JAXBContext> cache = contextMap.get();
+            context = cache.get(packageName);
             if (context == null) {
                 context = JAXBContext.newInstance(packageName);
-                contextMap.put(packageName, context);
+                cache.put(packageName, context);
             }
         } catch (JAXBException e) {
             log.error(Messages.getMessage("jaxbContextFail"), e);

Propchange: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/resolver/JAXBContextResolver.java
------------------------------------------------------------------------------
    svn:executable = *

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

Propchange: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/tools/WebBuilder.java
------------------------------------------------------------------------------
    svn:executable = *

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

Propchange: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/utils/ClassUtils.java
------------------------------------------------------------------------------
    svn:executable = *

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

Propchange: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/validation/ClassResourceValidator.java
------------------------------------------------------------------------------
    svn:executable = *

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

Propchange: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/validation/JAXRSClassResourceValidator.java
------------------------------------------------------------------------------
    svn:executable = *

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

Propchange: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/validation/JAXRSOperationResourceValidator.java
------------------------------------------------------------------------------
    svn:executable = *

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

Propchange: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/validation/OperationResourceValidator.java
------------------------------------------------------------------------------
    svn:executable = *

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

Propchange: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/validation/RESTValidator.java
------------------------------------------------------------------------------
    svn:executable = *

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

Propchange: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/validation/ResourceValidationException.java
------------------------------------------------------------------------------
    svn:executable = *

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

Propchange: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/validation/ValidationMessage.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/web/RESTServlet.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/web/RESTServlet.java?rev=788908&r1=788907&r2=788908&view=diff
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/web/RESTServlet.java (original)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/web/RESTServlet.java Sat Jun 27 00:02:26 2009
@@ -19,31 +19,16 @@
 
 package com.ibm.ws.jaxrs.web;
 
-import java.io.File;
 import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MultivaluedMap;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.cxf.jaxrs.impl.MetadataMap;
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 
 import com.ibm.ws.jaxrs.context.ContextConstants;
 import com.ibm.ws.jaxrs.context.RESTContext;
@@ -204,9 +189,8 @@
      */
     private void processHttpRequest(HttpServletRequest request, HttpServletResponse response)
             throws ServletException {
+        RESTContext context = initContext(request, response);
         try {
-            RESTContext context = new RESTContext();
-            initContext(request, response, context);
             RESTEngine.invoke(context);
         } catch (Throwable e) {
             throw new ServletException(e.getMessage(), e);
@@ -217,223 +201,37 @@
      * This method will initialize various properties on the RESTContext that are
      * derived from the current request.
      */
-    void initContext(HttpServletRequest request, HttpServletResponse response, RESTContext context)
-            throws IOException, Exception {
-
-        // set the request and response on the context
-        context.setProperty(ContextConstants.SERVLET_REQUEST, request);
-        context.setProperty(ContextConstants.SERVLET_RESPONSE, response);
-
-        // set the ServletContext and ServletConfig on the context
-        try {
-            context.setProperty(ContextConstants.SERVLET_CONTEXT, servletConfig
-                    .getServletContext());
-        } catch (Throwable t) {
-            /* this is only a test framework issue */
-        }
-
-        context.setProperty(ContextConstants.SERVLET_CONFIG, servletConfig);
-
-        context.setProperty(ContextConstants.HTTP_ACCEPT_HEADER, request
-                .getHeader(HttpHeaders.ACCEPT));
-        context.setProperty(ContextConstants.HTTP_METHOD, request.getMethod());
-
-        context.setProperty(ContextConstants.CONTENT_TYPE, request
-                .getContentType());
-        context.setProperty(ContextConstants.HTTP_PATH_INFO,
-                normalizeURIValue(request.getPathInfo()));
-        context.setProperty(ContextConstants.HTTP_REQUEST_ENCODING, request
-                .getCharacterEncoding());
-        context.setProperty(ContextConstants.HTTP_REQUEST_URI,
-                normalizeURIValue(request.getRequestURI()));
-        context.setProperty(ContextConstants.HTTP_REQUEST_URL,
-                normalizeURIValue(request.getRequestURL().toString()));
-        context.setProperty(ContextConstants.HTTP_REQUEST_CONTEXT_PATH, request
-                .getContextPath());
-        context.setProperty(ContextConstants.HTTP_QUERY_STRING, request
-                .getQueryString());
-        context.setProperty(ContextConstants.AUTHENTICATION_SCHEME, request
-                .getAuthType());
-        context.setProperty(ContextConstants.USER_PRINCIPAL, request
-                .getUserPrincipal());
-        context.setProperty(ContextConstants.REQUEST_SECURE, Boolean
-                .valueOf(request.isSecure()));
-        context.setProperty(ContextConstants.CONTENT_LANGUAGE, request
-                .getHeader(HttpHeaders.CONTENT_LANGUAGE));
-        context.setProperty(ContextConstants.HTTP_REQUEST_LOCALE, request
-                .getLocale());
-        context.setProperty(ContextConstants.REQUEST_INPUT_STREAM, request
-                .getInputStream());
-        context.setProperty(ContextConstants.RESPONSE_OUTPUT_STREAM, response
-                .getOutputStream());
-        context.setProperty(ContextConstants.CONTEXT_CLASSLOADER, Thread
-                .currentThread().getContextClassLoader());
-        context.setProperty(ContextConstants.METADATA_KEY,
-                servletConfig != null ? servletConfig.getServletName() : null);
-
-        // set the config file URL if the servlet-config parameter is set
-        String fileLoc = servletConfig != null ? servletConfig
-                .getInitParameter("com.ibm.ws.jaxrs.ConfigFile") : null;
-        if (log.isDebugEnabled()) {
-            log.debug("IBM config file init parameter value is : " + fileLoc);
-        }
-        if (fileLoc != null && !"".equals(fileLoc)) {
-            File file = new File(fileLoc);
-            URL url = null;
-            if (!file.exists()) {
-                url = Thread.currentThread().getContextClassLoader()
-                        .getResource(fileLoc);
-                if (url == null) {
-                    if (!fileLoc.startsWith("/")) {
-                        fileLoc = "/" + fileLoc;
-                    }
-                    url = servletConfig.getServletContext()
-                            .getResource(fileLoc);
-                    if (log.isDebugEnabled()) {
-                        log.debug("IBM config file on servlet context  path : "
-                                + url);
-                    }
-                } else {
-                    if (log.isDebugEnabled()) {
-                        log
-                                .debug("IBM config file exists on classloader path : "
-                                        + url);
-                    }
-                }
-            } else {
-                url = file.toURI().toURL();
-                if (log.isDebugEnabled()) {
-                    log.debug("IBM config file exists on file system path : "
-                            + url);
-                }
-            }
-
-            if (log.isDebugEnabled()) {
-                log.debug("IBM config file setting is set to URL : " + url);
-            }
-            context.setProperty(ContextConstants.CONFIG_FILE_URL, url);
-        }
-
-        context.setProperty(ContextConstants.HTTP_PATH_RESOURCE,
-                getPath(request));
-
-        // initialize the query string values
-        MultivaluedMap<String, String> queryValuesDecoded = JAXRSUtils
-                .getStructuredParams(request.getQueryString(), "&", true);
-        MultivaluedMap<String, String> queryValuesEncoded = JAXRSUtils
-                .getStructuredParams(request.getQueryString(), "&", false);
-        context.setProperty(ContextConstants.QUERY_STRING_DECODED_VALUES,
-                queryValuesDecoded);
-        context.setProperty(ContextConstants.QUERY_STRING_ENCODED_VALUES,
-                queryValuesEncoded);
-
-        // initialize the HTTP headers
-        Map<String, List<String>> headers = getHeaders(request);
-        MultivaluedMap<String, String> headerValues = new MetadataMap<String, String>(
-                headers);
-        context.setProperty(ContextConstants.HTTP_HEADER_VALUES, headerValues);
-
-        // initialize the matrix parameters (both encoded/decoded)
+    RESTContext initContext(HttpServletRequest request, HttpServletResponse response) {
+        RESTContext context = new RESTServletContextImpl(request, response,
+                servletConfig);
+        /*
+         * the following properties are always used
+         */
         context
-                .setProperty(ContextConstants.MATRIX_PARAMETER_VALUES_DECODED,
-                        JAXRSUtils.getMatrixParams(URI.create(
-                                request.getRequestURL().toString())
-                                .getRawPath(), true));
-        context.setProperty(ContextConstants.MATRIX_PARAMETER_VALUES_ENCODED,
-                JAXRSUtils
-                        .getMatrixParams(URI.create(
-                                request.getRequestURL().toString())
-                                .getRawPath(), false));
-
-        // initialize the cookie array, convert the servlet cookies into JAX-RS style cookies
-        Cookie[] cookies = request.getCookies();
-        if (cookies != null) {
-            Map<String, javax.ws.rs.core.Cookie> cookieMap = new HashMap<String, javax.ws.rs.core.Cookie>();
-            for (Cookie cookie : cookies) {
-                javax.ws.rs.core.Cookie jaxrsCookie = new javax.ws.rs.core.Cookie(
-                        cookie.getName(), cookie.getValue(), cookie.getPath(),
-                        cookie.getDomain(), cookie.getVersion());
-                cookieMap.put(cookie.getName(), jaxrsCookie);
-            }
-            context.setProperty(ContextConstants.HTTP_COOKIES, cookieMap);
+                .setProperty(ContextConstants.HTTP_PATH_INFO,
+                        RESTServletContextImpl.normalizeURIValue(request
+                                .getPathInfo()));
+        String method = request.getMethod();
+        if (method != null) {
+            context.setProperty(ContextConstants.HTTP_METHOD, method
+                    .toUpperCase());
         }
-
-        // store all the acceptable Locales
-        List<Locale> locales = new ArrayList<Locale>();
-        Enumeration<Locale> localeEnum = request.getLocales();
-        if (localeEnum != null) {
-            while (localeEnum.hasMoreElements()) {
-                locales.add(localeEnum.nextElement());
+        try {
+            context.setProperty(ContextConstants.RESPONSE_OUTPUT_STREAM,
+                    response.getOutputStream());
+        } catch (IOException e) {
+            if (log.isDebugEnabled()) {
+                log
+                        .debug(
+                                "Could not get the OutputStream from the HttpServletResponse",
+                                e);
             }
-            context.setProperty(ContextConstants.HTTP_REQUEST_LOCALES, locales);
         }
-
         context.setProperty(ContextConstants.INTEGRATION_REGISTRATION_KEY,
                 servletConfig);
-    }
-
-    /**
-     * This method will return the path for the current request. This will contain
-     * all the parts after the context path, and the string will be encoded.
-     *
-     */
-    private String getPath(HttpServletRequest request) {
-        // normalize this value in the rare cases where someone has
-        // (/someresourcepath/../someresourcepath)
-        String path = URI.create(request.getRequestURL().toString())
-                .normalize().getRawPath();
-        if (request.getContextPath() != null
-                && path.indexOf(request.getContextPath()) != -1) {
-            String cp = request.getContextPath();
-            int cpLength = cp.length();
-            path = path.substring(path.indexOf(cp) + cpLength);
-        }
-
-        return path;
-    }
-
-    /**
-     * Normalize a given URI value and return it.
-     * @param value the value
-     * @return the normalized value if possible, if not possible, return what was sent in
-     */
-    private String normalizeURIValue(String value) {
-        if (value == null) {
-            return null;
-        }
-        try {
-            URI normalizedURI = new URI(value).normalize();
-            return normalizedURI.toString();
-        } catch (URISyntaxException e) {
-            // could this happen if the request message was made to the runtime already?
-            // maybe someone set up the request wrong
-        }
-        return value;
-    }
-
-    /**
-     * This method retrieves all the headers and establishes a multivalued map
-     * that is stored on the RESTContext.
-     *
-     */
-    private Map<String, List<String>> getHeaders(HttpServletRequest request) {
-        Map<String, List<String>> headers = new HashMap<String, List<String>>();
-        Enumeration headerNames = request.getHeaderNames();
-        if (headerNames != null) {
-            while (headerNames.hasMoreElements()) {
-                String headerName = (String) headerNames.nextElement();
-                List<String> headerValueList = new ArrayList<String>();
-                Enumeration headerValues = request.getHeaders(headerName);
-                if (headerValues != null) {
-                    while (headerValues.hasMoreElements()) {
-                        headerValueList
-                                .add((String) headerValues.nextElement());
-                    }
-                }
-                headerName = headerName.toLowerCase();
-                headers.put(headerName, headerValueList);
-            }
-        }
-        return headers;
+        context.setProperty(ContextConstants.HTTP_REQUEST_URL,
+                RESTServletContextImpl.normalizeURIValue(request
+                        .getRequestURL().toString()));
+        return context;
     }
 }

Propchange: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/web/RESTServlet.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/web/RESTServletContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/web/RESTServletContextImpl.java?rev=788908&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/web/RESTServletContextImpl.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/web/RESTServletContextImpl.java Sat Jun 27 00:02:26 2009
@@ -0,0 +1,575 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.ws.jaxrs.web;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MultivaluedMap;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+
+import com.ibm.ws.jaxrs.context.ContextConstants;
+import com.ibm.ws.jaxrs.context.RESTContext;
+
+public class RESTServletContextImpl implements RESTContext {
+
+    private static final Log log = LogFactory
+            .getLog(RESTServletContextImpl.class);
+
+    public RESTServletContextImpl(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+        this.request = request;
+        this.response = response;
+        this.config = config;
+    }
+
+    final private HttpServletRequest request;
+
+    final private HttpServletResponse response;
+
+    final private ServletConfig config;
+
+    final private Map<String, Object> properties = new HashMap<String, Object>();
+
+    abstract private static class ValueLookup {
+        abstract public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config);
+    }
+
+    final private static Map<String, ValueLookup> lookupObjs = new HashMap<String, ValueLookup>();
+
+    static {
+        lookupObjs.put(ContextConstants.SERVLET_REQUEST, new ValueLookup() {
+            @Override
+            public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                return request;
+            }
+        });
+
+        lookupObjs.put(ContextConstants.SERVLET_RESPONSE, new ValueLookup() {
+            @Override
+            public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                return response;
+            }
+        });
+
+        lookupObjs.put(ContextConstants.SERVLET_CONTEXT, new ValueLookup() {
+            @Override
+            public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                return config.getServletContext();
+            }
+        });
+
+        lookupObjs.put(ContextConstants.SERVLET_CONFIG, new ValueLookup() {
+            @Override
+            public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                return config;
+            }
+        });
+
+        lookupObjs.put(ContextConstants.HTTP_ACCEPT_HEADER, new ValueLookup() {
+            @Override
+            public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                return request.getHeader(HttpHeaders.ACCEPT);
+            }
+        });
+
+        lookupObjs.put(ContextConstants.CONTENT_TYPE, new ValueLookup() {
+            @Override
+            public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                return request.getContentType();
+            }
+        });
+
+        lookupObjs.put(ContextConstants.HTTP_REQUEST_ENCODING,
+                new ValueLookup() {
+                    @Override
+                    public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                        return request.getCharacterEncoding();
+                    }
+                });
+
+        lookupObjs.put(ContextConstants.HTTP_REQUEST_URI, new ValueLookup() {
+            @Override
+            public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                return normalizeURIValue(request.getRequestURI());
+            }
+        });
+
+        lookupObjs.put(ContextConstants.HTTP_REQUEST_CONTEXT_PATH,
+                new ValueLookup() {
+                    @Override
+                    public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                        return request.getContextPath();
+                    }
+                });
+
+        lookupObjs.put(ContextConstants.HTTP_QUERY_STRING, new ValueLookup() {
+            @Override
+            public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                return request.getQueryString();
+            }
+        });
+
+        lookupObjs.put(ContextConstants.AUTHENTICATION_SCHEME,
+                new ValueLookup() {
+                    @Override
+                    public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                        return request.getAuthType();
+                    }
+                });
+
+        lookupObjs.put(ContextConstants.USER_PRINCIPAL, new ValueLookup() {
+            @Override
+            public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                return request.getUserPrincipal();
+            }
+        });
+
+        lookupObjs.put(ContextConstants.REQUEST_SECURE, new ValueLookup() {
+            @Override
+            public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                return Boolean.valueOf(request.isSecure());
+            }
+        });
+
+        lookupObjs.put(ContextConstants.CONTENT_LANGUAGE, new ValueLookup() {
+            @Override
+            public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                return request.getHeader(HttpHeaders.CONTENT_LANGUAGE);
+            }
+        });
+
+        lookupObjs.put(ContextConstants.HTTP_REQUEST_LOCALE, new ValueLookup() {
+            @Override
+            public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                return request.getLocale();
+            }
+        });
+
+        lookupObjs.put(ContextConstants.REQUEST_INPUT_STREAM,
+                new ValueLookup() {
+                    @Override
+                    public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                        try {
+                            return request.getInputStream();
+                        } catch (IOException e) {
+                            if (log.isDebugEnabled()) {
+                                log
+                                        .debug(
+                                                "Could not get the InputStream from the HttpServletResponse",
+                                                e);
+                            }
+                            return null;
+                        }
+                    }
+                });
+
+        lookupObjs.put(ContextConstants.CONTEXT_CLASSLOADER, new ValueLookup() {
+            @Override
+            public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                return Thread.currentThread().getContextClassLoader();
+            }
+        });
+
+        lookupObjs.put(ContextConstants.METADATA_KEY, new ValueLookup() {
+            @Override
+            public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                return config != null ? config.getServletName() : null;
+            }
+        });
+
+        lookupObjs.put(ContextConstants.CONFIG_FILE_URL, new ValueLookup() {
+            @Override
+            public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                // set the config file URL if the servlet-config parameter is set
+                try {
+                    String fileLoc = config != null ? config
+                            .getInitParameter("com.ibm.ws.jaxrs.ConfigFile")
+                            : null;
+                    if (log.isDebugEnabled()) {
+                        log.debug("IBM config file init parameter value is : "
+                                + fileLoc);
+                    }
+                    if (fileLoc != null && !"".equals(fileLoc)) {
+                        File file = new File(fileLoc);
+                        URL url = null;
+                        if (!file.exists()) {
+                            url = Thread.currentThread()
+                                    .getContextClassLoader().getResource(
+                                            fileLoc);
+                            if (url == null) {
+                                if (!fileLoc.startsWith("/")) {
+                                    fileLoc = "/" + fileLoc;
+                                }
+                                if (config != null) {
+                                    url = config.getServletContext()
+                                            .getResource(fileLoc);
+                                }
+                                if (log.isDebugEnabled()) {
+                                    log
+                                            .debug("IBM config file on servlet context  path : "
+                                                    + url);
+                                }
+                            } else {
+                                if (log.isDebugEnabled()) {
+                                    log
+                                            .debug("IBM config file exists on classloader path : "
+                                                    + url);
+                                }
+                            }
+                        } else {
+                            url = file.toURI().toURL();
+                            if (log.isDebugEnabled()) {
+                                log
+                                        .debug("IBM config file exists on file system path : "
+                                                + url);
+                            }
+                        }
+
+                        if (log.isDebugEnabled()) {
+                            log
+                                    .debug("IBM config file setting is set to URL : "
+                                            + url);
+                        }
+                        return url;
+                    }
+                    return null;
+                } catch (MalformedURLException e) {
+                    if (log.isDebugEnabled()) {
+                        log.debug("Malformed URL for IBM config file setting",
+                                e);
+                    }
+                    return null;
+                }
+            }
+        });
+
+        lookupObjs.put(ContextConstants.HTTP_PATH_RESOURCE, new ValueLookup() {
+            @Override
+            public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                return getPath(request);
+            }
+        });
+
+        lookupObjs.put(ContextConstants.QUERY_STRING_DECODED_VALUES,
+                new ValueLookup() {
+                    @Override
+                    public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                        return JAXRSUtils.getStructuredParams(request
+                                .getQueryString(), "&", true);
+                    }
+                });
+
+        lookupObjs.put(ContextConstants.QUERY_STRING_ENCODED_VALUES,
+                new ValueLookup() {
+                    @Override
+                    public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                        return JAXRSUtils.getStructuredParams(request
+                                .getQueryString(), "&", false);
+                    }
+                });
+
+        lookupObjs.put(ContextConstants.HTTP_HEADER_VALUES, new ValueLookup() {
+            @Override
+            public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                return new HeaderMap(request);
+            }
+        });
+
+        lookupObjs.put(ContextConstants.MATRIX_PARAMETER_VALUES_DECODED,
+                new ValueLookup() {
+                    @Override
+                    public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                        return JAXRSUtils.getMatrixParams(URI.create(
+                                request.getRequestURL().toString())
+                                .getRawPath(), true);
+                    }
+                });
+
+        lookupObjs.put(ContextConstants.MATRIX_PARAMETER_VALUES_ENCODED,
+                new ValueLookup() {
+                    @Override
+                    public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                        return JAXRSUtils.getMatrixParams(URI.create(
+                                request.getRequestURL().toString())
+                                .getRawPath(), false);
+                    }
+                });
+
+        lookupObjs.put(ContextConstants.HTTP_COOKIES, new ValueLookup() {
+            @Override
+            public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                Cookie[] cookies = request.getCookies();
+                if (cookies != null) {
+                    Map<String, javax.ws.rs.core.Cookie> cookieMap = new HashMap<String, javax.ws.rs.core.Cookie>();
+                    for (Cookie cookie : cookies) {
+                        javax.ws.rs.core.Cookie jaxrsCookie = new javax.ws.rs.core.Cookie(
+                                cookie.getName(), cookie.getValue(), cookie
+                                        .getPath(), cookie.getDomain(), cookie
+                                        .getVersion());
+                        cookieMap.put(cookie.getName(), jaxrsCookie);
+                    }
+                    return cookieMap;
+                }
+                return null;
+            }
+        });
+
+        lookupObjs.put(ContextConstants.HTTP_REQUEST_LOCALES,
+                new ValueLookup() {
+                    @Override
+                    public Object lookupValue(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
+                        List<Locale> locales = new ArrayList<Locale>();
+                        Enumeration<Locale> localeEnum = request.getLocales();
+                        if (localeEnum != null) {
+                            while (localeEnum.hasMoreElements()) {
+                                locales.add(localeEnum.nextElement());
+                            }
+                            return locales;
+                        }
+                        return null;
+                    }
+                });
+    }
+
+    public Object getProperty(final String key) {
+        Object ret = properties.get(key);
+        if (ret != null) {
+            if (log.isDebugEnabled()) {
+                log.debug("Looked up property: " + key
+                        + " from context cache and found value: " + ret);
+            }
+            return ret;
+        }
+
+        ValueLookup lookup = lookupObjs.get(key);
+        if (lookup == null) {
+            if (log.isDebugEnabled()) {
+                log.debug("Tried looking up property: " + key
+                        + " but did not have ValueLookup object to look it up");
+            }
+            return null;
+        }
+        ret = lookup.lookupValue(request, response, config);
+        if (ret == null) {
+            if (log.isDebugEnabled()) {
+                log.debug("Tried looking up property: " + key
+                        + " but ValueLookup returned null");
+            }
+            return null;
+        }
+        properties.put(key, ret);
+        return ret;
+    }
+
+    public boolean isResponse() {
+        return false;
+    }
+
+    public void setProperty(String key, Object value) {
+        properties.put(key, value);
+    }
+
+    /**
+     * This method will return the path for the current request. This will contain
+     * all the parts after the context path, and the string will be encoded.
+     *
+     */
+    private static String getPath(HttpServletRequest request) {
+        // normalize this value in the rare cases where someone has
+        // (/someresourcepath/../someresourcepath)
+        String path = URI.create(request.getRequestURL().toString())
+                .normalize().getRawPath();
+        if (request.getContextPath() != null
+                && path.indexOf(request.getContextPath()) != -1) {
+            String cp = request.getContextPath();
+            int cpLength = cp.length();
+            path = path.substring(path.indexOf(cp) + cpLength);
+        }
+
+        return path;
+    }
+
+    /**
+     * Normalize a given URI value and return it.
+     * @param value the value
+     * @return the normalized value if possible, if not possible, return what was sent in
+     */
+    static String normalizeURIValue(String value) {
+        if (value == null) {
+            return null;
+        }
+        try {
+            URI normalizedURI = new URI(value).normalize();
+            return normalizedURI.toString();
+        } catch (URISyntaxException e) {
+            // could this happen if the request message was made to the runtime already?
+            // maybe someone set up the request wrong
+        }
+        return value;
+    }
+
+    final private static class HeaderMap implements MultivaluedMap<String, String> {
+        /*
+         * not thread safe but this will only be init per context
+         */
+        final private HttpServletRequest request;
+
+        final Map<String, List<String>> headersCache = new HashMap<String, List<String>>();
+
+        boolean isHeaderCacheInit = false;
+
+        private void init() {
+            if (isHeaderCacheInit) {
+                return;
+            }
+            Enumeration headerNames = request.getHeaderNames();
+            if (headerNames != null) {
+                while (headerNames.hasMoreElements()) {
+                    String headerName = (String) headerNames.nextElement();
+                    List<String> headerValueList = new ArrayList<String>();
+                    Enumeration headerValues = request.getHeaders(headerName);
+                    if (headerValues != null) {
+                        while (headerValues.hasMoreElements()) {
+                            headerValueList.add((String) headerValues
+                                    .nextElement());
+                        }
+                    }
+                    headerName = headerName.toLowerCase();
+                    headersCache.put(headerName, Collections
+                            .unmodifiableList(headerValueList));
+                }
+            }
+            isHeaderCacheInit = true;
+        }
+
+        public HeaderMap(HttpServletRequest request) {
+            this.request = request;
+        }
+
+        public void clear() {
+            throw new UnsupportedOperationException();
+        }
+
+        public boolean containsKey(Object key) {
+            return request.getHeader((String) key) != null;
+        }
+
+        public boolean containsValue(Object value) {
+            init();
+            return headersCache.containsValue(value);
+        }
+
+        public Set<java.util.Map.Entry<String, List<String>>> entrySet() {
+            init();
+            return headersCache.entrySet();
+        }
+
+        public List<String> get(Object key) {
+            String header = ((String) key).toLowerCase();
+            List<String> ret = headersCache.get(header);
+            if (ret != null) {
+                if (ret.isEmpty()) {
+                    return null;
+                }
+                return ret;
+            }
+            Enumeration<String> headerValues = request.getHeaders((String) key);
+            if (headerValues == null) {
+                return null;
+            }
+            ret = new ArrayList<String>();
+            while (headerValues.hasMoreElements()) {
+                ret.add(headerValues.nextElement());
+            }
+            headersCache.put(header, Collections.unmodifiableList(ret));
+            if (ret.isEmpty()) {
+                return null;
+            }
+            return ret;
+        }
+
+        public boolean isEmpty() {
+            init();
+            return headersCache.isEmpty();
+        }
+
+        public Set<String> keySet() {
+            init();
+            return headersCache.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() {
+            init();
+            return headersCache.size();
+        }
+
+        public Collection<List<String>> values() {
+            init();
+            return headersCache.values();
+        }
+
+        public void add(String arg0, String arg1) {
+            throw new UnsupportedOperationException();
+        }
+
+        public String getFirst(String arg0) {
+            return request.getHeader(arg0);
+        }
+
+        public void putSingle(String arg0, String arg1) {
+            throw new UnsupportedOperationException();
+        }
+
+    }
+
+}

Propchange: incubator/wink/contrib/ibm-jaxrs/src/com/ibm/ws/jaxrs/web/RESTServletContextImpl.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message