cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1380280 - in /cxf/trunk: parent/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/
Date Mon, 03 Sep 2012 16:02:48 GMT
Author: sergeyb
Date: Mon Sep  3 16:02:47 2012
New Revision: 1380280

URL: http://svn.apache.org/viewvc?rev=1380280&view=rev
Log:
[CXF-4455] Update to javax.ws.rs-api 2.0-m10

Modified:
    cxf/trunk/parent/pom.xml
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/LinkHeaderProvider.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/impl/ResponseBuilderImpl.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/impl/UriBuilderImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/LinkHeaderProviderTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/MetadataMapTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java

Modified: cxf/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/parent/pom.xml?rev=1380280&r1=1380279&r2=1380280&view=diff
==============================================================================
--- cxf/trunk/parent/pom.xml (original)
+++ cxf/trunk/parent/pom.xml Mon Sep  3 16:02:47 2012
@@ -148,7 +148,7 @@
         <cxf.geronimo.servlet.version>1.0</cxf.geronimo.servlet.version>
         <cxf.geronimo.servlet25.version>1.1.2</cxf.geronimo.servlet25.version>
         <cxf.geronimo.jpa.version>1.0</cxf.geronimo.jpa.version>
-        <cxf.javax.ws.rs.version>2.0-m09</cxf.javax.ws.rs.version>
+        <cxf.javax.ws.rs.version>2.0-m10</cxf.javax.ws.rs.version>
         <cxf.commons-codec.version>1.4</cxf.commons-codec.version>
         <cxf.commons-lang.version>2.6</cxf.commons-lang.version>
         <cxf.commons-collections.version>3.2.1</cxf.commons-collections.version>

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/LinkHeaderProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/LinkHeaderProvider.java?rev=1380280&r1=1380279&r2=1380280&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/LinkHeaderProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/LinkHeaderProvider.java
Mon Sep  3 16:02:47 2012
@@ -21,13 +21,14 @@ package org.apache.cxf.jaxrs.impl;
 
 import java.util.Arrays;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 import javax.ws.rs.core.Link;
 import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
 
