cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6352] Support for multiple links with no 'rel'
Date Fri, 17 Apr 2015 11:35:24 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 6c2b16cf4 -> 8dd53865e


[CXF-6352] Support for multiple links with no 'rel'


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/8dd53865
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/8dd53865
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/8dd53865

Branch: refs/heads/3.0.x-fixes
Commit: 8dd53865e47c51c5392c5ecbf0a45b53c6dfc2d1
Parents: 6c2b16c
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Fri Apr 17 12:33:56 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Fri Apr 17 12:35:00 2015 +0100

----------------------------------------------------------------------
 .../org/apache/cxf/jaxrs/impl/ResponseImpl.java | 20 ++++++++--------
 .../apache/cxf/jaxrs/impl/ResponseImplTest.java | 25 ++++++++++++++++++++
 2 files changed, 35 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/8dd53865/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
index c101a67..681142a 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
@@ -31,7 +31,7 @@ import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -269,10 +269,10 @@ public final class ResponseImpl extends Response {
     }
     
     public Link getLink(String relation) {
-        Set<Map.Entry<String, Link>> entries = getAllLinks().entrySet();
-        for (Map.Entry<String, Link> entry : entries) {
-            if (entry.getKey().contains(relation)) {
-                return entry.getValue();
+        Set<Link> links = getAllLinks();
+        for (Link link : links) {
+            if (link.getRel() != null && link.getRel().equals(relation)) {
+                return link;
             }
         }
         return null;
@@ -284,22 +284,22 @@ public final class ResponseImpl extends Response {
     }
 
     public Set<Link> getLinks() {
-        return new HashSet<Link>(getAllLinks().values());
+        return new HashSet<Link>(getAllLinks());
     }
 
-    private Map<String, Link> getAllLinks() {
+    private Set<Link> getAllLinks() {
         List<Object> linkValues = metadata.get(HttpHeaders.LINK);
         if (linkValues == null) {
-            return Collections.emptyMap();
+            return Collections.emptySet();
         } else {
-            Map<String, Link> links = new LinkedHashMap<String, Link>();
+            Set<Link> links = new LinkedHashSet<Link>();
             for (Object o : linkValues) {
                 Link link = o instanceof Link ? (Link)o : Link.valueOf(o.toString());
                 if (!link.getUri().isAbsolute()) {
                     URI requestURI = URI.create((String)outMessage.get(Message.REQUEST_URI));
                     link = Link.fromLink(link).baseUri(requestURI).build();
                 }
-                links.put(link.getRel(), link);
+                links.add(link);
             }
             return links;
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/8dd53865/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
index 1c788da..b750508 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
@@ -387,6 +387,31 @@ public class ResponseImplTest extends Assert {
         assertEquals("prev", prev.getRel());
     }
     
+    @Test
+    public void testGetLinksNoRel() {
+        ResponseImpl ri = new ResponseImpl(200);
+        MetadataMap<String, Object> meta = new MetadataMap<String, Object>();
+        ri.addMetadata(meta);
+        
+        Set<Link> links = ri.getLinks();
+        assertTrue(links.isEmpty());
+        
+        meta.add(HttpHeaders.LINK, "<http://next>");
+        meta.add(HttpHeaders.LINK, "<http://prev>");
+        
+        assertFalse(ri.hasLink("next"));
+        Link next = ri.getLink("next");
+        assertNull(next);
+        assertFalse(ri.hasLink("prev"));
+        Link prev = ri.getLink("prev");
+        assertNull(prev);
+        
+        links = ri.getLinks();
+        assertTrue(links.contains(Link.fromUri("http://next").build()));
+        assertTrue(links.contains(Link.fromUri("http://prev").build()));
+        
+    }
+    
     public static class StringBean {
         private String header;
 


Mime
View raw message