cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1459856 - in /cxf/branches/2.7.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 15:59:04 GMT
Author: sergeyb
Date: Fri Mar 22 15:59:04 2013
New Revision: 1459856

URL: http://svn.apache.org/r1459856
Log:
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.7.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/ValidateWadlTest.java
      - copied unchanged from r1459728, cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/ValidateWadlTest.java
    cxf/branches/2.7.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/invalidParamStyle.xml
      - copied unchanged from r1459728, cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/invalidParamStyle.xml
Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
    cxf/branches/2.7.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java

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

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

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java?rev=1459856&r1=1459855&r2=1459856&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
Fri Mar 22 15:59:04 2013
@@ -26,12 +26,12 @@ import java.util.Comparator;
 import java.util.Date;
 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;
 
@@ -41,6 +41,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;
@@ -75,13 +76,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() {
@@ -126,11 +127,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 : HttpUtils.getLocale(values.get(0).trim());
@@ -142,11 +138,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() {
@@ -185,20 +182,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.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java?rev=1459856&r1=1459855&r2=1459856&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java
Fri Mar 22 15:59:04 2013
@@ -46,7 +46,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) {

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java?rev=1459856&r1=1459855&r2=1459856&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
Fri Mar 22 15:59:04 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.Date;
 import java.util.List;
 import java.util.Locale;
@@ -189,6 +190,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 testGetDate() throws Exception {
         
         Message m = new MessageImpl();

Modified: cxf/branches/2.7.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.7.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java?rev=1459856&r1=1459855&r2=1459856&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
(original)
+++ cxf/branches/2.7.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
Fri Mar 22 15:59:04 2013
@@ -95,6 +95,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 {
@@ -120,6 +121,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;
@@ -919,7 +921,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; 
             } 
@@ -1002,6 +1005,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