cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1382087 - 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 Fri, 07 Sep 2012 16:33:56 GMT
Author: sergeyb
Date: Fri Sep  7 16:33:56 2012
New Revision: 1382087

URL: http://svn.apache.org/viewvc?rev=1382087&view=rev
Log:
[CXF-4455] Initial support for new request filters

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java
  (with props)
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerResponseContextImpl.java
  (with props)
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
  (with props)
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
  (with props)
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/MetadataMap.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/model/AbstractResourceInfo.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=1382087&r1=1382086&r2=1382087&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 Fri Sep
 7 16:33:56 2012
@@ -231,7 +231,13 @@ public class JAXRSInvoker extends Abstra
                                                          contentType,
                                                          acceptContentType,
                                                          true);
-
+                
+                if (!ori.getNameBindings().isEmpty() 
+                    && JAXRSUtils.runContainerFilters(ProviderFactory.getInstance(exchange.getInMessage()),
+                                                      exchange.getInMessage(),
+                                                      false, ori.getNameBindings())) {
+                    return new MessageContentsList(exchange.get(Response.class));
+                }                
 
                 exchange.put(OperationResourceInfo.class, subOri);
                 msg.put(URITemplate.TEMPLATE_PARAMETERS, values);

Added: 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=1382087&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java
Fri Sep  7 16:33:56 2012
@@ -0,0 +1,220 @@
+/**
+ * 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 org.apache.cxf.jaxrs.impl;
+
+import java.io.InputStream;
+import java.net.URI;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.core.Cookie;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.SecurityContext;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.message.Message;
+
+public class ContainerRequestContextImpl implements ContainerRequestContext {
+
+    private static final String PROPERTY_KEY = "jaxrs.filter.properties";
+    private static final String ENDPOINT_ADDRESS_PROPERTY = "org.apache.cxf.transport.endpoint.address";
+    
+    private HttpHeaders h;
+    private Message m;
+    private Map<String, Object> props;
+    private boolean preMatch;
+    public ContainerRequestContextImpl(Message message, boolean preMatch) {
+        this.m = message;
+        this.props = CastUtils.cast((Map<?, ?>)message.get(PROPERTY_KEY));
+        this.h = new HttpHeadersImpl(message);
+        this.preMatch = preMatch;
+    }
+    
+    @Override
+    public void abortWith(Response response) {
+        m.getExchange().put(Response.class, response);
+    }
+
+    @Override
+    public List<Locale> getAcceptableLanguages() {
+        return getHttpHeaders().getAcceptableLanguages();
+    }
+
+    @Override
+    public List<MediaType> getAcceptableMediaTypes() {
+        return getHttpHeaders().getAcceptableMediaTypes();
+    }
+
+    @Override
+    public Map<String, Cookie> getCookies() {
+        return getHttpHeaders().getCookies();
+    }
+
+    @Override
+    public Date getDate() {
+        return getHttpHeaders().getDate();
+    }
+
+    @Override
+    public InputStream getEntityStream() {
+        return m.get(InputStream.class);
+    }
+
+    @Override
+    public String getHeaderString(String name) {
+        return getHttpHeaders().getHeaderString(name);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public MultivaluedMap<String, String> getHeaders() {
+        h = null;
+        return new MetadataMap<String, String>(
+            (Map<String, List<String>>)m.get(Message.PROTOCOL_HEADERS), false,
true, true);
+    }
+
+    @Override
+    public Locale getLanguage() {
+        return getHttpHeaders().getLanguage();
+    }
+
+    @Override
+    public int getLength() {
+        return getHttpHeaders().getLength();
+    }
+
+    @Override
+    public MediaType getMediaType() {
+        return getHttpHeaders().getMediaType();
+    }
+
+    @Override
+    public String getMethod() {
+        return (String)getProperty(Message.HTTP_REQUEST_METHOD);
+    }
+
+    @Override
+    public Object getProperty(String name) {
+        return props == null ? null : props.get(name);
+    }
+
+    @Override
+    public Enumeration<String> getPropertyNames() {
+        final Iterator<String> it = props.keySet().iterator();
+        return new Enumeration<String>() {
+
+            @Override
+            public boolean hasMoreElements() {
+                return it.hasNext();
+            }
+
+            @Override
+            public String nextElement() {
+                return it.next();
+            }
+            
+        };
+    }
+
+    @Override
+    public Request getRequest() {
+        return new RequestImpl(m);
+    }
+
+    @Override
+    public SecurityContext getSecurityContext() {
+        return new SecurityContextImpl(m);
+    }
+
+    @Override
+    public UriInfo getUriInfo() {
+        return new UriInfoImpl(m);
+    }
+
+    @Override
+    public boolean hasEntity() {
+        return getEntityStream() != null;
+    }
+
+    @Override
+    public void removeProperty(String name) {
+        if (props != null) {
+            props.remove(name);    
+        }
+    }
+
+    @Override
+    public void setEntityStream(InputStream is) {
+        m.put(InputStream.class, is);
+    }
+
+    @Override
+    public void setMethod(String method) throws IllegalStateException {
+        m.put(Message.HTTP_REQUEST_METHOD, method);
+
+    }
+
+    @Override
+    public void setProperty(String name, Object value) {
+        if (props == null) {
+            props = new HashMap<String, Object>();
+            m.put(PROPERTY_KEY, props);
+        }    
+        props.put(name, value);    
+        
+    }
+
+    @Override
+    public void setRequestUri(URI requestUri) throws IllegalStateException {
+        if (!preMatch) {
+            throw new IllegalStateException();
+        }
+        m.put(Message.REQUEST_URI, requestUri.toString());
+    }
+
+    @Override
+    public void setRequestUri(URI baseUri, URI requestUri) throws IllegalStateException {
+        setRequestUri(requestUri);
+        Object servletRequest = m.get("HTTP.REQUEST");
+        if (servletRequest != null) {
+            ((javax.servlet.http.HttpServletRequest)servletRequest)
+                .setAttribute(ENDPOINT_ADDRESS_PROPERTY, baseUri.toString());
+        }
+    }
+
+    @Override
+    public void setSecurityContext(SecurityContext sc) {
+        m.put(SecurityContext.class, sc);
+    }
+
+    private HttpHeaders getHttpHeaders() {
+        return h != null ? h : new HttpHeadersImpl(m);
+    }
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 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=1382087&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerResponseContextImpl.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerResponseContextImpl.java
Fri Sep  7 16:33:56 2012
@@ -0,0 +1,209 @@
+/**
+ * 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 org.apache.cxf.jaxrs.impl;
+
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.util.Date;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.core.EntityTag;
+import javax.ws.rs.core.Link;
+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.StatusType;
+
+public class ContainerResponseContextImpl implements ContainerResponseContext {
+
+    @Override
+    public Set<String> getAllowedMethods() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Map<String, NewCookie> getCookies() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Date getDate() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Object getEntity() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Annotation[] getEntityAnnotations() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Class<?> getEntityClass() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public OutputStream getEntityStream() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public EntityTag getEntityTag() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Type getEntityType() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public String getHeaderString(String arg0) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public MultivaluedMap<String, Object> getHeaders() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Locale getLanguage() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Date getLastModified() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public int getLength() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    @Override
+    public Link getLink(String arg0) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Builder getLinkBuilder(String arg0) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Set<Link> getLinks() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public URI getLocation() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public MediaType getMediaType() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public int getStatus() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    @Override
+    public StatusType getStatusInfo() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public MultivaluedMap<String, String> getStringHeaders() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public boolean hasEntity() {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    @Override
+    public boolean hasLink(String arg0) {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    @Override
+    public void setEntity(Object arg0, Annotation[] arg1, MediaType arg2) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void setEntityStream(OutputStream arg0) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void setStatus(int arg0) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void setStatusInfo(StatusType arg0) {
+        // TODO Auto-generated method stub
+
+    }
+
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerResponseContextImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerResponseContextImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java?rev=1382087&r1=1382086&r2=1382087&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java Fri
Sep  7 16:33:56 2012
@@ -55,19 +55,30 @@ public class MetadataMap<K, V> implement
     
     public MetadataMap(Map<K, List<V>> store, boolean readOnly, boolean caseInsensitive)
{
         
-        this.caseInsensitive = caseInsensitive;
+        this (store, true, readOnly, caseInsensitive);
+        
+    }
+    // TODO: Review the use of this constructor,
+    //       refactor the code, copyStore and readOnly are duplicates
+    public MetadataMap(Map<K, List<V>> store, boolean copyStore, 
+                       boolean readOnly, boolean caseInsensitive) {
         
-        this.m = new LinkedHashMap<K, List<V>>();
-        if (store != null) {
-            for (Map.Entry<K, List<V>> entry : store.entrySet()) {
-                List<V> values = new ArrayList<V>(entry.getValue());
-                m.put(entry.getKey(), readOnly 
-                      ? Collections.unmodifiableList(values) : values);
+        if (copyStore) {
+            this.m = new LinkedHashMap<K, List<V>>();
+            if (store != null) {
+                for (Map.Entry<K, List<V>> entry : store.entrySet()) {
+                    List<V> values = new ArrayList<V>(entry.getValue());
+                    m.put(entry.getKey(), readOnly 
+                          ? Collections.unmodifiableList(values) : values);
+                }
             }
+            if (readOnly) {
+                this.m = Collections.unmodifiableMap(m);
+            }
+        } else {
+            this.m = store;
         }
-        if (readOnly) {
-            this.m = Collections.unmodifiableMap(m);
-        }
+        this.caseInsensitive = caseInsensitive;
         
     }
     

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=1382087&r1=1382086&r2=1382087&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
Fri Sep  7 16:33:56 2012
@@ -85,6 +85,11 @@ public class JAXRSInInterceptor extends 
     
     public void handleMessage(Message message) {
         
+        if (message.getExchange().get(OperationResourceInfo.class) != null) {
+            // it's a suspended invocation;
+            return;
+        }
+        
         try {
             processRequest(message);
         } catch (RuntimeException ex) {
@@ -103,12 +108,9 @@ public class JAXRSInInterceptor extends 
     
     private void processRequest(Message message) {
         
-        if (message.getExchange().get(OperationResourceInfo.class) != null) {
-            // it's a suspended invocation;
-            return;
-        }
+        ProviderFactory providerFactory = ProviderFactory.getInstance(message);
         
-        RequestPreprocessor rp = ProviderFactory.getInstance(message).getRequestPreprocessor();
+        RequestPreprocessor rp = providerFactory.getRequestPreprocessor();
         if (rp != null) {
             rp.preprocess(message, new UriInfoImpl(message, null));
             if (message.getExchange().get(Response.class) != null) {
@@ -116,6 +118,10 @@ public class JAXRSInInterceptor extends 
             }
         }
         
+        if (JAXRSUtils.runContainerFilters(providerFactory, message, true, null)) {
+            return;
+        }
+        
         String requestContentType = (String)message.get(Message.CONTENT_TYPE);
         if (requestContentType == null) {
             requestContentType = "*/*";
