cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1382959 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ rt/frontend/jaxrs/src/main/java/org...
Date Mon, 10 Sep 2012 16:09:36 GMT
Author: sergeyb
Date: Mon Sep 10 16:09:36 2012
New Revision: 1382959

URL: http://svn.apache.org/viewvc?rev=1382959&view=rev
Log:
[CXF-4455] Prototyping the support for new out filters

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerResponseContextImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
    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/provider/ProviderFactory.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/BookServer20.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=1382959&r1=1382958&r2=1382959&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java Mon Sep
10 16:09:36 2012
@@ -118,29 +118,30 @@ public class JAXRSInvoker extends Abstra
     @SuppressWarnings("unchecked")
     public Object invoke(Exchange exchange, Object request, Object resourceObject) {
 
-        OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
-        ClassResourceInfo cri = ori.getClassResourceInfo();
+        final OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
+        final ClassResourceInfo cri = ori.getClassResourceInfo();
+        final Message inMessage = exchange.getInMessage();
+        final ProviderFactory providerFactory = ProviderFactory.getInstance(inMessage);
 
         boolean wasSuspended = exchange.remove(REQUEST_WAS_SUSPENDED) != null;
         
         if (!wasSuspended) {
-            pushOntoStack(ori, ClassHelper.getRealClass(resourceObject), exchange.getInMessage());
+            pushOntoStack(ori, ClassHelper.getRealClass(resourceObject), inMessage);
                     
             if (cri.isRoot()) {
                 Object realResourceObject = ClassHelper.getRealObject(resourceObject);
-                JAXRSUtils.injectParameters(ori, realResourceObject,
-                                         exchange.getInMessage());
+                JAXRSUtils.injectParameters(ori, realResourceObject, inMessage);
     
                 InjectionUtils.injectContexts(realResourceObject,
                                               ori.getClassResourceInfo(),
-                                              exchange.getInMessage());
+                                              inMessage);
                 
                 ProviderInfo<?> appProvider = 
                     (ProviderInfo<?>)exchange.getEndpoint().get(Application.class.getName());
                 if (appProvider != null) {
                     InjectionUtils.injectContexts(appProvider.getProvider(),
                                                   appProvider,
-                                                  exchange.getInMessage());
+                                                  inMessage);
                 }
                 
             }