+import org.apache.cxf.common.util.StringUtils;
+
 public class LinkHeaderProvider implements HeaderDelegate<Link> {
 
     private static final String REL = "rel";
@@ -99,7 +100,7 @@ public class LinkHeaderProvider implemen
         sb.append(link.getUri());
         sb.append('>');
         
-        List<String> rels = link.getRel();
+        String rels = link.getRel();
         if (!rels.isEmpty()) {
             sb.append(";").append(REL).append('=');
             writeListParamValues(sb, rels);
@@ -110,7 +111,7 @@ public class LinkHeaderProvider implemen
         if (link.getType() != null) {
             sb.append(";").append(TYPE).append('=').append(link.getType());
         }
-        for (Map.Entry<String, List<String>> entry : link.getParams().entrySet())
{
+        for (Map.Entry<String, String> entry : link.getParams().entrySet()) {
             if (KNOWN_PARAMETERS.contains(entry.getKey())) {
                 continue;
             }
@@ -122,17 +123,16 @@ public class LinkHeaderProvider implemen
         
     }
 
-    private void writeListParamValues(StringBuilder sb, List<String> values) {
-        if (values.size() > 1) {
-            sb.append('"');
+    private void writeListParamValues(StringBuilder sb, String value) {
+        if (StringUtils.isEmpty(value)) {
+            return;
         }
-        for (int i = 0; i < values.size(); i++) {
-            sb.append(values.get(i));
-            if (i < values.size() - 1) { 
-                sb.append(',');    
-            }
+        boolean commaAvailable = value.contains(",");
+        if (commaAvailable) {
+            sb.append('"');
         }
-        if (values.size() > 1) {
+        sb.append(value);
+        if (commaAvailable) {
             sb.append('"');
         }
     }

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=1380280&r1=1380279&r2=1380280&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 Mon
Sep  3 16:02:47 2012
@@ -231,4 +231,22 @@ public class MetadataMap<K, V> implement
     public void addFirst(K key, V value) {
         addValue(key, value, false);
     }
+
+    public boolean equalsIgnoreValueOrder(MultivaluedMap<K, V> map) {
+        Set<K> mapKeys = map.keySet();
+        if (mapKeys.size() != m.keySet().size()) {
+            return false;
+        }
+        
+        for (K key : mapKeys) {
+            List<V> localValues = this.get(key);
+            List<V> mapValues = map.get(key);
+            if (localValues == null 
+                || localValues.size() != mapValues.size()
+                || !localValues.containsAll(mapValues)) {
+                return false;
+            }
+        }
+        return true;
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java?rev=1380280&r1=1380279&r2=1380280&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
Mon Sep  3 16:02:47 2012
@@ -20,7 +20,6 @@
 package org.apache.cxf.jaxrs.impl;
 
 import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
 import java.net.URI;
 import java.text.SimpleDateFormat;
 import java.util.Date;
@@ -281,12 +280,6 @@ public final class ResponseBuilderImpl e
     }
 
     @Override
-    public ResponseBuilder entity(Object arg0, Type arg1, Annotation[] arg2) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
     public ResponseBuilder link(URI arg0, String arg1) {
         // TODO Auto-generated method stub
         return null;

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=1380280&r1=1380279&r2=1380280&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  3 16:02:47 2012
@@ -221,8 +221,8 @@ public final class ResponseImpl extends 
     }
     
     public Link getLink(String relation) {
-        Set<Map.Entry<List<String>, Link>> entries = getAllLinks().entrySet();
-        for (Map.Entry<List<String>, Link> entry : entries) {
+        Set<Map.Entry<String, Link>> entries = getAllLinks().entrySet();
+        for (Map.Entry<String, Link> entry : entries) {
             if (entry.getKey().contains(relation)) {
                 return entry.getValue();
             }
@@ -238,12 +238,12 @@ public final class ResponseImpl extends 
         return new HashSet<Link>(getAllLinks().values());
     }
 
-    private Map<List<String>, Link> getAllLinks() {
+    private Map<String, Link> getAllLinks() {
         List<Object> linkValues = metadata.get(HttpHeaders.LINK);
         if (linkValues == null) {
             return Collections.emptyMap();
         } else {
-            Map<List<String>, Link> links = new HashMap<List<String>,
Link>();
+            Map<String, Link> links = new HashMap<String, Link>();
             for (Object o : linkValues) {
                 Link link = Link.valueOf(o.toString());
                 links.put(link.getRel(), link);
@@ -311,6 +311,9 @@ public final class ResponseImpl extends 
     }
     
     public boolean bufferEntity() throws MessageProcessingException {
+        if (entityClosed) {
+            throw new IllegalStateException();
+        }
         if (!entityBufferred && entity instanceof InputStream) {
             try {
                 InputStream oldEntity = (InputStream)entity;

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java?rev=1380280&r1=1380279&r2=1380280&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
Mon Sep  3 16:02:47 2012
@@ -72,10 +72,10 @@ public class UriBuilderImpl extends UriB
 
     @Override
     public URI build(Object... values) throws IllegalArgumentException, UriBuilderException
{
-        return doBuild(false, values);
+        return doBuild(false, false, values);
     }
 
-    private URI doBuild(boolean fromEncoded, Object... values) {
+    private URI doBuild(boolean fromEncoded, boolean encodePathSlash, Object... values) {
         
         String thePath = buildPath(fromEncoded);
         URITemplate pathTempl = new URITemplate(thePath);
@@ -176,27 +176,6 @@ public class UriBuilderImpl extends UriB
         return schemeSpecificPart != null;
     }
     
-    private String substituteVarargs(URITemplate templ, Object[] values, int ind) {
-        Map<String, String> varValueMap = new HashMap<String, String>();
-        
-        // vars in set are properly ordered due to linking in hash set
-        Set<String> uniqueVars = new LinkedHashSet<String>(templ.getVariables());
-        if (values.length < uniqueVars.size()) {
-            throw new IllegalArgumentException("Unresolved variables; only " + values.length
-                                               + " value(s) given for " + uniqueVars.size()
-                                               + " unique variable(s)");
-        }
-        int idx = ind;
-        for (String var : uniqueVars) {
-            Object oval = values[idx++];
-            if (oval == null) {
-                throw new IllegalArgumentException("No object for " + var);
-            }
-            varValueMap.put(var, oval.toString());
-        }
-        return templ.substitute(varValueMap);
-    }
-
     @Override
     public URI buildFromEncoded(Object... values) throws IllegalArgumentException, UriBuilderException
{
         // Problem: multi-arg URI c-tor always forces encoding, operation contract would
be broken;
@@ -215,16 +194,17 @@ public class UriBuilderImpl extends UriB
             
             values[i] = HttpUtils.encodePartiallyEncoded(values[i].toString(), false);
         }
-        return doBuild(true, values);
+        return doBuild(true, false, values);
     }
 
     @Override
-    public URI buildFromMap(Map<String, ? extends Object> map) throws IllegalArgumentException,
+    public URI buildFromMap(Map<String, ?> map) throws IllegalArgumentException,
         UriBuilderException {
-        return doBuildFromMap(map, false);
+        return doBuildFromMap(map, false, false);
     }
 
-    private URI doBuildFromMap(Map<String, ? extends Object> map, boolean fromEncoded)

+    private URI doBuildFromMap(Map<String, ? extends Object> map, boolean fromEncoded,

+                               boolean encodePathSlash) 
         throws IllegalArgumentException, UriBuilderException {
         try {
             String thePath = buildPath(fromEncoded);
@@ -243,6 +223,27 @@ public class UriBuilderImpl extends UriB
         }
     }
     
+    private String substituteVarargs(URITemplate templ, Object[] values, int ind) {
+        Map<String, String> varValueMap = new HashMap<String, String>();
+        
+        // vars in set are properly ordered due to linking in hash set
+        Set<String> uniqueVars = new LinkedHashSet<String>(templ.getVariables());
+        if (values.length < uniqueVars.size()) {
+            throw new IllegalArgumentException("Unresolved variables; only " + values.length
+                                               + " value(s) given for " + uniqueVars.size()
+                                               + " unique variable(s)");
+        }
+        int idx = ind;
+        for (String var : uniqueVars) {
+            Object oval = values[idx++];
+            if (oval == null) {
+                throw new IllegalArgumentException("No object for " + var);
+            }
+            varValueMap.put(var, oval.toString());
+        }
+        return templ.substitute(varValueMap);
+    }
+    
     private String substituteMapped(String path, Map<String, ? extends Object> varValueMap)
{
     
         URITemplate templ = new URITemplate(path);
@@ -257,7 +258,7 @@ public class UriBuilderImpl extends UriB
     }
 
     @Override
-    public URI buildFromEncodedMap(Map<String, ? extends Object> map) throws IllegalArgumentException,
+    public URI buildFromEncodedMap(Map<String, ?> map) throws IllegalArgumentException,
         UriBuilderException {
         
         Map<String, String> decodedMap = new HashMap<String, String>(map.size());
@@ -285,7 +286,7 @@ public class UriBuilderImpl extends UriB
             }
             
         }
-        return doBuildFromMap(decodedMap, true);
+        return doBuildFromMap(decodedMap, true, false);
     }
 
     // CHECKSTYLE:OFF
@@ -725,4 +726,27 @@ public class UriBuilderImpl extends UriB
             throw new IllegalArgumentException(ex);
         }
     }
+
+    //the clarified rules for encoding values of uri templates are:
+    //  - encode each value contextually based on the URI component containing the template
+    //  - in path templates, by default, encode also slashes (i.e. treat all path templates
as 
+    //    part of a single path segment, to be consistent with @Path annotation templates)
+    //  - for special cases when the slash encoding in path templates is not desired, 
+    //    users may use the newly added build methods to override the default behavior
+    
+    @Override
+    public URI build(Object[] vars, boolean encodePathSlash) throws IllegalArgumentException,
UriBuilderException {
+        return doBuild(false, encodePathSlash, vars);
+    }
+
+    @Override
+    public URI buildFromMap(Map<String, ?> map, boolean encodePathSlash) throws IllegalArgumentException,
+        UriBuilderException {
+        return doBuildFromMap(map, false, encodePathSlash);
+    }
+
+    @Override
+    public String toTemplate() {
+        throw new UnsupportedOperationException();
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/LinkHeaderProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/LinkHeaderProviderTest.java?rev=1380280&r1=1380279&r2=1380280&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/LinkHeaderProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/LinkHeaderProviderTest.java
Mon Sep  3 16:02:47 2012
@@ -19,8 +19,6 @@
 
 package org.apache.cxf.jaxrs.impl;
 
-import java.util.List;
-
 import javax.ws.rs.core.Link;
 
 import org.junit.Assert;
@@ -44,11 +42,11 @@ public class LinkHeaderProviderTest exte
     public void testFromComplexString() {
         Link l = Link.valueOf("<http://bar>;rel=next;title=\"Next Link\";type=text/xml;method=get");
         assertEquals("http://bar", l.getUri().toString());
-        List<String> rels = l.getRel();
-        assertEquals(1, rels.size());
-        assertEquals("next", rels.get(0));
+        String rel = l.getRel();
+        assertEquals("next", rel);
         assertEquals("Next Link", l.getTitle());
-        assertEquals("get", l.getMethod());
+        assertEquals("text/xml", l.getType());
+        assertEquals("get", l.getParams().get("method"));
     }
     
     @Test

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/MetadataMapTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/MetadataMapTest.java?rev=1380280&r1=1380279&r2=1380280&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/MetadataMapTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/MetadataMapTest.java
Mon Sep  3 16:02:47 2012
@@ -231,6 +231,30 @@ public class MetadataMapTest extends Ass
         assertEquals("bar", values.get(0).toString());
     }
     
-    
+    @Test
+    public void testCompareIgnoreValueOrder() {
+        MetadataMap<String, String> m = new MetadataMap<String, String>();
+        m.add("baz", "bar1");
+        m.add("baz", "bar2");
+        List<String> values = m.get("baz");
+        assertEquals("bar1", values.get(0));
+        assertEquals("bar2", values.get(1));
+        
+        MetadataMap<String, String> m2 = new MetadataMap<String, String>();
+        m2.add("baz", "bar2");
+        m2.add("baz", "bar1");
+        values = m2.get("baz");
+        assertEquals("bar2", values.get(0));
+        assertEquals("bar1", values.get(1));
+        
+        assertTrue(m.equalsIgnoreValueOrder(m2));
+        assertTrue(m.equalsIgnoreValueOrder(m));
+        assertTrue(m2.equalsIgnoreValueOrder(m));
+        
+        MetadataMap<String, String> m3 = new MetadataMap<String, String>();
+        m3.add("baz", "bar1");
+        assertFalse(m.equalsIgnoreValueOrder(m3));
+        assertFalse(m2.equalsIgnoreValueOrder(m3));
+    }
     
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java?rev=1380280&r1=1380279&r2=1380280&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
Mon Sep  3 16:02:47 2012
@@ -199,8 +199,8 @@ public class ResponseImplTest extends As
         assertTrue(links.contains(prev));
         
         assertEquals("http://next", next.getUri().toString());
-        assertEquals("next", next.getRel().get(0));
+        assertEquals("next", next.getRel());
         assertEquals("http://prev", prev.getUri().toString());
-        assertEquals("prev", prev.getRel().get(0));
+        assertEquals("prev", prev.getRel());
     }
 }



Mime
View raw message