cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1448742 - in /cxf/trunk: parent/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/
Date Thu, 21 Feb 2013 17:41:28 GMT
Author: sergeyb
Date: Thu Feb 21 17:41:28 2013
New Revision: 1448742

URL: http://svn.apache.org/r1448742
Log:
[CXF-4845] Upgrade to JAX-RS 2.0 API rc1

Modified:
    cxf/trunk/parent/pom.xml
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/LinkBuilderImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalUriInfo.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java

Modified: cxf/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/parent/pom.xml?rev=1448742&r1=1448741&r2=1448742&view=diff
==============================================================================
--- cxf/trunk/parent/pom.xml (original)
+++ cxf/trunk/parent/pom.xml Thu Feb 21 17:41:28 2013
@@ -111,7 +111,7 @@
         <cxf.geronimo.servlet25.version>1.1.2</cxf.geronimo.servlet25.version>
         <cxf.geronimo.transaction.version>1.1.1</cxf.geronimo.transaction.version>
         <cxf.geronimo.ws.metadata.version>1.1.3</cxf.geronimo.ws.metadata.version>
-        <cxf.javax.ws.rs.version>2.0-m16</cxf.javax.ws.rs.version>
+        <cxf.javax.ws.rs.version>2.0-rc1</cxf.javax.ws.rs.version>
         <cxf.jaxb21.version>2.1</cxf.jaxb21.version>
         <cxf.jaxb21.impl.version>2.1.13</cxf.jaxb21.impl.version>
         <cxf.jaxb21.xjc.version>2.1.13</cxf.jaxb21.xjc.version>

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/LinkBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/LinkBuilderImpl.java?rev=1448742&r1=1448741&r2=1448742&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/LinkBuilderImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/LinkBuilderImpl.java
Thu Feb 21 17:41:28 2013
@@ -31,9 +31,9 @@ import java.util.Set;
 import javax.ws.rs.core.Link;
 import javax.ws.rs.core.Link.Builder;
 import javax.ws.rs.core.UriBuilder;
-import javax.ws.rs.core.UriInfo;
 
 import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.jaxrs.utils.HttpUtils;
 
 public class LinkBuilderImpl implements Builder {
     private static final String DOUBLE_QUOTE = "\"";
@@ -47,15 +47,17 @@ public class LinkBuilderImpl implements 
     }
 
     @Override
-    public Link buildRelativized(UriInfo uriInfo, Object... values) {
+    public Link buildRelativized(URI requestUri, Object... values) {
         URI uri = ub.build(values);
-        return new LinkImpl(uriInfo.relativize(uri), params);
+        URI relativized = HttpUtils.relativize(requestUri, uri);
+        return new LinkImpl(relativized, params);
     }
 
     @Override
-    public Link buildResolved(UriInfo uriInfo, Object... values) {
+    public Link buildResolved(URI baseUri, Object... values) {
         URI uri = ub.build(values);
-        return new LinkImpl(uriInfo.resolve(uri), params);
+        URI resolved = HttpUtils.resolve(UriBuilder.fromUri(baseUri), uri);
+        return new LinkImpl(resolved, params);
     }
 
     @Override
@@ -232,5 +234,4 @@ public class LinkBuilderImpl implements 
             }
         }
     }
