cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1459888 - in /cxf/branches/2.6.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/ tools/wadl...
Date Fri, 22 Mar 2013 16:28:44 GMT
Author: sergeyb
Date: Fri Mar 22 16:28:43 2013
New Revision: 1459888

URL: http://svn.apache.org/r1459888
Log:
Merged revisions 1459856 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes

................
  r1459856 | sergeyb | 2013-03-22 15:59:04 +0000 (Fri, 22 Mar 2013) | 13 lines
  
  Merged revisions 1459728,1459855 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1459728 | sergeyb | 2013-03-22 11:25:35 +0000 (Fri, 22 Mar 2013) | 1 line
    
    [CXF-4912] Initial support for the wadl parameter validation
  ........
    r1459855 | sergeyb | 2013-03-22 15:54:12 +0000 (Fri, 22 Mar 2013) | 1 line
    
    [CXF-4915] Optimizing HttpHeaders to create a single extra Map only
  ........
................

Added:
    cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/ValidateWadlTest.java
      - copied unchanged from r1459856, cxf/branches/2.7.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/ValidateWadlTest.java
    cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/invalidParamStyle.xml
      - copied unchanged from r1459856, cxf/branches/2.7.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/invalidParamStyle.xml
Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
    cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/branches/2.7.x-fixes:r1459856
  Merged /cxf/trunk:r1459728,1459855

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java?rev=1459888&r1=1459887&r2=1459888&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
Fri Mar 22 16:28:43 2013
@@ -25,12 +25,12 @@ import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
+import java.util.TreeMap;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -40,6 +40,7 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 
 import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Message;
@@ -74,13 +75,13 @@ public class HttpHeadersImpl implements 
     
     
     private Message message;
-    private MultivaluedMap<String, String> headers;
-    
-    @SuppressWarnings("unchecked")
+    private Map<String, List<String>> headers;
     public HttpHeadersImpl(Message message) {
         this.message = message;
-        this.headers = new MetadataMap<String, String>(
-            (Map<String, List<String>>)message.get(Message.PROTOCOL_HEADERS),
true, true);
+        this.headers = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));
+        if (headers == null) {
+            headers = Collections.emptyMap();
+        }
     }
     
     public List<MediaType> getAcceptableMediaTypes() {
@@ -125,11 +126,6 @@ public class HttpHeadersImpl implements 
         }
     }
     
-    private boolean splitIndividualValue() {
-        Object property = message.getContextualProperty(HEADER_SPLIT_PROPERTY);
-        return MessageUtils.isTrue(property);
-    }
-    
     public Locale getLanguage() {
         List<String> values = getListValues(HttpHeaders.CONTENT_LANGUAGE);
         return values.size() == 0 ? null : createLocale(values.get(0).trim());
@@ -141,11 +137,12 @@ public class HttpHeadersImpl implements 
     }
 
     public MultivaluedMap<String, String> getRequestHeaders() {
-        Map<String, List<String>> newHeaders = new LinkedHashMap<String, List<String>>();
+        Map<String, List<String>> newHeaders = 
+            new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
         for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
             newHeaders.put(entry.getKey(), getRequestHeader(entry.getKey()));
         }
