cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1381654 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/mai...
Date Thu, 06 Sep 2012 15:54:28 GMT
Author: sergeyb
Date: Thu Sep  6 15:54:27 2012
New Revision: 1381654

URL: http://svn.apache.org/viewvc?rev=1381654&view=rev
Log:
[CXF-4455] Preparing for the introduction of new Container filters

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java?rev=1381654&r1=1381653&r2=1381654&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
Thu Sep  6 15:54:27 2012
@@ -165,18 +165,7 @@ public class JAXRSInInterceptor extends 
         boolean operChecked = false;
         List<ProviderInfo<RequestHandler>> shs = ProviderFactory.getInstance(message).getRequestHandlers();
         for (ProviderInfo<RequestHandler> sh : shs) {
-            String newAcceptTypes = HttpUtils.getProtocolHeader(message, Message.ACCEPT_CONTENT_TYPE,
"*/*");
-            if (!acceptTypes.equals(newAcceptTypes) || (ori == null && !operChecked))
{
-                acceptTypes = newAcceptTypes;
-                acceptContentTypes = JAXRSUtils.sortMediaTypes(newAcceptTypes);
-                message.getExchange().put(Message.ACCEPT_CONTENT_TYPE, acceptContentTypes);
-                if (ori != null) {
-                    values = new MetadataMap<String, String>();
-                    resource = JAXRSUtils.selectResourceClass(resources, 
-                                                              rawPath, 
-                                                              values,
-                                                              message);
-                }
+            if (ori == null && !operChecked) {
                 try {                
                     ori = JAXRSUtils.findTargetMethod(resource, 
                         message, httpMethod, values, 
@@ -187,27 +176,16 @@ public class JAXRSInInterceptor extends 
                 }
                 
             }
-            InjectionUtils.injectContextFields(sh.getProvider(), sh, message);
-            InjectionUtils.injectContextMethods(sh.getProvider(), sh, message);
+            InjectionUtils.injectContexts(sh.getProvider(), sh, message);
             Response response = sh.getProvider().handleRequest(message, resource);
             if (response != null) {
                 message.getExchange().put(Response.class, response);
                 return;
             }
+            
         }
         
-        String newAcceptTypes = (String)message.get(Message.ACCEPT_CONTENT_TYPE);
-        if (!acceptTypes.equals(newAcceptTypes) || ori == null) {
-            acceptTypes = newAcceptTypes;
-            acceptContentTypes = JAXRSUtils.sortMediaTypes(acceptTypes);
-            message.getExchange().put(Message.ACCEPT_CONTENT_TYPE, acceptContentTypes);
-            if (ori != null) {
-                values = new MetadataMap<String, String>();
-                resource = JAXRSUtils.selectResourceClass(resources, 
-                                                          rawPath, 
-                                                          values,
-                                                          message);
-            }
+        if (ori == null) {
             try {                
                 ori = JAXRSUtils.findTargetMethod(resource, message, 
                                             httpMethod, values, requestContentType, acceptContentTypes,
true);

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java?rev=1381654&r1=1381653&r2=1381654&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
Thu Sep  6 15:54:27 2012
@@ -133,14 +133,13 @@ public class JAXRSOutInterceptor extends
         List<ProviderInfo<ResponseHandler>> handlers = 
             ProviderFactory.getInstance(message).getResponseHandlers();
         for (ProviderInfo<ResponseHandler> rh : handlers) {
-            InjectionUtils.injectContextFields(rh.getProvider(), rh, 
-                                               message.getExchange().getInMessage());
-            InjectionUtils.injectContextFields(rh.getProvider(), rh, 
+            InjectionUtils.injectContexts(rh.getProvider(), rh, 
                                                message.getExchange().getInMessage());
             Response r = rh.getProvider().handleResponse(message, ori, response);
             if (r != null) {
                 response = r;
             }
+            
         }
         
         serializeMessage(message, response, ori, true);        

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java?rev=1381654&r1=1381653&r2=1381654&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
Thu Sep  6 15:54:27 2012
@@ -50,6 +50,7 @@ public abstract class AbstractResourceIn
     private Map<Class<?>, List<Field>> contextFields;
     private Map<Class<?>, Map<Class<?>, Method>> contextMethods;
     private Bus bus;
+    private boolean contextsAvailable = true;
     
     protected AbstractResourceInfo(Bus bus) {
         this.bus = bus;
@@ -61,11 +62,21 @@ public abstract class AbstractResourceIn
         this.resourceClass = resourceClass;
         root = isRoot;
         if (root && resourceClass != null) {
-            findContextFields(serviceClass);
-            findContextSetterMethods(serviceClass);
+            findContexts(serviceClass);   
         }
     }
     
+    private void findContexts(Class<?> cls) {
+        findContextFields(cls);
+        findContextSetterMethods(cls);
+        contextsAvailable = contextFields != null && !contextFields.isEmpty() 
+            || contextMethods != null && !contextMethods.isEmpty();
+    }
+    
+    public boolean contextsAvailable() {
+        return contextsAvailable;
+    }
+    
     public Bus getBus() {
         return bus;
     }
@@ -73,8 +84,7 @@ public abstract class AbstractResourceIn
     public void setResourceClass(Class<?> rClass) {
         resourceClass = rClass;
         if (serviceClass.isInterface() && resourceClass != null && !resourceClass.isInterface())
{
-            findContextFields(resourceClass);
-            findContextSetterMethods(resourceClass);
+            findContexts(resourceClass);
         }
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java?rev=1381654&r1=1381653&r2=1381654&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java
Thu Sep  6 15:54:27 2012
@@ -20,6 +20,7 @@
 package org.apache.cxf.jaxrs.model;
 
 import java.lang.reflect.Method;
+import java.util.Collections;
 import java.util.List;
 
 import javax.ws.rs.Consumes;
@@ -45,6 +46,7 @@ public class OperationResourceInfo {
     private String defaultParamValue;
     private List<Parameter> parameters;
     private boolean oneway; 
+    private List<String> nameBindings = Collections.emptyList();
 
     public OperationResourceInfo(Method mInvoke, ClassResourceInfo cri) {
         this(mInvoke, mInvoke, cri);
@@ -62,6 +64,7 @@ public class OperationResourceInfo {
         this.parameters = ori.parameters;
         this.oneway = ori.oneway;
         this.classResourceInfo = cri;
+        this.nameBindings = ori.nameBindings;
     }
     
     public OperationResourceInfo(Method mInvoke, Method mAnnotated, ClassResourceInfo cri)
{
@@ -69,6 +72,7 @@ public class OperationResourceInfo {
         annotatedMethod = mAnnotated;
         if (mAnnotated != null) {
             parameters = ResourceUtils.getParameters(mAnnotated);
+            nameBindings = AnnotationUtils.getNameBindings(mAnnotated.getAnnotations());
         }
         classResourceInfo = cri;
         checkMediaTypes(null, null);
@@ -97,6 +101,10 @@ public class OperationResourceInfo {
         this.oneway = oneway;
     }
     
+    public List<String> getNameBindings() {
+        return nameBindings;
+    }
+    
     private void checkOneway() {
         if (annotatedMethod != null) {
             oneway = AnnotationUtils.getAnnotation(annotatedMethod.getAnnotations(), Oneway.class)
!= null;

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1381654&r1=1381653&r2=1381654&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Thu Sep  6 15:54:27 2012
@@ -25,16 +25,22 @@ import java.lang.reflect.ParameterizedTy
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashSet;
+import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.logging.Logger;
 
 import javax.ws.rs.Produces;
 import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.container.PreMatching;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
@@ -61,6 +67,7 @@ import org.apache.cxf.jaxrs.impl.WebAppl
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.ProviderInfo;
 import org.apache.cxf.jaxrs.model.wadl.WadlGenerator;
+import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Message;
@@ -96,12 +103,31 @@ public final class ProviderFactory {
         new ArrayList<ProviderInfo<ContextProvider<?>>>(1);
     private List<ProviderInfo<ExceptionMapper<?>>> exceptionMappers = 
         new ArrayList<ProviderInfo<ExceptionMapper<?>>>(1);
+    // RequestHandler & ResponseHandler will have to be deprecated for 2.7.0
     private List<ProviderInfo<RequestHandler>> requestHandlers = 
         new ArrayList<ProviderInfo<RequestHandler>>(1);
     private List<ProviderInfo<ResponseHandler>> responseHandlers = 
         new ArrayList<ProviderInfo<ResponseHandler>>(1);
+    
+    // ContainerRequestFilter & ContainerResponseFilter are introduced in JAX-RS 2.0
+    private List<ProviderInfo<ContainerRequestFilter>> globalContainerRequestFilters
= 
+        new ArrayList<ProviderInfo<ContainerRequestFilter>>(1);
+    private List<ProviderInfo<ContainerRequestFilter>> globalPreContainerRequestFilters
= 
+        new ArrayList<ProviderInfo<ContainerRequestFilter>>(1);
+    private List<ProviderInfo<ContainerResponseFilter>> globalContainerResponseFilters
= 
+        new ArrayList<ProviderInfo<ContainerResponseFilter>>(1);
+    private List<ProviderInfo<ContainerResponseFilter>> globalPreContainerResponseFilters
= 
+        new ArrayList<ProviderInfo<ContainerResponseFilter>>(1);
+    private Map<String, ProviderInfo<ContainerRequestFilter>> boundContainerRequestFilters
= 
+        new LinkedHashMap<String, ProviderInfo<ContainerRequestFilter>>();
+    private Map<String, ProviderInfo<ContainerResponseFilter>> boundContainerResponseFilters
= 
+        new LinkedHashMap<String, ProviderInfo<ContainerResponseFilter>>();
+    
+    // ParamConverter and ParamConverterProvider is introduced in JAX-RS 2.0
+    // ParameterHandler will have to be deprecated
     private List<ProviderInfo<ParameterHandler<?>>> paramHandlers = 
         new ArrayList<ProviderInfo<ParameterHandler<?>>>(1);
+    
     private List<ProviderInfo<ResponseExceptionMapper<?>>> responseExceptionMappers
= 
         new ArrayList<ProviderInfo<ResponseExceptionMapper<?>>>(1);
     private RequestPreprocessor requestPreprocessor;
@@ -112,6 +138,9 @@ public final class ProviderFactory {
     private List<ProviderInfo<MessageBodyWriter<?>>> jaxbWriters = 
         new ArrayList<ProviderInfo<MessageBodyWriter<?>>>();
     
+    private Collection<ProviderInfo<?>> injectedProviders = 
+        new LinkedList<ProviderInfo<?>>();
+    
     private Bus bus;
     
     private ProviderFactory(Bus bus) {
@@ -267,6 +296,7 @@ public final class ProviderFactory {
         return null;
     }
     
+    //This method can only be called from providers
     public <T extends Throwable> ExceptionMapper<T> createExceptionMapper(Class<?>
exceptionType,
                                                                           Message m) {
         return createExceptionMapper(null, exceptionType, m);
@@ -436,6 +466,36 @@ public final class ProviderFactory {
         return JAXB_PROVIDER_NAME.equals(clsName) || JSON_PROVIDER_NAME.equals(clsName);
     }
     
+    public List<ProviderInfo<ContainerRequestFilter>> getGlobalContainerRequestFilters(boolean
preMatch) {
+        return Collections.unmodifiableList(
+            preMatch ? globalPreContainerRequestFilters : globalContainerRequestFilters);
+    }
+    
+    public List<ProviderInfo<ContainerResponseFilter>> getGlobalContainerResponseFilters(boolean
preMatch) {
+        return Collections.unmodifiableList(
+            preMatch ? globalPreContainerResponseFilters : globalContainerResponseFilters);
+    }
+    
+    public List<ProviderInfo<ContainerRequestFilter>> getBoundContainerRequestFilters(List<String>
names) {
+        return getBoundContainerFilters(boundContainerRequestFilters, names);
+    }
+    
+    public List<ProviderInfo<ContainerResponseFilter>> getBoundContainerResponseFilters(List<String>
names) {
+        return getBoundContainerFilters(boundContainerResponseFilters, names);
+    }
+    
+    private static <T> List<ProviderInfo<T>> getBoundContainerFilters(Map<String,
ProviderInfo<T>> filters,
+                                                                             List<String>
names) {
+        List<ProviderInfo<T>> list = new LinkedList<ProviderInfo<T>>();
+        for (String name : names) {
+            ProviderInfo<T> filter = filters.get(name);
+            if (filter != null) {
+                list.add(filter);
+            }
+        }
+        return list;
+    }
+    
     public List<ProviderInfo<RequestHandler>> getRequestHandlers() {
         List<ProviderInfo<RequestHandler>> handlers = null;
         if (requestHandlers.size() == 0) {
@@ -530,6 +590,16 @@ public final class ProviderFactory {
                 responseHandlers.add(new ProviderInfo<ResponseHandler>((ResponseHandler)o,
bus)); 
             }
             
+            if (ContainerRequestFilter.class.isAssignableFrom(oClass)) {
+                addContainerRequestFilter(
+                   new ProviderInfo<ContainerRequestFilter>((ContainerRequestFilter)o,
bus));
+            }
+            
+            if (ContainerResponseFilter.class.isAssignableFrom(oClass)) {
+                addContainerResponseFilter(
+                   new ProviderInfo<ContainerResponseFilter>((ContainerResponseFilter)o,
bus)); 
+            }
+            
             if (ExceptionMapper.class.isAssignableFrom(oClass)) {
                 exceptionMappers.add(new ProviderInfo<ExceptionMapper<?>>((ExceptionMapper<?>)o,
bus)); 
             }
@@ -547,26 +617,60 @@ public final class ProviderFactory {
         sortContextResolvers();
         
         injectContextProxies(messageReaders, messageWriters, contextResolvers, 
-        			requestHandlers, responseHandlers,
-                       exceptionMappers);
+            requestHandlers, responseHandlers, exceptionMappers,
+            boundContainerRequestFilters.values(), globalPreContainerRequestFilters, globalContainerRequestFilters,
+            boundContainerResponseFilters.values(), globalPreContainerResponseFilters, globalContainerResponseFilters);
     }
 //CHECKSTYLE:ON
     
+    private void addContainerRequestFilter(ProviderInfo<ContainerRequestFilter> p)
{
+        addContainerFilter(p, boundContainerRequestFilters, 
+                           globalPreContainerRequestFilters, globalContainerRequestFilters);
+    }
+    
+    private void addContainerResponseFilter(ProviderInfo<ContainerResponseFilter> p)
{
+        addContainerFilter(p, boundContainerResponseFilters, 
+                           globalPreContainerResponseFilters, globalContainerResponseFilters);
+    }
+    
+    private static <T> void addContainerFilter(ProviderInfo<T> p,
+                                               Map<String, ProviderInfo<T>> boundFilters,
+                                               List<ProviderInfo<T>> globalPreFilters,
+                                               List<ProviderInfo<T>> globalPostFilters)
{
+        T filter = p.getProvider();
+        Annotation[] annotations = filter.getClass().getAnnotations();
+        List<String> names = AnnotationUtils.getNameBindings(annotations);
+        if (!names.isEmpty()) {
+            for (String name : names) {
+                boundFilters.put(name, p);
+            }
+        } else {
+            boolean isPreMatch = AnnotationUtils.getAnnotation(annotations, PreMatching.class)
!= null;
+            if (isPreMatch) {
+                globalPreFilters.add(p);
+            } else {
+                globalPostFilters.add(p);
+            }
+        }
+    }
+    
     static void injectContextValues(ProviderInfo<?> pi, Message m) {
         if (m != null) {
-            InjectionUtils.injectContextFields(pi.getProvider(), pi, m);
-            InjectionUtils.injectContextMethods(pi.getProvider(), pi, m);
+            InjectionUtils.injectContexts(pi.getProvider(), pi, m);
         }
     }
     
-    void injectContextProxies(List<?> ... providerLists) {
-        for (List<?> list : providerLists) {
-            List<ProviderInfo<?>> l2 = CastUtils.cast(list);
+    void injectContextProxies(Collection<?> ... providerLists) {
+        for (Collection<?> list : providerLists) {
+            Collection<ProviderInfo<?>> l2 = CastUtils.cast(list);
             for (ProviderInfo<?> pi : l2) {
                 if (ProviderFactory.SHARED_FACTORY == this && isJaxbBasedProvider(pi.getProvider()))
{
                     continue;
                 }
-                InjectionUtils.injectContextProxies(pi, pi.getProvider());
+                if (pi.contextsAvailable()) {
+                    InjectionUtils.injectContextProxies(pi, pi.getProvider());
+                    injectedProviders.add(pi);
+                }
             }
         }
     }
@@ -804,15 +908,13 @@ public final class ProviderFactory {
         return requestPreprocessor;
     }
     
+    public void clearExceptionMapperProxies() {
+        clearProxies(exceptionMappers);
+    }
+    
     public void clearThreadLocalProxies() {
-        clearProxies(messageReaders,
-                     messageWriters,
-                     jaxbReaders,
-                     jaxbWriters,
-                     contextResolvers,
-                     requestHandlers,
-                     responseHandlers,
-                     exceptionMappers);
+        clearProxies(injectedProviders);
+        
         if (application != null) {
             application.clearThreadLocalProxies();
         }
@@ -821,9 +923,9 @@ public final class ProviderFactory {
         }
     }
     
-    void clearProxies(List<?> ...lists) {
-        for (List<?> list : lists) {
-            List<ProviderInfo<?>> l2 = CastUtils.cast(list);
+    void clearProxies(Collection<?> ...lists) {
+        for (Collection<?> list : lists) {
+            Collection<ProviderInfo<?>> l2 = CastUtils.cast(list);
             for (ProviderInfo<?> pi : l2) {
                 pi.clearThreadLocalProxies();
             }
@@ -834,9 +936,16 @@ public final class ProviderFactory {
         messageReaders.clear();
         messageWriters.clear();
         contextResolvers.clear();
+        contextProviders.clear();
         exceptionMappers.clear();
         requestHandlers.clear();
         responseHandlers.clear();
+        globalContainerRequestFilters.clear();
+        globalContainerResponseFilters.clear();
+        boundContainerRequestFilters.clear();
+        boundContainerResponseFilters.clear();
+        globalPreContainerRequestFilters.clear();
+        globalPreContainerResponseFilters.clear();
         paramHandlers.clear();
         responseExceptionMappers.clear();
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java?rev=1381654&r1=1381653&r2=1381654&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
Thu Sep  6 15:54:27 2012
@@ -21,7 +21,10 @@ package org.apache.cxf.jaxrs.utils;
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
+import java.util.Collections;
 import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.ResourceBundle;
 import java.util.Set;
 import java.util.logging.Logger;
@@ -37,6 +40,7 @@ import javax.ws.rs.FormParam;
 import javax.ws.rs.HeaderParam;
 import javax.ws.rs.HttpMethod;
 import javax.ws.rs.MatrixParam;
+import javax.ws.rs.NameBinding;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
@@ -118,6 +122,20 @@ public final class AnnotationUtils {
         return classes;
     }
 
+    public static List<String> getNameBindings(Annotation[] targetAnns) {
+        if (targetAnns.length == 0) {
+            return Collections.emptyList();
+        }
+        List<String> names = new LinkedList<String>();
+        for (Annotation a : targetAnns) {
+            NameBinding nb = a.annotationType().getAnnotation(NameBinding.class);
+            if (nb != null) {
+                names.add(a.getClass().getName());
+            }
+        }
+        return names;
+    }
+    
     public static boolean isContextClass(Class<?> contextClass) {
         return CONTEXT_CLASSES.contains(contextClass);
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1381654&r1=1381653&r2=1381654&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Thu Sep  6 15:54:27 2012
@@ -905,7 +905,7 @@ public final class InjectionUtils {
     public static void injectContextProxiesAndApplication(AbstractResourceInfo cri, 
                                                           Object instance,
                                                           Application app) {
-        if (!cri.isSingleton()) {
+        if (!cri.contextsAvailable() || !cri.isSingleton()) {
             return;
         }
         
@@ -942,8 +942,10 @@ public final class InjectionUtils {
     public static void injectContexts(Object requestObject,
                                  AbstractResourceInfo resource,
                                  Message message) {
-        injectContextMethods(requestObject, resource, message);
-        injectContextFields(requestObject, resource, message);
+        if (resource.contextsAvailable()) {
+            injectContextMethods(requestObject, resource, message);
+            injectContextFields(requestObject, resource, message);
+        }
     }
     
     @SuppressWarnings("unchecked")
@@ -975,8 +977,6 @@ public final class InjectionUtils {
         }
     }
     
-    // TODO : should we have context and resource fields be treated as context fields ?
-    
     public static void injectContextFields(Object o,
                                            AbstractResourceInfo cri,
                                            Message m) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1381654&r1=1381653&r2=1381654&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Thu
Sep  6 15:54:27 2012
@@ -1260,9 +1260,8 @@ public final class JAXRSUtils {
     
     @SuppressWarnings("unchecked")
     public static <T extends Throwable> Response convertFaultToResponse(T ex, Message
inMessage) {
-        
-        ExceptionMapper<T> mapper = 
-            ProviderFactory.getInstance(inMessage).createExceptionMapper(ex, inMessage);
+        ProviderFactory factory = ProviderFactory.getInstance(inMessage);
+        ExceptionMapper<T> mapper = factory.createExceptionMapper(ex, inMessage);
         if (mapper != null) {
             if (ex.getClass() == WebApplicationException.class 
                 && mapper.getClass() != WebApplicationExceptionMapper.class) {
@@ -1270,7 +1269,6 @@ public final class JAXRSUtils {
                 Class<?> exceptionClass = getWebApplicationExceptionClass(webEx.getResponse(),

                                                                           WebApplicationException.class);
                 if (exceptionClass != WebApplicationException.class) {
-                    //TODO: consider using switch statements
                     try {
                         Constructor<?> ctr = exceptionClass.getConstructor(Response.class);
                         ex = (T)ctr.newInstance(webEx.getResponse());
@@ -1280,11 +1278,14 @@ public final class JAXRSUtils {
                     }
                 }
             }
+            
             try {
                 return mapper.toResponse(ex);
             } catch (Exception mapperEx) {
                 mapperEx.printStackTrace();
                 return Response.serverError().build();
+            } finally {
+                factory.clearExceptionMapperProxies();
             }
         }
         

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java?rev=1381654&r1=1381653&r2=1381654&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
Thu Sep  6 15:54:27 2012
@@ -113,6 +113,7 @@ public class JAXRSLocalTransportTest ext
     @Test
     public void testWebClientPipedDispatch() throws Exception {
         WebClient localClient = WebClient.create("local://books");
+        localClient.accept("text/xml");
         localClient.path("bookstore/books");
         Book book = localClient.post(new Book("New", 124L), Book.class);
         assertEquals(124L, book.getId());



Mime
View raw message