-    
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java?rev=1448742&r1=1448741&r2=1448742&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java Thu
Feb 21 17:41:28 2013
@@ -45,8 +45,6 @@ import org.apache.cxf.message.MessageUti
 public class UriInfoImpl implements UriInfo {
     private static final Logger LOG = LogUtils.getL7dLogger(UriInfoImpl.class);
     private static final String CASE_INSENSITIVE_QUERIES = "org.apache.cxf.http.case_insensitive_queries";
-    private static final String CURRENT_PATH_SEGMENT = ".";
-    private static final String PARENT_PATH_SEGMENT = "..";
     
     private MultivaluedMap<String, String> templateParams;
     private Message message;
@@ -219,84 +217,13 @@ public class UriInfoImpl implements UriI
 
     @Override
     public URI relativize(URI uri) {
-        URI resolved = resolve(uri);
-        URI requestURI = getRequestUri();
-        if (!getUriPrefix(resolved).equals(getUriPrefix(requestURI))) {
-            return resolved;
-        }
-        List<PathSegment> resolvedSegments = JAXRSUtils.getPathSegments(resolved.getRawPath(),
false);
-        List<PathSegment> requestSegments = JAXRSUtils.getPathSegments(requestURI.getRawPath(),
false);
-        
-        int count = 0;
-        for (int i = resolvedSegments.size() - 1; i >= 0; i--) {
-            if (i <= requestSegments.size() - 1) {
-                String resolvedPath = resolvedSegments.get(i).getPath();
-                String requestPath = requestSegments.get(i).getPath();
-                if (!resolvedPath.equals(requestPath)) {
-                    count++;
-                }
-            }
-        }
-        StringBuilder sb = new StringBuilder();
-        
-        for (int i = 0; i < count; i++) {
-            if (i != 0) {
-                sb.append("/");
-            }
-            sb.append(PARENT_PATH_SEGMENT);
-        }
-        for (int i = count + 1; i < resolvedSegments.size(); i++) {
-            if (i != 0) {
-                sb.append("/");
-            }
-            sb.append(resolvedSegments.get(i).getPath());
-        }
-        return URI.create(sb.toString());
+        URI resolved = HttpUtils.resolve(getBaseUriBuilder(), uri);
+        return HttpUtils.relativize(getRequestUri(), resolved);
     }
     
-    private static String getUriPrefix(URI uri) {
-        StringBuilder sb = new StringBuilder();
-        sb.append(uri.getScheme()).append(uri.getHost()).append(uri.getPort());
-        
-        return sb.toString();
-    }
-
     @Override
     public URI resolve(URI uri) {
-        if (!uri.isAbsolute()) {
-            String uriValue = uri.toString();
-            boolean parentPathSegmentAvail = uriValue.contains(PARENT_PATH_SEGMENT)
-                || uriValue.contains(CURRENT_PATH_SEGMENT); 
-            uri = getBaseUriBuilder().path(uriValue).build();
-            if (parentPathSegmentAvail) {
-                List<PathSegment> segments = JAXRSUtils.getPathSegments(uri.getRawPath(),
false);
-                List<PathSegment> actualSegments = new LinkedList<PathSegment>();
-                UriBuilder ub = UriBuilder.fromUri(uri).replacePath(null);
-                for (PathSegment ps : segments) {
-                    if (PARENT_PATH_SEGMENT.equals(ps.getPath()) && !actualSegments.isEmpty())
{
-                        actualSegments.remove(actualSegments.size() - 1);
-                    } else if (!CURRENT_PATH_SEGMENT.equals(ps.getPath())) {
-                        actualSegments.add(ps);
-                    }
-                }
-                for (PathSegment ps : actualSegments) {
-                    ub.segment(ps.toString());
-                }
-                uri = ub.build();
-            }
-        }
-        return uri;
+        return HttpUtils.resolve(getBaseUriBuilder(), uri);
     }
     
-    @Override
-    public URI relativize(URI arg0, URI arg1) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    public URI resolve(URI arg0, URI arg1) {
-        // TODO Auto-generated method stub
-        return null;
-    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalUriInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalUriInfo.java?rev=1448742&r1=1448741&r2=1448742&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalUriInfo.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalUriInfo.java
Thu Feb 21 17:41:28 2013
@@ -106,18 +106,7 @@ public class ThreadLocalUriInfo extends 
     }
 
     @Override
-    public URI relativize(URI uri1, URI uri2) {
-        return get().relativize(uri1, uri2);
-    }
-
-    @Override
     public URI resolve(URI uri) {
         return get().resolve(uri);
     }
-
-    @Override
-    public URI resolve(URI uri1, URI uri2) {
-        return get().resolve(uri1, uri2);
-    }
-
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java?rev=1448742&r1=1448741&r2=1448742&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java Thu
Feb 21 17:41:28 2013
@@ -26,6 +26,7 @@ import java.net.URLEncoder;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -41,6 +42,7 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
 
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
@@ -75,6 +77,10 @@ public final class HttpUtils {
     private static final String PATH_RESERVED_CHARACTERS = "=@/:!$&\'(),;~";
     private static final String QUERY_RESERVED_CHARACTERS = "?/";
     
+    private static final String CURRENT_PATH_SEGMENT = ".";
+    private static final String PARENT_PATH_SEGMENT = "..";
+    
+    
     private HttpUtils() {
     }
     
@@ -89,7 +95,7 @@ public final class HttpUtils {
     public static String pathDecode(String value) {
         return UrlUtils.pathDecode(value);
     }
-    
+
     private static String componentEncode(String reservedChars, String value) {
         
         StringBuilder buffer = new StringBuilder();
@@ -455,4 +461,71 @@ public final class HttpUtils {
         String charset = mt == null ? "UTF-8" : mt.getParameters().get("charset");
         return charset == null ? "UTF-8" : charset;
     }
+    
+    public static URI resolve(UriBuilder baseBuilder, URI uri) {
+        if (!uri.isAbsolute()) {
+            String uriValue = uri.toString();
+            boolean parentPathSegmentAvail = uriValue.contains(PARENT_PATH_SEGMENT)
+                || uriValue.contains(CURRENT_PATH_SEGMENT); 
+            uri = baseBuilder.path(uriValue).build();
+            if (parentPathSegmentAvail) {
+                List<PathSegment> segments = JAXRSUtils.getPathSegments(uri.getRawPath(),
false);
+                List<PathSegment> actualSegments = new LinkedList<PathSegment>();
+                UriBuilder ub = UriBuilder.fromUri(uri).replacePath(null);
+                for (PathSegment ps : segments) {
+                    if (PARENT_PATH_SEGMENT.equals(ps.getPath()) && !actualSegments.isEmpty())
{
+                        actualSegments.remove(actualSegments.size() - 1);
+                    } else if (!CURRENT_PATH_SEGMENT.equals(ps.getPath())) {
+                        actualSegments.add(ps);
+                    }
+                }
+                for (PathSegment ps : actualSegments) {
+                    ub.segment(ps.toString());
+                }
+                uri = ub.build();
+            }
+        }
+        return uri;
+    }
+    
+    public static URI relativize(URI requestURI, URI resolved) {
+        if (!getUriPrefix(resolved).equals(getUriPrefix(requestURI))) {
+            return resolved;
+        }
+        List<PathSegment> resolvedSegments = JAXRSUtils.getPathSegments(resolved.getRawPath(),
false);
+        List<PathSegment> requestSegments = JAXRSUtils.getPathSegments(requestURI.getRawPath(),
false);
+        
+        int count = 0;
+        for (int i = resolvedSegments.size() - 1; i >= 0; i--) {
+            if (i <= requestSegments.size() - 1) {
+                String resolvedPath = resolvedSegments.get(i).getPath();
+                String requestPath = requestSegments.get(i).getPath();
+                if (!resolvedPath.equals(requestPath)) {
+                    count++;
+                }
+            }
+        }
+        StringBuilder sb = new StringBuilder();
+        
+        for (int i = 0; i < count; i++) {
+            if (i != 0) {
+                sb.append("/");
+            }
+            sb.append(PARENT_PATH_SEGMENT);
+        }
+        for (int i = count + 1; i < resolvedSegments.size(); i++) {
+            if (i != 0) {
+                sb.append("/");
+            }
+            sb.append(resolvedSegments.get(i).getPath());
+        }
+        return URI.create(sb.toString());
+    }
+    
+    private static String getUriPrefix(URI uri) {
+        StringBuilder sb = new StringBuilder();
+        sb.append(uri.getScheme()).append(uri.getHost()).append(uri.getPort());
+        
+        return sb.toString();
+    }
 }



Mime
View raw message