-        return new MetadataMap<String, String>(newHeaders, true, true);
+        return new MetadataMap<String, String>(Collections.unmodifiableMap(newHeaders),
false);
     }
 
     public List<Locale> getAcceptableLanguages() {
@@ -184,20 +181,19 @@ public class HttpHeadersImpl implements 
         if (values == null || values.isEmpty() || values.get(0) == null) {
             return Collections.emptyList();
         }
-        if (HttpUtils.isDateRelatedHeader(name)) {
+        boolean splitIndividualValue 
+            = MessageUtils.isTrue(message.getContextualProperty(HEADER_SPLIT_PROPERTY));
+        if (!splitIndividualValue
+            || HttpUtils.isDateRelatedHeader(name)) {
             return values;
         }
-        String sep = HttpHeaders.COOKIE.equalsIgnoreCase(name) ? getCookieSeparator() : DEFAULT_SEPARATOR;
         List<String> ls = new LinkedList<String>();
         for (String value : values) {
             if (value == null) {
                 continue;
             }
-            if (splitIndividualValue()) {
-                ls.addAll(getHeaderValues(name, value, sep));
-            } else {
-                ls.add(value);
-            }
+            String sep = HttpHeaders.COOKIE.equalsIgnoreCase(name) ? getCookieSeparator()
: DEFAULT_SEPARATOR;
+            ls.addAll(getHeaderValues(name, value, sep));
         }
         return ls;
     }

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java?rev=1459888&r1=1459887&r2=1459888&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java
Fri Mar 22 16:28:43 2013
@@ -45,7 +45,11 @@ public class MetadataMap<K, V> implement
     }
     
     public MetadataMap(Map<K, List<V>> store) {
-        this(store, false, false);
+        this(store, true);
+    }
+    
+    public MetadataMap(Map<K, List<V>> store, boolean copy) {
+        this(store, copy, false, false);
     }
     
     public MetadataMap(boolean readOnly, boolean caseInsensitive) {
@@ -54,18 +58,27 @@ 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);
+        
+    }
+
+    public MetadataMap(Map<K, List<V>> store, boolean copy, 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);
+        this.caseInsensitive = caseInsensitive;
+        if (copy) {
+            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);
+            if (readOnly) {
+                this.m = Collections.unmodifiableMap(m);
+            }
+        } else {
+            this.m = store;
         }
         
     }

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java?rev=1459888&r1=1459887&r2=1459888&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
Fri Mar 22 16:28:43 2013
@@ -21,6 +21,7 @@ package org.apache.cxf.jaxrs.impl;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -169,6 +170,17 @@ public class HttpHeadersImplTest extends
     }
     
     @Test
+    public void testGetContentTypeLowCase() throws Exception {
+        
+        Message m = new MessageImpl();
+        m.put(Message.PROTOCOL_HEADERS, 
+              Collections.singletonMap("content-type", 
+                  Collections.singletonList("text/plain")));
+        HttpHeaders h = new HttpHeadersImpl(m);
+        assertEquals("text/plain", h.getRequestHeaders().getFirst("Content-Type"));
+    }
+    
+    @Test
     public void testGetMediaTypes() throws Exception {
         
         Message m = control.createMock(Message.class);

Modified: cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java?rev=1459888&r1=1459887&r2=1459888&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
(original)
+++ cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
Fri Mar 22 16:28:43 2013
@@ -93,6 +93,7 @@ import org.apache.cxf.jaxrs.utils.JAXRSU
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
 import org.apache.cxf.service.model.SchemaInfo;
 import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.tools.common.ToolException;
 import org.apache.ws.commons.schema.XmlSchema;
 
 public class SourceGenerator {
@@ -118,6 +119,7 @@ public class SourceGenerator {
                                                       FormParam.class));
     private static final Map<String, Class<?>> HTTP_METHOD_ANNOTATIONS;
     private static final Map<String, Class<?>> PARAM_ANNOTATIONS;
+    private static final String PLAIN_PARAM_STYLE = "plain";
     private static final Set<String> RESOURCE_LEVEL_PARAMS;
     private static final Map<String, String> AUTOBOXED_PRIMITIVES_MAP;
     private static final Map<String, String> XSD_SPECIFIC_TYPE_MAP;
@@ -906,7 +908,8 @@ public class SourceGenerator {
         for (int i = 0; i < inParamEls.size(); i++) {
     
             Element paramEl = inParamEls.get(i);
-            Class<?> paramAnn = PARAM_ANNOTATIONS.get(paramEl.getAttribute("style"));
+            
+            Class<?> paramAnn = getParamAnnotation(paramEl.getAttribute("style"));
             if (paramAnn == QueryParam.class && form) {
                 paramAnn = FormParam.class; 
             } 
@@ -980,6 +983,18 @@ public class SourceGenerator {
         }
     }
     
+    private Class<?> getParamAnnotation(String paramStyle) {
+        Class<?> paramAnn = PARAM_ANNOTATIONS.get(paramStyle);
+        if (paramAnn == null) {
+            String error = "Unsupported parameter style: " + paramStyle;
+            if (PLAIN_PARAM_STYLE.equals(paramStyle)) {
+                error += ", plain style parameters have to be wrapped by representations";
   
+            }
+            throw new ToolException(error); 
+        }
+        return paramAnn;
+    }
+    
     private void generateEnumClass(String clsName, List<Element> options, File src,
String classPackage) {
         StringBuilder sbImports = new StringBuilder();
         StringBuilder sbCode = new StringBuilder();



Mime
View raw message