cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5920] Using UriBuilder to compose the final Link URI
Date Thu, 07 Aug 2014 10:14:19 GMT
Repository: cxf
Updated Branches:
  refs/heads/master a5f8a4dd4 -> df669c623


[CXF-5920] Using UriBuilder to compose the final Link URI


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

Branch: refs/heads/master
Commit: df669c623116598f752beccf7762c68a9b74ac55
Parents: a5f8a4d
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Thu Aug 7 13:13:53 2014 +0300
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Thu Aug 7 13:13:53 2014 +0300

----------------------------------------------------------------------
 .../org/apache/cxf/jaxrs/impl/LinkBuilderImpl.java    | 14 ++++++++++++--
 .../apache/cxf/jaxrs/impl/LinkBuilderImplTest.java    |  4 ++--
 .../org/apache/cxf/systest/jaxrs/BookStoreSpring.java |  9 +++++++++
 .../jaxrs/JAXRSClientServerSpringBookTest.java        | 11 +++++++++++
 4 files changed, 34 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/df669c62/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/LinkBuilderImpl.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/LinkBuilderImpl.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/LinkBuilderImpl.java
index 15c3243..edfc403 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/LinkBuilderImpl.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/LinkBuilderImpl.java
@@ -57,8 +57,18 @@ public class LinkBuilderImpl implements Builder {
     private URI getResolvedUri(Object... values) {
         URI uri = ub.build(values);
                 
-        return baseUri != null 
-            ? HttpUtils.resolve(UriBuilder.fromUri(baseUri), uri) : uri;
+        if (baseUri != null) {
+            UriBuilder linkUriBuilder = UriBuilder.fromUri(baseUri);
+            String scheme = uri.getScheme();
+            if (scheme != null && scheme.startsWith("http")) {
+                return HttpUtils.resolve(linkUriBuilder, uri);    
+            } else {
+                String theUri = uri.toString();
+                return linkUriBuilder.path(theUri).build();
+            }
+        } else {
+            return uri;
+        }
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/cxf/blob/df669c62/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/LinkBuilderImplTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/LinkBuilderImplTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/LinkBuilderImplTest.java
index a3790dc..4d84863 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/LinkBuilderImplTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/LinkBuilderImplTest.java
@@ -79,7 +79,7 @@ public class LinkBuilderImplTest extends Assert {
         Link.Builder linkBuilder = Link.fromUri("relative");
         linkBuilder.baseUri("http://localhost:8080/base/path");
         Link link = linkBuilder.rel("next").build();
-        assertEquals("<http://localhost:8080/base/relative>;rel=\"next\"", link.toString());
+        assertEquals("<http://localhost:8080/base/path/relative>;rel=\"next\"", link.toString());
     }
     
     @Test
@@ -87,7 +87,7 @@ public class LinkBuilderImplTest extends Assert {
         Link.Builder linkBuilder = Link.fromUri("/relative");
         linkBuilder.baseUri("http://localhost:8080/base/path");
         Link link = linkBuilder.rel("next").build();
-        assertEquals("<http://localhost:8080/relative>;rel=\"next\"", link.toString());
+        assertEquals("<http://localhost:8080/base/path/relative>;rel=\"next\"", link.toString());
     }
     
     @Test

http://git-wip-us.apache.org/repos/asf/cxf/blob/df669c62/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
index 5f0eeb4..d264d0b 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
@@ -41,8 +41,10 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Link;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.Source;
@@ -90,6 +92,13 @@ public class BookStoreSpring {
     public Book getBookRedirectStart() {
         return new Book("Redirect start", 123L); 
     }
+    @GET
+    @Path("/link")
+    public Response getBookLink() {
+        Link link = Link.fromResource(BookStoreSpring.class)
+            .baseUri(ui.getBaseUri()).rel("self").build();
+        return Response.ok().links(link).build();
+    }
     
     @GET
     @Path("/books/redirectComplete")

http://git-wip-us.apache.org/repos/asf/cxf/blob/df669c62/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
index 133c0f0..7265127 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
@@ -33,6 +33,7 @@ import java.util.Map;
 
 import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.core.Form;
+import javax.ws.rs.core.Link;
 import javax.ws.rs.core.Response;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
@@ -183,6 +184,16 @@ public class JAXRSClientServerSpringBookTest extends AbstractBusClientServerTest
     public void testGetBookISOXML3() throws Exception {
         doTestGetBookISOXML(null, "1");
     }
+    
+    @Test
+    public void testGetBookLink() throws Exception {
+        String address = "http://localhost:" + PORT + "/the/bookstore/link";
+        WebClient wc = WebClient.create(address);
+        Response r = wc.get();
+        Link l = r.getLink("self");
+        assertEquals("<http://localhost:" + PORT + "/the/bookstore/>;rel=\"self\"",
+                     l.toString());
+    }
     private void doTestGetBookISO(String charset, String pathSegment) throws Exception {
         String address = "http://localhost:" + PORT + "/the/bookstore/ISO-8859-1/" + pathSegment;
   
         WebClient wc = WebClient.create(address);


Mime
View raw message