@@ -157,13 +163,17 @@ 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");
         OperationResourceInfo ori = null;     
         
         boolean operChecked = false;
-        List<ProviderInfo<RequestHandler>> shs = ProviderFactory.getInstance(message).getRequestHandlers();
+        List<ProviderInfo<RequestHandler>> shs = providerFactory.getRequestHandlers();
         for (ProviderInfo<RequestHandler> sh : shs) {
             if (ori == null && !operChecked) {
                 try {                
@@ -201,6 +211,11 @@ public class JAXRSInInterceptor extends 
             }
         }
 
+        if (!ori.getNameBindings().isEmpty() 
+            && JAXRSUtils.runContainerFilters(providerFactory, message, false, ori.getNameBindings()))
{
+            return;
+        }
+        
         if (LOG.isLoggable(Level.FINE)) {
             LOG.fine("Request path is: " + rawPath);
             LOG.fine("Request HTTP method is: " + httpMethod);
@@ -209,8 +224,9 @@ public class JAXRSInInterceptor extends 
 
             LOG.fine("Found operation: " + ori.getMethodToInvoke().getName());
         }
-        setExchangeProperties(message, ori, values, resources.size());  
-      
+        
+        setExchangeProperties(message, ori, values, resources.size());
+        
         //Process parameters
         try {
             List<Object> params = JAXRSUtils.processParameters(ori, values, message);

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=1382087&r1=1382086&r2=1382087&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
Fri Sep  7 16:33:56 2012
@@ -50,7 +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;
+    private boolean contextsAvailable;
     
     protected AbstractResourceInfo(Bus bus) {
         this.bus = bus;

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=1382087&r1=1382086&r2=1382087&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 Fri
Sep  7 16:33:56 2012
@@ -62,6 +62,8 @@ import javax.ws.rs.RedirectionException;
 import javax.ws.rs.ServerErrorException;
 import javax.ws.rs.ServiceUnavailableException;
 import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Cookie;
 import javax.ws.rs.core.HttpHeaders;
@@ -91,6 +93,7 @@ import org.apache.cxf.jaxrs.ext.MessageC
 import org.apache.cxf.jaxrs.ext.ProtocolHeaders;
 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.HttpHeadersImpl;
 import org.apache.cxf.jaxrs.impl.HttpServletResponseFilter;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
@@ -1333,4 +1336,23 @@ public final class JAXRSUtils {
         return XMLUtils.convertStringToQName(name, "");
     }
     
+    public static boolean runContainerFilters(ProviderFactory pf, Message m, boolean preMatch,

+                                              List<String> names) {
+        List<ProviderInfo<ContainerRequestFilter>> containerFilters = names ==
null 
+            ? pf.getGlobalContainerRequestFilters(preMatch) : pf.getBoundContainerRequestFilters(names);
+        if (!containerFilters.isEmpty()) {
+            ContainerRequestContext context = new ContainerRequestContextImpl(m, true);
+            for (ProviderInfo<ContainerRequestFilter> filter : containerFilters) {
+                try {
+                    filter.getProvider().filter(context);
+                } catch (IOException ex) {
+                    throw new WebApplicationException(ex);
+                }
+                if (m.getExchange().get(Response.class) != null) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
 }

Added: 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=1382087&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
(added)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
Fri Sep  7 16:33:56 2012
@@ -0,0 +1,85 @@
+/**
+ * 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 org.apache.cxf.systest.jaxrs;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+    
+public class BookServer20 extends AbstractBusTestServerBase {
+    public static final String PORT = allocatePort(BookServer20.class);
+ 
+    org.apache.cxf.endpoint.Server server; 
+    
+    protected void run() {
+        Bus bus = BusFactory.getDefaultBus();
+        setBus(bus);
+        JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
+        sf.setBus(bus);
+        sf.setResourceClasses(BookStore.class);
+        
+        List<Object> providers = new ArrayList<Object>();
+        
+        providers.add(new PreMatchContainerRequestFilter());
+        sf.setProviders(providers);
+        sf.setResourceProvider(BookStore.class,
+                               new SingletonResourceProvider(new BookStore(), true));
+        sf.setAddress("http://localhost:" + PORT + "/");
+        server = sf.create();
+        BusFactory.setDefaultBus(null);
+        BusFactory.setThreadDefaultBus(null);
+    }
+    
+    public void tearDown() throws Exception {
+        server.stop();
+        server.destroy();
+        server = null;
+    }
+
+    public static void main(String[] args) {
+        try {
+            BookServer20 s = new BookServer20();
+            s.start();
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            System.exit(-1);
+        } finally {
+            System.out.println("done!");
+        }
+    }
+    
+    private static class PreMatchContainerRequestFilter implements ContainerRequestFilter
{
+
+        @Override
+        public void filter(ContainerRequestContext context) throws IOException {
+            context.getHeaders().add("BOOK", "123");
+        }
+        
+    }
+}

Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

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=1382087&r1=1382086&r2=1382087&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 Fri
Sep  7 16:33:56 2012
@@ -426,6 +426,12 @@ public class BookStore {
     }
     
     @GET
+    @Path("/bookheaders/simple/")
+    public Book getBookByHeaderSimple(@HeaderParam("BOOK") String header) throws Exception
{
+        return doGetBook(header);
+    }
+    
+    @GET
     @Path("/bookheaders/")
     public Book getBookByHeader(@HeaderParam("BOOK") List<String> ids) throws Exception
{
         List<MediaType> types = httpHeaders.getAcceptableMediaTypes();

Added: 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=1382087&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
(added)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
Fri Sep  7 16:33:56 2012
@@ -0,0 +1,44 @@
+/**
+ * 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 org.apache.cxf.systest.jaxrs;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class JAXRS20ClientServerBookTest extends AbstractBusClientServerTestBase {
+    public static final String PORT = BookServer20.PORT;
+    
+    @BeforeClass
+    public static void startServers() throws Exception {
+        assertTrue("server did not launch correctly",
+                   launchServer(BookServer20.class, true));
+    }
+    
+    @Test
+    public void testGetBook() {
+        String address = "http://localhost:" + PORT + "/bookstore/bookheaders/simple";
+        WebClient wc = WebClient.create(address);
+        Book book = wc.get(Book.class);
+        assertEquals(123L, book.getId());
+    }
+}

Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message