@@ -160,7 +161,7 @@ public class JAXRSInvoker extends Abstra
         Object result = null;
         ClassLoaderHolder contextLoader = null;
         try {
-            if (setServiceLoaderAsContextLoader(exchange.getInMessage())) {
+            if (setServiceLoaderAsContextLoader(inMessage)) {
                 contextLoader = ClassLoaderUtils
                     .setThreadContextClassloader(resourceObject.getClass().getClassLoader());
             }
@@ -179,7 +180,7 @@ public class JAXRSInvoker extends Abstra
             Response excResponse = JAXRSUtils.convertFaultToResponse(ex.getCause(), 
                                                                      exchange.getInMessage());
             if (excResponse == null) {
-                ProviderFactory.getInstance(exchange.getInMessage()).clearThreadLocalProxies();
+                providerFactory.clearThreadLocalProxies();
                 ClassResourceInfo criRoot =
                     (ClassResourceInfo)exchange.get(JAXRSUtils.ROOT_RESOURCE_CLASS);
                 if (criRoot != null) {
@@ -231,9 +232,9 @@ public class JAXRSInvoker extends Abstra
                                                          contentType,
                                                          acceptContentType,
                                                          true);
-                
-                if (!ori.getNameBindings().isEmpty() 
-                    && JAXRSUtils.runContainerFilters(ProviderFactory.getInstance(exchange.getInMessage()),
+                // Global and name-bound request filters
+                if (JAXRSUtils.runContainerRequestFilters(
+                                                      providerFactory,
                                                       exchange.getInMessage(),
                                                       false, ori.getNameBindings())) {
                     return new MessageContentsList(exchange.get(Response.class));

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java?rev=1382959&r1=1382958&r2=1382959&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java
Mon Sep 10 16:09:36 2012
@@ -50,15 +50,18 @@ public class ContainerRequestContextImpl
     private Message m;
     private Map<String, Object> props;
     private boolean preMatch;
-    public ContainerRequestContextImpl(Message message, boolean preMatch) {
+    private boolean responseContext;
+    public ContainerRequestContextImpl(Message message, boolean preMatch, boolean responseContext)
{
         this.m = message;
         this.props = CastUtils.cast((Map<?, ?>)message.get(PROPERTY_KEY));
         this.h = new HttpHeadersImpl(message);
         this.preMatch = preMatch;
+        this.responseContext = responseContext;
     }
     
     @Override
     public void abortWith(Response response) {
+        checkContext();
         m.getExchange().put(Response.class, response);
     }
 
@@ -172,11 +175,13 @@ public class ContainerRequestContextImpl
 
     @Override
     public void setEntityStream(InputStream is) {
+        checkContext();
         m.put(InputStream.class, is);
     }
 
     @Override
     public void setMethod(String method) throws IllegalStateException {
+        checkContext();
         m.put(Message.HTTP_REQUEST_METHOD, method);
 
     }
@@ -217,4 +222,10 @@ public class ContainerRequestContextImpl
     private HttpHeaders getHttpHeaders() {
         return h != null ? h : new HttpHeadersImpl(m);
     }
+    
+    private void checkContext() {
+        if (responseContext) {
+            throw new IllegalStateException();
+        }
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerResponseContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerResponseContextImpl.java?rev=1382959&r1=1382958&r2=1382959&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerResponseContextImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerResponseContextImpl.java
Mon Sep 10 16:09:36 2012
@@ -20,6 +20,7 @@ package org.apache.cxf.jaxrs.impl;
 
 import java.io.OutputStream;
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
 import java.lang.reflect.Type;
 import java.net.URI;
 import java.util.Date;
@@ -34,176 +35,172 @@ import javax.ws.rs.core.Link.Builder;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.NewCookie;
+import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.StatusType;
 
+import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.message.Message;
+
 public class ContainerResponseContextImpl implements ContainerResponseContext {
 
+    private Message m;
+    private Response r;
+    private OperationResourceInfo ori;
+    public ContainerResponseContextImpl(Response r, 
+                                        Message m,
+                                        OperationResourceInfo ori) {
+        this.m = m;
+        this.r = r;
+        this.ori = ori;
+    }
+    
     @Override
     public Set<String> getAllowedMethods() {
-        // TODO Auto-generated method stub
-        return null;
+        return r.getAllowedMethods();
     }
 
     @Override
     public Map<String, NewCookie> getCookies() {
-        // TODO Auto-generated method stub
-        return null;
+        return r.getCookies();
     }
 
     @Override
     public Date getDate() {
-        // TODO Auto-generated method stub
-        return null;
+        return r.getDate();
     }
 
     @Override
     public Object getEntity() {
-        // TODO Auto-generated method stub
-        return null;
+        return r.getEntity();
     }
 
     @Override
     public Annotation[] getEntityAnnotations() {
-        // TODO Auto-generated method stub
-        return null;
+        Method method = ori == null ? null : ori.getAnnotatedMethod();
+        return method == null ? null : method.getAnnotations();
     }
 
     @Override
     public Class<?> getEntityClass() {
-        // TODO Auto-generated method stub
-        return null;
+        return ori == null ? null : ori.getMethodToInvoke().getReturnType();
     }
 
     @Override
-    public OutputStream getEntityStream() {
-        // TODO Auto-generated method stub
-        return null;
+    public Type getEntityType() {
+        return ori == null ? null : ori.getMethodToInvoke().getGenericReturnType();
     }
-
+    
     @Override
-    public EntityTag getEntityTag() {
-        // TODO Auto-generated method stub
-        return null;
+    public OutputStream getEntityStream() {
+        return m.get(OutputStream.class);
     }
 
     @Override
-    public Type getEntityType() {
-        // TODO Auto-generated method stub
-        return null;
+    public EntityTag getEntityTag() {
+        return r.getEntityTag();
     }
 
     @Override
-    public String getHeaderString(String arg0) {
-        // TODO Auto-generated method stub
-        return null;
+    public String getHeaderString(String name) {
+        return r.getHeaderString(name);
     }
 
     @Override
     public MultivaluedMap<String, Object> getHeaders() {
-        // TODO Auto-generated method stub
-        return null;
+        return r.getMetadata();
     }
 
     @Override
     public Locale getLanguage() {
-        // TODO Auto-generated method stub
-        return null;
+        return r.getLanguage();
     }
 
     @Override
     public Date getLastModified() {
-        // TODO Auto-generated method stub
-        return null;
+        return r.getLastModified();
     }
 
     @Override
     public int getLength() {
-        // TODO Auto-generated method stub
-        return 0;
+        return r.getLength();
     }
 
     @Override
-    public Link getLink(String arg0) {
-        // TODO Auto-generated method stub
-        return null;
+    public Link getLink(String rel) {
+        return r.getLink(rel);
     }
 
     @Override
-    public Builder getLinkBuilder(String arg0) {
-        // TODO Auto-generated method stub
-        return null;
+    public Builder getLinkBuilder(String rel) {
+        return r.getLinkBuilder(rel);
     }
 
     @Override
     public Set<Link> getLinks() {
-        // TODO Auto-generated method stub
-        return null;
+        return r.getLinks();
     }
 
     @Override
     public URI getLocation() {
-        // TODO Auto-generated method stub
-        return null;
+        return r.getLocation();
     }
 
     @Override
     public MediaType getMediaType() {
-        // TODO Auto-generated method stub
-        return null;
+        return r.getMediaType();
     }
 
     @Override
     public int getStatus() {
-        // TODO Auto-generated method stub
-        return 0;
+        return r.getStatus();
     }
 
     @Override
     public StatusType getStatusInfo() {
-        // TODO Auto-generated method stub
-        return null;
+        return r.getStatusInfo();
     }
 
     @Override
     public MultivaluedMap<String, String> getStringHeaders() {
-        // TODO Auto-generated method stub
-        return null;
+        //TODO: right now this view is not modifiable
+        return r.getStringHeaders();
     }
 
     @Override
     public boolean hasEntity() {
-        // TODO Auto-generated method stub
-        return false;
+        return r.hasEntity();
     }
 
     @Override
-    public boolean hasLink(String arg0) {
-        // TODO Auto-generated method stub
-        return false;
+    public boolean hasLink(String rel) {
+        return r.hasLink(rel);
     }
 
     @Override
-    public void setEntity(Object arg0, Annotation[] arg1, MediaType arg2) {
-        // TODO Auto-generated method stub
+    public void setEntityStream(OutputStream os) {
+        m.put(OutputStream.class, os);
 
     }
 
     @Override
-    public void setEntityStream(OutputStream arg0) {
-        // TODO Auto-generated method stub
-
+    public void setEntity(Object entity, Annotation[] anns, MediaType mt) {
+        ((ResponseImpl)r).setEntity(entity);
+        updateMessageResponse();
+        //TODO: review this code after API gets finalized
     }
-
+    
     @Override
-    public void setStatus(int arg0) {
-        // TODO Auto-generated method stub
-
+    public void setStatus(int status) {
+        ((ResponseImpl)r).setStatus(status);
+        updateMessageResponse();
     }
 
     @Override
-    public void setStatusInfo(StatusType arg0) {
-        // TODO Auto-generated method stub
-
+    public void setStatusInfo(StatusType status) {
+        setStatus(status.getStatusCode());
     }
 
+    private void updateMessageResponse() {
+        m.put(Response.class, r);
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java?rev=1382959&r1=1382958&r2=1382959&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
Mon Sep 10 16:09:36 2012
@@ -52,7 +52,7 @@ import org.apache.cxf.jaxrs.utils.HttpUt
 import org.apache.cxf.message.Message;
 
 public final class ResponseImpl extends Response {
-    private final int status;
+    private int status;
     private Object entity;
     private MultivaluedMap<String, Object> metadata;
     
@@ -72,6 +72,14 @@ public final class ResponseImpl extends 
     void addMetadata(MultivaluedMap<String, Object> meta) { 
         this.metadata = meta;
     }
+    
+    void setStatus(int s) { 
+        this.status = s;
+    }
+    
+    void setEntity(Object entity) { 
+        this.entity = entity;
+    }
 
     //TODO: This method is needed because on the client side the
     // Response processing is done after the chain completes, thus

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=1382959&r1=1382958&r2=1382959&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
Mon Sep 10 16:09:36 2012
@@ -118,7 +118,8 @@ public class JAXRSInInterceptor extends 
             }
         }
         
-        if (JAXRSUtils.runContainerFilters(providerFactory, message, true, null)) {
+        // Global pre-match request filters
+        if (JAXRSUtils.runContainerRequestFilters(providerFactory, message, true, null))
{
             return;
         }
         
@@ -163,10 +164,6 @@ public class JAXRSInInterceptor extends 
             throw new WebApplicationException(resp);
         }
 
-        if (JAXRSUtils.runContainerFilters(providerFactory, message, false, null)) {
-            return;
-        }
-        
         message.getExchange().put(JAXRSUtils.ROOT_RESOURCE_CLASS, resource);
 
         String httpMethod = HttpUtils.getProtocolHeader(message, Message.HTTP_REQUEST_METHOD,
"POST");
@@ -211,8 +208,8 @@ public class JAXRSInInterceptor extends 
             }
         }
 
-        if (!ori.getNameBindings().isEmpty() 
-            && JAXRSUtils.runContainerFilters(providerFactory, message, false, ori.getNameBindings()))
{
+        // Global and name-bound request filters
+        if (JAXRSUtils.runContainerRequestFilters(providerFactory, message, false, ori.getNameBindings()))
{
             return;
         }
         

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=1382959&r1=1382958&r2=1382959&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
Mon Sep 10 16:09:36 2012
@@ -79,9 +79,9 @@ public class JAXRSOutInterceptor extends
     }
 
     public void handleMessage(Message message) {
-        
+        ProviderFactory providerFactory = ProviderFactory.getInstance(message);
         try {
-            processResponse(message);
+            processResponse(providerFactory, message);
         } finally {
             Object rootInstance = message.getExchange().remove(JAXRSUtils.ROOT_INSTANCE);
             Object rootProvider = message.getExchange().remove(JAXRSUtils.ROOT_PROVIDER);
@@ -93,7 +93,7 @@ public class JAXRSOutInterceptor extends
                                 + tex.getMessage());
                 }
             }
-            ProviderFactory.getInstance(message).clearThreadLocalProxies();
+            providerFactory.clearThreadLocalProxies();
             ClassResourceInfo cri =
                 (ClassResourceInfo)message.getExchange().get(JAXRSUtils.ROOT_RESOURCE_CLASS);
             if (cri != null) {
@@ -104,7 +104,7 @@ public class JAXRSOutInterceptor extends
 
     }
     
-    private void processResponse(Message message) {
+    private void processResponse(ProviderFactory providerFactory, Message message) {
         
         if (isResponseAlreadyHandled(message)) {
             return;
@@ -129,7 +129,21 @@ public class JAXRSOutInterceptor extends
         Exchange exchange = message.getExchange();
         OperationResourceInfo ori = (OperationResourceInfo)exchange.get(OperationResourceInfo.class
             .getName());
-
+        
+        // Global post-match and name-bound response filters
+        if (ori != null) {
+            JAXRSUtils.runContainerResponseFilters(providerFactory, response, message, ori,
false);
+            Response updatedResponse = message.get(Response.class);
+            if (updatedResponse != null) {
+                response = updatedResponse;
+            }
+        }
+        
+        // TODO: enable or remove, depending on the API clarifications
+        // Global pre-match response filters 
+        // JAXRSUtils.runContainerResponseFilters(providerFactory, response, message, ori,
true);
+        
+        
         List<ProviderInfo<ResponseHandler>> handlers = 
             ProviderFactory.getInstance(message).getResponseHandlers();
         for (ProviderInfo<ResponseHandler> rh : handlers) {

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=1382959&r1=1382958&r2=1382959&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
Mon Sep 10 16:09:36 2012
@@ -114,12 +114,12 @@ public final class ProviderFactory {
         new ArrayList<ProviderInfo<ContainerRequestFilter>>(1);
     private List<ProviderInfo<ContainerRequestFilter>> globalPreContainerRequestFilters
= 
         new ArrayList<ProviderInfo<ContainerRequestFilter>>(1);
+    private Map<String, ProviderInfo<ContainerRequestFilter>> boundContainerRequestFilters
= 
+        new LinkedHashMap<String, ProviderInfo<ContainerRequestFilter>>();
     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>>();
     
@@ -466,31 +466,43 @@ 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<ContainerRequestFilter>> getPreMatchContainerRequestFilters()
{
+        return Collections.unmodifiableList(globalPreContainerRequestFilters);
     }
     
-    public List<ProviderInfo<ContainerResponseFilter>> getGlobalContainerResponseFilters(boolean
preMatch) {
-        return Collections.unmodifiableList(
-            preMatch ? globalPreContainerResponseFilters : globalContainerResponseFilters);
+    public List<ProviderInfo<ContainerRequestFilter>> getPostMatchContainerRequestFilters(List<String>
names) {
+        return getPostMatchContainerFilters(globalContainerRequestFilters, 
+                                            boundContainerRequestFilters, 
+                                            names);
     }
     
-    public List<ProviderInfo<ContainerRequestFilter>> getBoundContainerRequestFilters(List<String>
names) {
-        return getBoundContainerFilters(boundContainerRequestFilters, names);
+    public List<ProviderInfo<ContainerResponseFilter>> getPreMatchContainerResponseFilters()
{
+        return Collections.unmodifiableList(globalPreContainerResponseFilters);
     }
     
-    public List<ProviderInfo<ContainerResponseFilter>> getBoundContainerResponseFilters(List<String>
names) {
-        return getBoundContainerFilters(boundContainerResponseFilters, names);
+    public List<ProviderInfo<ContainerResponseFilter>> getPostMatchContainerResponseFilters(List<String>
names) {
+        return getPostMatchContainerFilters(globalContainerResponseFilters, 
+                                            boundContainerResponseFilters, 
+                                            names);
     }
     
-    private static <T> List<ProviderInfo<T>> getBoundContainerFilters(Map<String,
ProviderInfo<T>> filters,
-                                                                             List<String>
names) {
+    private static <T> List<ProviderInfo<T>> getPostMatchContainerFilters(List<ProviderInfo<T>>
globalFilters,
+                                                                         Map<String, ProviderInfo<T>>
boundFilters,
+                                                                         List<String>
names) {
+        
+        if (globalFilters.isEmpty() && boundFilters.isEmpty()) {
+            return Collections.emptyList();
+        }
+        
         List<ProviderInfo<T>> list = new LinkedList<ProviderInfo<T>>();
-        for (String name : names) {
-            ProviderInfo<T> filter = filters.get(name);
-            if (filter != null) {
-                list.add(filter);
+        list.addAll(globalFilters);
+
+        if (names != null) {
+            for (String name : names) {
+                ProviderInfo<T> filter = boundFilters.get(name);
+                if (filter != null) {
+                    list.add(filter);
+                }
             }
         }
         return list;
@@ -612,6 +624,7 @@ public final class ProviderFactory {
                 paramHandlers.add(new ProviderInfo<ParameterHandler<?>>((ParameterHandler<?>)o,
bus)); 
             }
         }
+        //TODO: BindingPriority has to be checked too
         sortReaders();
         sortWriters();
         sortContextResolvers();

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=1382959&r1=1382958&r2=1382959&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Mon
Sep 10 16:09:36 2012
@@ -64,6 +64,8 @@ import javax.ws.rs.ServiceUnavailableExc
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.container.ContainerRequestContext;
 import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Cookie;
 import javax.ws.rs.core.HttpHeaders;
@@ -94,6 +96,7 @@ import org.apache.cxf.jaxrs.ext.Protocol
 import org.apache.cxf.jaxrs.ext.ProtocolHeadersImpl;
 import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
 import org.apache.cxf.jaxrs.impl.ContainerRequestContextImpl;
+import org.apache.cxf.jaxrs.impl.ContainerResponseContextImpl;
 import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
 import org.apache.cxf.jaxrs.impl.HttpServletResponseFilter;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
@@ -1336,12 +1339,12 @@ public final class JAXRSUtils {
         return XMLUtils.convertStringToQName(name, "");
     }
     
-    public static boolean runContainerFilters(ProviderFactory pf, Message m, boolean preMatch,

+    public static boolean runContainerRequestFilters(ProviderFactory pf, Message m, boolean
preMatch, 
                                               List<String> names) {
-        List<ProviderInfo<ContainerRequestFilter>> containerFilters = names ==
null 
-            ? pf.getGlobalContainerRequestFilters(preMatch) : pf.getBoundContainerRequestFilters(names);
+        List<ProviderInfo<ContainerRequestFilter>> containerFilters = preMatch

+            ? pf.getPreMatchContainerRequestFilters() : pf.getPostMatchContainerRequestFilters(names);
         if (!containerFilters.isEmpty()) {
-            ContainerRequestContext context = new ContainerRequestContextImpl(m, true);
+            ContainerRequestContext context = new ContainerRequestContextImpl(m, preMatch,
false);
             for (ProviderInfo<ContainerRequestFilter> filter : containerFilters) {
                 try {
                     filter.getProvider().filter(context);
@@ -1355,4 +1358,29 @@ public final class JAXRSUtils {
         }
         return false;
     }
+    
+    public static void runContainerResponseFilters(ProviderFactory pf,
+                                                   Response r,
+                                                   Message m, 
+                                                   OperationResourceInfo ori,
+                                                   boolean preMatch) {
+        List<ProviderInfo<ContainerResponseFilter>> containerFilters = preMatch

+            ? pf.getPreMatchContainerResponseFilters() 
+            : pf.getPostMatchContainerResponseFilters(ori == null ? null : ori.getNameBindings());
+        if (!containerFilters.isEmpty()) {
+            ContainerRequestContext requestContext = 
+                new ContainerRequestContextImpl(m.getExchange().getInMessage(), 
+                                               preMatch,
+                                               true);
+            ContainerResponseContext responseContext = 
+                new ContainerResponseContextImpl(r, m, ori);
+            for (ProviderInfo<ContainerResponseFilter> filter : containerFilters) {
+                try {
+                    filter.getProvider().filter(requestContext, responseContext);
+                } catch (IOException ex) {
+                    throw new WebApplicationException(ex);
+                }
+            }
+        }
+    }
 }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java?rev=1382959&r1=1382958&r2=1382959&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
Mon Sep 10 16:09:36 2012
@@ -20,11 +20,18 @@
 package org.apache.cxf.systest.jaxrs;
 
 import java.io.IOException;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.ws.rs.NameBinding;
 import javax.ws.rs.container.ContainerRequestContext;
 import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
@@ -47,6 +54,8 @@ public class BookServer20 extends Abstra
         List<Object> providers = new ArrayList<Object>();
         
         providers.add(new PreMatchContainerRequestFilter());
+        providers.add(new PostMatchContainerResponseFilter());
+        providers.add(new PostMatchContainerResponseFilter2());
         sf.setProviders(providers);
         sf.setResourceProvider(BookStore.class,
                                new SingletonResourceProvider(new BookStore(), true));
@@ -82,4 +91,32 @@ public class BookServer20 extends Abstra
         }
         
     }
+    
+    public static class PostMatchContainerResponseFilter implements ContainerResponseFilter
{
+
+        @Override
+        public void filter(ContainerRequestContext requestContext,
+                           ContainerResponseContext responseContext) throws IOException {
+            responseContext.getHeaders().add("Response", "OK");
+        }
+        
+    }
+    
+    @CustomHeaderAdded
+    public static class PostMatchContainerResponseFilter2 implements ContainerResponseFilter
{
+
+        @Override
+        public void filter(ContainerRequestContext requestContext,
+                           ContainerResponseContext responseContext) throws IOException {
+            responseContext.getHeaders().add("Custom", "custom");
+        }
+        
+    }
+    
+    @Target({ ElementType.TYPE, ElementType.METHOD })
+    @Retention(value = RetentionPolicy.RUNTIME)
+    @NameBinding
+    public @interface CustomHeaderAdded { 
+        
+    }
 }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1382959&r1=1382958&r2=1382959&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Mon
Sep 10 16:09:36 2012
@@ -82,6 +82,7 @@ import org.apache.cxf.jaxrs.ext.search.S
 import org.apache.cxf.jaxrs.ext.xml.XMLInstruction;
 import org.apache.cxf.jaxrs.ext.xml.XSISchemaLocation;
 import org.apache.cxf.phase.PhaseInterceptorChain;
+import org.apache.cxf.systest.jaxrs.BookServer20.CustomHeaderAdded;
 
 @Path("/bookstore")
 @GZIP(threshold = 1)
@@ -427,6 +428,7 @@ public class BookStore {
     
     @GET
     @Path("/bookheaders/simple/")
+    @CustomHeaderAdded
     public Book getBookByHeaderSimple(@HeaderParam("BOOK") String header) throws Exception
{
         return doGetBook(header);
     }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java?rev=1382959&r1=1382958&r2=1382959&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
Mon Sep 10 16:09:36 2012
@@ -19,6 +19,8 @@
 
 package org.apache.cxf.systest.jaxrs;
 
+import javax.ws.rs.core.Response;
+
 import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 
@@ -40,5 +42,8 @@ public class JAXRS20ClientServerBookTest
         WebClient wc = WebClient.create(address);
         Book book = wc.get(Book.class);
         assertEquals(123L, book.getId());
+        Response response = wc.getResponse();
+        assertEquals("OK", response.getHeaderString("Response"));
+        assertEquals("custom", response.getHeaderString("Custom"));
     }
 }



Mime
View raw message