cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r736740 - in /cxf/branches/2.1.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ rt/frontend/jaxrs/src/ma...
Date Thu, 22 Jan 2009 18:44:27 GMT
Author: sergeyb
Date: Thu Jan 22 10:44:27 2009
New Revision: 736740

URL: http://svn.apache.org/viewvc?rev=736740&view=rev
Log:
Merged revisions 736621 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r736621 | sergeyb | 2009-01-22 12:29:38 +0000 (Thu, 22 Jan 2009) | 1 line
  
  JAXRS: applying a nicely done patch for CXF-1991 on behalf of Andrzej Michalec
........

Added:
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoStack.java
      - copied unchanged from r736621, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoStack.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/UriBuilderWrongAnnotations.java
      - copied unchanged from r736621, cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/UriBuilderWrongAnnotations.java
Modified:
    cxf/branches/2.1.x-fixes/   (props changed)
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
    cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/Chapter.java
    cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jan 22 10:44:27 2009
@@ -1 +1 @@
-/cxf/trunk:686333-686363,686764,686820,687096,687194,687363,687387,687463,687543,687722,687798,687814,687817,687891,687910,687914,688086,688102,688133,688596,688735,688870,689572,689596,689855,689924,690067,690289,691246,691271,691295,691338,691355,691488,691602,691646,691706,691728,692116,692157,692310,692466,692499,693653,693819,694179,694263,694417,694716,694744,694747,694795,694869,694981,694987,694993,695041,695096,695396,695484,695537,695552,695561,695619,695684,695835,695840,695868,695935,695977,696016,696094,696433,696720,697085,697868,698128,699289,700261,700507,700602,700981,701316,701783,701830,701862,702187,702205-702248,702267,702547,702561,702580,702602,702609,702616,702653,702656,702957,703191,703239,703309,703501,703513,703548,704584,704937,704997,705150,705235,705274,705340,705446,705548,705614,705692,705708,706482,706631,706675,706900,706909,707034,707089,707100,707902,708035,708044,708074,708410,708417,708550,708554,709353-709354,709425,710076,710150,71015
 4,711193,711388,711410,711490,711635,711949,711975,712194,712198,712238,712272,712299,712312,712670,712893,713082,713095-713096,713099,713584,713597,713737,713804,713899,714167-714168,714245,714255,717937-717961,718281-718448,718565,718620,718640,718665,718970,719017,719210,719215-719218,719222-719273,719305,719327-719680,720053,720119-720218,720238,720293-720316,720497,721221,721241,721501,722117,722129,722412,722988,723024,723338,723378,723716-723791,724333-724372,724433-724438,724449,724481,724485,724668,724780,724782,724785,724793,724795,724940,725071,725316,725332,725335,725348,725364,725418,725425-725426,725455,725506,725554,725562,725651,725671,725688,725754,725773,725799,725839,726342,726524,726631,726634,726637,726639,726692,726724,726769,726992,727096,727445,727521,727568,727692,727754,727781,727792,728070,728087,728696,728897,729051,729430,729449,729460,729863,730082,730139,730889,730891,731598,731604,731615,731631,731635,732036,732050,732320,732363,732411,732450,
 732710,732827,733512,733582,733901,734367,734462,734666,734762,734772,734812,734836,734965,735113,735252,735722-735723,735729,735734,735751,735782,735787,735987,736352,736358-736362,736408,736423
+/cxf/trunk:686333-686363,686764,686820,687096,687194,687363,687387,687463,687543,687722,687798,687814,687817,687891,687910,687914,688086,688102,688133,688596,688735,688870,689572,689596,689855,689924,690067,690289,691246,691271,691295,691338,691355,691488,691602,691646,691706,691728,692116,692157,692310,692466,692499,693653,693819,694179,694263,694417,694716,694744,694747,694795,694869,694981,694987,694993,695041,695096,695396,695484,695537,695552,695561,695619,695684,695835,695840,695868,695935,695977,696016,696094,696433,696720,697085,697868,698128,699289,700261,700507,700602,700981,701316,701783,701830,701862,702187,702205-702248,702267,702547,702561,702580,702602,702609,702616,702653,702656,702957,703191,703239,703309,703501,703513,703548,704584,704937,704997,705150,705235,705274,705340,705446,705548,705614,705692,705708,706482,706631,706675,706900,706909,707034,707089,707100,707902,708035,708044,708074,708410,708417,708550,708554,709353-709354,709425,710076,710150,71015
 4,711193,711388,711410,711490,711635,711949,711975,712194,712198,712238,712272,712299,712312,712670,712893,713082,713095-713096,713099,713584,713597,713737,713804,713899,714167-714168,714245,714255,717937-717961,718281-718448,718565,718620,718640,718665,718970,719017,719210,719215-719218,719222-719273,719305,719327-719680,720053,720119-720218,720238,720293-720316,720497,721221,721241,721501,722117,722129,722412,722988,723024,723338,723378,723716-723791,724333-724372,724433-724438,724449,724481,724485,724668,724780,724782,724785,724793,724795,724940,725071,725316,725332,725335,725348,725364,725418,725425-725426,725455,725506,725554,725562,725651,725671,725688,725754,725773,725799,725839,726342,726524,726631,726634,726637,726639,726692,726724,726769,726992,727096,727445,727521,727568,727692,727754,727781,727792,728070,728087,728696,728897,729051,729430,729449,729460,729863,730082,730139,730889,730891,731598,731604,731615,731631,731635,732036,732050,732320,732363,732411,732450,
 732710,732827,733512,733582,733901,734367,734462,734666,734762,734772,734812,734836,734965,735113,735252,735722-735723,735729,735734,735751,735782,735787,735987,736352,736358-736362,736408,736423,736621

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

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=736740&r1=736739&r2=736740&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
Thu Jan 22 10:44:27 2009
@@ -40,6 +40,7 @@
 import org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.jaxrs.model.OperationResourceInfoStack;
 import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.provider.ProviderFactory;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
@@ -53,55 +54,56 @@
 public class JAXRSInvoker extends AbstractInvoker {
     private static final Logger LOG = LogUtils.getL7dLogger(JAXRSServiceFactoryBean.class);
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JAXRSInvoker.class);
-    
+
     private List<Object> resourceObjects;
 
     public JAXRSInvoker() {
     }
-    
+
     public JAXRSInvoker(List<Object> resourceObjects) {
         this.resourceObjects = resourceObjects;
     }
     public Object invoke(Exchange exchange, Object request) {
         return invoke(exchange, request, resourceObjects);
-    }    
+    }
     @SuppressWarnings("unchecked")
     public Object invoke(Exchange exchange, Object request, List<Object> resources)
{
-        
+
         Response response = exchange.get(Response.class);
         if (response != null) {
             // this means a blocking request filter provided a Response
             // or earlier exception has been converted to Response
-            
+
             //TODO: should we remove response from exchange ?
-            //      or should we rather ignore content list and have 
-            //      Response set here for all cases and extract it 
-            //      in the out interceptor instead of dealing with the contents list ?  
-            return new MessageContentsList(response);    
+            //      or should we rather ignore content list and have
+            //      Response set here for all cases and extract it
+            //      in the out interceptor instead of dealing with the contents list ?
+            return new MessageContentsList(response);
         }
-        
+
         OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
+        pushOntoStack(ori, exchange.getInMessage());
 
         ClassResourceInfo cri = ori.getClassResourceInfo();
         Object resourceObject = getServiceObject(exchange, resources);
-        
+
         Method methodToInvoke = InjectionUtils.checkProxy(
              cri.getMethodDispatcher().getMethod(ori), resourceObject);
-        
+
         if (cri.isRoot()) {
-            JAXRSUtils.handleSetters(ori, resourceObject, 
+            JAXRSUtils.handleSetters(ori, resourceObject,
                                      exchange.getInMessage());
-            
-            InjectionUtils.injectContextFields(resourceObject, 
-                                               ori.getClassResourceInfo(), 
+
+            InjectionUtils.injectContextFields(resourceObject,
+                                               ori.getClassResourceInfo(),
                                                exchange.getInMessage());
-            InjectionUtils.injectResourceFields(resourceObject, 
-                                            ori.getClassResourceInfo(), 
+            InjectionUtils.injectResourceFields(resourceObject,
+                                            ori.getClassResourceInfo(),
                                             exchange.getInMessage());
         }
 
         String baseAddress = HttpUtils.getOriginalAddress(exchange.getInMessage());
-        
+
         List<Object> params = null;
         if (request instanceof List) {
             params = CastUtils.cast((List<?>)request);
@@ -125,47 +127,47 @@
             }
             return new MessageContentsList(excResponse);
         }
-        
+
         if (ori.isSubResourceLocator()) {
             try {
                 Message msg = exchange.getInMessage();
-                MultivaluedMap<String, String> values = new MetadataMap<String,
String>();                 
+                MultivaluedMap<String, String> values = new MetadataMap<String,
String>();
                 String subResourcePath = (String)msg.get(JAXRSInInterceptor.RELATIVE_PATH);
-                String httpMethod = (String)msg.get(Message.HTTP_REQUEST_METHOD); 
+                String httpMethod = (String)msg.get(Message.HTTP_REQUEST_METHOD);
                 String contentType = (String)msg.get(Message.CONTENT_TYPE);
                 if (contentType == null) {
                     contentType = "*/*";
                 }
-                List<MediaType> acceptContentType = 
+                List<MediaType> acceptContentType =
                     (List<MediaType>)msg.getExchange().get(Message.ACCEPT_CONTENT_TYPE);
-                
-                result = checkResultObject(result, subResourcePath); 
-                
+
+                result = checkResultObject(result, subResourcePath);
+
                 List<Object> newResourceObjects = new ArrayList<Object>();
                 newResourceObjects.add(result);
-            
+
                 ClassResourceInfo subCri = cri.getSubResource(
-                     methodToInvoke.getReturnType(), 
+                     methodToInvoke.getReturnType(),
                      ClassHelper.getRealClass(result));
                 if (subCri == null) {
-                    org.apache.cxf.common.i18n.Message errorM = 
-                        new org.apache.cxf.common.i18n.Message("NO_SUBRESOURCE_FOUND",  
-                                                               BUNDLE, 
+                    org.apache.cxf.common.i18n.Message errorM =
+                        new org.apache.cxf.common.i18n.Message("NO_SUBRESOURCE_FOUND",
+                                                               BUNDLE,
                                                                subResourcePath);
                     LOG.severe(errorM.toString());
                     throw new WebApplicationException(404);
                 }
-                
-                OperationResourceInfo subOri = JAXRSUtils.findTargetMethod(subCri, 
-                                                         subResourcePath, 
-                                                         httpMethod, 
-                                                         values, 
-                                                         contentType, 
+
+                OperationResourceInfo subOri = JAXRSUtils.findTargetMethod(subCri,
+                                                         subResourcePath,
+                                                         httpMethod,
+                                                         values,
+                                                         contentType,
                                                          acceptContentType);
-                
-                
+
+
                 exchange.put(OperationResourceInfo.class, subOri);
-                msg.put(JAXRSInInterceptor.RELATIVE_PATH, 
+                msg.put(JAXRSInInterceptor.RELATIVE_PATH,
                         values.getFirst(URITemplate.FINAL_MATCH_GROUP));
                 msg.put(URITemplate.TEMPLATE_PARAMETERS, values);
                 // work out request parameters for the sub-resouce class. Here we
@@ -174,26 +176,26 @@
                 //have a parameter that read from entitybody.
                 List<Object> newParams = JAXRSUtils.processParameters(subOri, values,
msg);
                 msg.setContent(List.class, newParams);
-                
+
                 return this.invoke(exchange, newParams, newResourceObjects);
             } catch (WebApplicationException ex) {
                 Response excResponse = JAXRSUtils.convertFaultToResponse(ex, baseAddress);
                 return new MessageContentsList(excResponse);
             }
         }
-        
+
         return result;
-    }    
-    
+    }
+
     public Object getServiceObject(Exchange exchange) {
         return getServiceObject(exchange, resourceObjects);
     }
     public Object getServiceObject(Exchange exchange, List<Object> resources) {
         Object serviceObject = null;
-        
+
         OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
         ClassResourceInfo cri = ori.getClassResourceInfo();
-        
+
         if (resources != null) {
             Class c  = cri.getResourceClass();
             for (Object resourceObject : resources) {
@@ -203,24 +205,24 @@
                 }
             }
         }
-        
+
         if (serviceObject == null) {
             serviceObject = cri.getResourceProvider().getInstance();
         }
-        
+
         return serviceObject;
     }
-    
+
     private static Object checkResultObject(Object result, String subResourcePath) {
         if (result == null) {
-            org.apache.cxf.common.i18n.Message errorM = 
-                new org.apache.cxf.common.i18n.Message("NULL_SUBRESOURCE",  
-                                                       BUNDLE, 
+            org.apache.cxf.common.i18n.Message errorM =
+                new org.apache.cxf.common.i18n.Message("NULL_SUBRESOURCE",
+                                                       BUNDLE,
                                                        subResourcePath);
             LOG.severe(errorM.toString());
             throw new WebApplicationException(500);
         }
-        
+
         //the result becomes the object that will handle the request
         if (result instanceof MessageContentsList) {
             result = ((MessageContentsList)result).get(0);
@@ -229,7 +231,16 @@
         } else if (result.getClass().isArray()) {
             result = ((Object[])result)[0];
         }
-        
+
         return result;
     }
+
+    private void pushOntoStack(OperationResourceInfo ori, Message msg) {
+        OperationResourceInfoStack stack = msg.get(OperationResourceInfoStack.class);
+        if (stack == null) {
+            stack = new OperationResourceInfoStack();
+            msg.put(OperationResourceInfoStack.class, stack);
+        }
+        stack.push(ori);
+    }
 }

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java?rev=736740&r1=736739&r2=736740&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
Thu Jan 22 10:44:27 2009
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.jaxrs.impl;
 
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -27,6 +28,7 @@
 import java.util.List;
 import java.util.Map;
 
+import javax.ws.rs.Path;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.UriBuilder;
@@ -35,7 +37,7 @@
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 
 public class UriBuilderImpl extends UriBuilder {
-    
+
     private String scheme;
     private String userInfo;
     private int port;
@@ -44,11 +46,10 @@
     private MultivaluedMap<String, String> matrix;
     private String fragment;
     private MultivaluedMap<String, String> query;
-    
-       
+
     public UriBuilderImpl() {
     }
-    
+
     public UriBuilderImpl(URI uri) {
         setUriParts(uri);
     }
@@ -57,13 +58,7 @@
     public URI build() throws UriBuilderException {
         
         try {
-            return new URI(scheme, 
-                           userInfo, 
-                           host, 
-                           port, 
-                           buildPath(), 
-                           buildQuery(), 
-                           fragment);
+            return new URI(scheme, userInfo, host, port, buildPath(), buildQuery(), fragment);
         } catch (URISyntaxException ex) {
             throw new UriBuilderException("URI can not be built", ex);
         }
@@ -82,13 +77,14 @@
         return null;
     }
 
-//CHECKSTYLE:OFF
+    // CHECKSTYLE:OFF
     @Override
     public UriBuilder clone() {
         return new UriBuilderImpl(build());
     }
-//CHECKSTYLE:ON
-    
+
+    // CHECKSTYLE:ON
+
     @Override
     public UriBuilder encode(boolean enable) {
         //this.encode = enable;
@@ -107,6 +103,7 @@
         return this;
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public UriBuilder matrixParam(String name, String value) throws IllegalArgumentException
{
         matrix.putSingle(name, value);
@@ -118,28 +115,72 @@
         if (paths == null) {
             paths = new ArrayList<PathSegment>();
         }
-        for (String segment : segments) {
-            paths.add(new PathSegmentImpl(segment, false));
+        for (String seg : segments) {
+            paths.addAll(JAXRSUtils.getPathSegments(seg, false));
         }
         return this;
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public UriBuilder path(Class resource) throws IllegalArgumentException {
-        // TODO Auto-generated method stub
-        return null;
+        if (resource == null) {
+            throw new IllegalArgumentException("resource is null");
+        }
+        Annotation ann = resource.getAnnotation(Path.class);
+        if (ann == null) {
+            throw new IllegalArgumentException("Class '" + resource.getCanonicalName()
+                                               + "' is not annotated with Path");
+        }
+        // path(String) decomposes multi-segment path when necessary
+        return path(((Path)ann).value());
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public UriBuilder path(Method... methods) throws IllegalArgumentException {
-        // TODO Auto-generated method stub
-        return null;
+        if (methods == null) {
+            throw new IllegalArgumentException("methods is null");
+        }
+        for (Method method : methods) {
+            if (method == null) {
+                throw new IllegalArgumentException("method is null");
+            }
+            Annotation ann = method.getAnnotation(Path.class);
+            if (ann == null) {
+                throw new IllegalArgumentException("Method '" + method.getClass().getCanonicalName()
+ "."
+                                                   + method.getName() + "' is not annotated
with Path");
+            }
+            // path(String) decomposes multi-segment path when necessary
+            path(((Path)ann).value());
+        }
+        return this;
     }
 
     @Override
     public UriBuilder path(Class resource, String method) throws IllegalArgumentException
{
-        // TODO Auto-generated method stub
-        return null;
+        if (resource == null) {
+            throw new IllegalArgumentException("resource is null");
+        }
+        if (method == null) {
+            throw new IllegalArgumentException("method is null");
+        }
+        Annotation foundAnn = null;
+        for (Method meth : resource.getMethods()) {
+            if (meth.getName().equals(method)) {
+                Annotation ann = meth.getAnnotation(Path.class);
+                if (foundAnn != null && ann != null) {
+                    throw new IllegalArgumentException("Multiple Path annotations for '"
+ method
+                                                       + "' overloaded method");
+                }
+                foundAnn = ann;
+            }
+        }
+        if (foundAnn == null) {
+            throw new IllegalArgumentException("No Path annotation for '" + method + "' method");
+        }
+        // path(String) decomposes multi-segment path when necessary
+        return path(((Path)foundAnn).value());
     }
 
     @Override
@@ -177,7 +218,19 @@
 
     @Override
     public UriBuilder schemeSpecificPart(String ssp) throws IllegalArgumentException {
-        //schemeSpPart = ssp;
+        // scheme-specific part is whatever after ":" of URI
+        // see: http://en.wikipedia.org/wiki/URI_scheme
+        try {
+            URI uri = new URI("whatever://" + ssp);
+            port = uri.getPort();
+            host = uri.getHost();
+            paths = JAXRSUtils.getPathSegments(uri.getPath(), false);
+            fragment = uri.getFragment();
+            query = JAXRSUtils.getStructuredParams(uri.getQuery(), "&", true);
+            userInfo = uri.getUserInfo();
+        } catch (URISyntaxException e) {
+            throw new IllegalArgumentException("Wrong syntax of scheme-specific part", e);
+        }
         return this;
     }
 
@@ -192,6 +245,24 @@
         this.userInfo = ui;
         return this;
     }
+    
+    @Override
+    public boolean isEncode() {
+        throw new UnsupportedOperationException("Not implemented :/");        
+    }
+  
+    @Override
+    public UriBuilder extension(String arg0) {
+        throw new UnsupportedOperationException("Not implemented :/");
+    }
+    
+    @Override
+    public UriBuilder replacePath(String... path) throws IllegalArgumentException {
+        for (String p : path) {
+            paths = JAXRSUtils.getPathSegments(p, false);
+        }
+        return this;
+    }
 
     private void setUriParts(URI uri) {
         scheme = uri.getScheme();
@@ -202,22 +273,26 @@
         query = JAXRSUtils.getStructuredParams(uri.getQuery(), "&", true);
         userInfo = uri.getUserInfo();
     }
-    
+
     private String buildPath() {
         StringBuilder sb = new StringBuilder();
         for (PathSegment ps : paths) {
             String p = ps.getPath();
-            if (!p.startsWith("/")) {
-                sb.append('/');    
+            if (!p.startsWith("/") && (sb.length() == 0 || sb.charAt(sb.length()
- 1) != '/')) {
+                sb.append('/');
             }
             sb.append(p);
         }
         return sb.toString();
-        
+
     }
-    
+
     private String buildQuery() {
         StringBuilder b = new StringBuilder();
+        if (query == null) {
+            return null;
+        }
+        
         for (Iterator<Map.Entry<String, List<String>>> it = query.entrySet().iterator();
it.hasNext();) {
             Map.Entry<String, List<String>> entry = it.next();
             b.append(entry.getKey()).append('=').append(entry.getValue().get(0));
@@ -228,23 +303,4 @@
         return b.length() > 0 ? b.toString() : null;
     }
 
-    @Override
-    public boolean isEncode() {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
-    @Override
-    public UriBuilder replacePath(String... segments) throws IllegalArgumentException {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    public UriBuilder extension(String arg0) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-    
-    
 }

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java?rev=736740&r1=736739&r2=736740&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java
Thu Jan 22 10:44:27 2009
@@ -20,29 +20,42 @@
 package org.apache.cxf.jaxrs.impl;
 
 import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.logging.Logger;
 
+import javax.ws.rs.Path;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.jaxrs.model.OperationResourceInfoStack;
 import org.apache.cxf.jaxrs.model.URITemplate;
+import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Message;
 
 public class UriInfoImpl implements UriInfo {
+    private static final Logger LOG = LogUtils.getL7dLogger(UriInfoImpl.class);
 
-    private MultivaluedMap<String, String> templateParams; 
+    private MultivaluedMap<String, String> templateParams;
     private Message message;
-    
+    private OperationResourceInfoStack stack;
+
     public UriInfoImpl(Message m, MultivaluedMap<String, String> templateParams) {
         this.message = m;
         this.templateParams = templateParams;
+        if (m != null) {
+            this.stack = m.get(OperationResourceInfoStack.class);
+        }
     }
-    
+
     public URI getAbsolutePath() {
         String path = getAbsolutePathAsString();
         return URI.create(path);
@@ -66,7 +79,6 @@
     }
 
     public String getPath(boolean decode) {
-        
         return doGetPath(decode, true);
     }
 
@@ -83,9 +95,7 @@
     }
 
     public MultivaluedMap<String, String> getQueryParameters(boolean decode) {
-        return JAXRSUtils.getStructuredParams((String)message.get(Message.QUERY_STRING),
-                                              "&",
-                                              decode);
+        return JAXRSUtils.getStructuredParams((String)message.get(Message.QUERY_STRING),
"&", decode);
     }
 
     public URI getRequestUri() {
@@ -111,26 +121,52 @@
             if (entry.getKey().equals(URITemplate.FINAL_MATCH_GROUP)) {
                 continue;
             }
-            values.add(entry.getKey(), 
-                       decode ? JAXRSUtils.uriDecode(entry.getValue().get(0)) 
-                              : entry.getValue().get(0));
+            values.add(entry.getKey(), decode ? JAXRSUtils.uriDecode(entry.getValue().get(0))
: entry
+                .getValue().get(0));
         }
         return values;
     }
 
-    public List<String> getAncestorResourceURIs() {
-        // TODO Auto-generated method stub
-        return null;
+    
+    public List<Object> getAncestorResources() {
+        if (stack != null) {
+            List<Object> resources = new ArrayList<Object>(stack.size());
+            for (OperationResourceInfo ori : stack) {
+                resources.add(ori.getClassResourceInfo().getResourceClass());
+            }
+            return resources;
+        }
+        LOG.fine("No resource stack information, returning empty list");
+        return Collections.emptyList();
     }
 
-    public List<Object> getAncestorResources() {
-        // TODO Auto-generated method stub
-        return null;
+    public List<String> getAncestorResourceURIs() {
+        return getAncestorResourceURIs(true);
     }
 
-    public List<String> getAncestorResourceURIs(boolean arg0) {
-        // TODO Auto-generated method stub
-        return null;
+    public List<String> getAncestorResourceURIs(boolean decode) {
+        if (stack != null) {
+            List<String> uris = new ArrayList<String>(stack.size());
+            String sum = "";
+            for (OperationResourceInfo ori : stack) {
+                Path[] paths = {
+                    (Path)AnnotationUtils.getClassAnnotation(ori.getClassResourceInfo().getResourceClass(),
+                                                             Path.class),
+                    (Path)AnnotationUtils.getMethodAnnotation(ori.getAnnotatedMethod(), Path.class)
+                };
+                for (Path p : paths) {
+                    if (p != null) {
+                        String v = p.value();
+                        sum += "/" + (decode ? JAXRSUtils.uriDecode(v) : v);
+                    }
+                }
+                UriBuilder ub = UriBuilder.fromPath(sum);
+                uris.add(ub.build().normalize().getPath());
+            }
+            return uris;
+        }
+        LOG.fine("No resource stack information, returning empty list");
+        return Collections.emptyList();
     }
 
 
@@ -148,7 +184,7 @@
         String path = HttpUtils.getPathToMatch(message, addSlash);
         return decode ? JAXRSUtils.uriDecode(path) : path;
     }
-    
+
     private String getAbsolutePathAsString() {
         String address = getBaseUri().toString();
         String path = doGetPath(true, false);

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=736740&r1=736739&r2=736740&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Thu Jan 22 10:44:27 2009
@@ -123,6 +123,7 @@
         return pf;
     }
 
+    @SuppressWarnings("unchecked")
     public <T> ContextResolver<T> createContextResolver(Type contextType, Message
m) {
         for (ProviderInfo<ContextResolver> cr : userContextResolvers) {
             Type[] types = cr.getProvider().getClass().getGenericInterfaces();

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java?rev=736740&r1=736739&r2=736740&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
Thu Jan 22 10:44:27 2009
@@ -19,31 +19,104 @@
 
 package org.apache.cxf.jaxrs.impl;
 
+import java.lang.reflect.Method;
 import java.net.URI;
 
+import org.apache.cxf.jaxrs.resources.Book;
+import org.apache.cxf.jaxrs.resources.BookStore;
+import org.apache.cxf.jaxrs.resources.UriBuilderWrongAnnotations;
+
 import org.junit.Assert;
 import org.junit.Test;
 
 public class UriBuilderImplTest extends Assert {
-    
+
     @Test
     public void testUri() throws Exception {
         URI uri = new URI("http://foo/bar/baz?query=1#fragment");
         URI newUri = new UriBuilderImpl().uri(uri).build();
         assertEquals("URI is not built correctly", newUri, uri);
     }
-    
+
     @Test
     public void testAddPath() throws Exception {
         URI uri = new URI("http://foo/bar");
         URI newUri = new UriBuilderImpl().uri(uri).path("baz").build();
-        assertEquals("URI is not built correctly", newUri, 
-                     new URI("http://foo/bar/baz"));
+        assertEquals("URI is not built correctly", new URI("http://foo/bar/baz"), newUri);
         newUri = new UriBuilderImpl().uri(uri).path("baz", "/1", "/2").build();
-        assertEquals("URI is not built correctly", newUri, 
-                     new URI("http://foo/bar/baz/1/2"));
+        assertEquals("URI is not built correctly", new URI("http://foo/bar/baz/1/2"), newUri);
+    }
+
+    @Test
+    public void testAddPathSlashes() throws Exception {
+        URI uri = new URI("http://foo/");
+        URI newUri = new UriBuilderImpl().uri(uri).path("/bar").path("baz/").path("/blah/").build();
+        assertEquals("URI is not built correctly", new URI("http://foo/bar/baz/blah/"), newUri);
+    }
+
+    @Test
+    public void testAddPathClass() throws Exception {
+        URI uri = new URI("http://foo/");
+        URI newUri = new UriBuilderImpl().uri(uri).path(BookStore.class).path("bar").build();
+        assertEquals("URI is not built correctly", new URI("http://foo/bookstore/bar"), newUri);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testAddPathClassNull() throws Exception {
+        new UriBuilderImpl().path((Class)null).build();
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testAddPathClassNoAnnotation() throws Exception {
+        new UriBuilderImpl().path(this.getClass()).build();
+    }
+
+    @Test
+    public void testAddPathClassMethod() throws Exception {
+        URI uri = new URI("http://foo/");
+        URI newUri = new UriBuilderImpl().uri(uri).path(BookStore.class, "updateBook").path("bar").build();
+        assertEquals("URI is not built correctly", new URI("http://foo/books/bar"), newUri);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testAddPathClassMethodNull1() throws Exception {
+        new UriBuilderImpl().path(null, "methName").build();
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testAddPathClassMethodNull2() throws Exception {
+        new UriBuilderImpl().path(BookStore.class, null).build();
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testAddPathClassMethodTooMany() throws Exception {
+        new UriBuilderImpl().path(UriBuilderWrongAnnotations.class, "overloaded").build();
     }
-    
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testAddPathClassMethodTooLess() throws Exception {
+        new UriBuilderImpl().path(BookStore.class, "nonexistingMethod").build();
+    }
+
+    @Test
+    public void testAddPathMethod() throws Exception {
+        Method meth = BookStore.class.getMethod("updateBook", Book.class);
+        URI uri = new URI("http://foo/");
+        URI newUri = new UriBuilderImpl().uri(uri).path(meth).path("bar").build();
+        assertEquals("URI is not built correctly", new URI("http://foo/books/bar"), newUri);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testAddPathMethodNull() throws Exception {
+        new UriBuilderImpl().path((Method)null).build();
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testAddPathMethodNoAnnotation() throws Exception {
+        Method noAnnot = BookStore.class.getMethod("getBook", String.class);
+        new UriBuilderImpl().path(noAnnot).build();
+    }
+
     @Test
     public void testSchemeHostPortQueryFragment() throws Exception {
         URI uri;
@@ -52,11 +125,9 @@
         } else {
             uri = new URI("http://foo:1234/bar?n1=v1&n2=v2#fragment");
         }
-        URI newUri = new UriBuilderImpl().scheme("http").host("foo")
-                     .port(1234).path("bar")
-                     .queryParam("n1", "v1").queryParam("n2", "v2")
-                     .fragment("fragment").build();
-        assertEquals("URI is not built correctly", newUri, uri);
+        URI newUri = new UriBuilderImpl().scheme("http").host("foo").port(1234).path("bar").queryParam("n1",
+                                                                                        
              "v1")
+            .queryParam("n2", "v2").fragment("fragment").build();
+        assertEquals("URI is not built correctly", uri, newUri);
     }
-
 }

Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/Chapter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/Chapter.java?rev=736740&r1=736739&r2=736740&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/Chapter.java
(original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/Chapter.java
Thu Jan 22 10:44:27 2009
@@ -19,9 +19,15 @@
 
 package org.apache.cxf.systest.jaxrs;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.ProduceMime;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
 import javax.xml.bind.annotation.XmlRootElement;
 
 
@@ -61,4 +67,23 @@
         return this;
     }
 
+    
+    @GET
+    @Path("/matched-resources")
+    @ProduceMime("text/plain")
+    public String getMatchedResources(@Context UriInfo ui) {
+        List<String> list = new ArrayList<String>();
+        for (Object obj : ui.getAncestorResources()) {
+            list.add(obj.toString());
+        }
+        return list.toString();
+    }
+
+    @GET
+    @Path("/matched%21uris")
+    @ProduceMime("text/plain")
+    public String getMatchedUris(@Context UriInfo ui, 
+                                 @QueryParam("decode") String decode) {
+        return ui.getAncestorResourceURIs(Boolean.parseBoolean(decode)).toString();     
  
+    }
 }

Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=736740&r1=736739&r2=736740&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Thu Jan 22 10:44:27 2009
@@ -685,6 +685,39 @@
         }  
     }
     
+    @Test
+    public void testUriInfoMatchedResources() throws Exception {
+        getAndCompare("http://localhost:9080/bookstore/"
+                      + "booksubresource/123/chapters/sub/1/matched-resources", 
+                      "[class org.apache.cxf.systest.jaxrs.BookStore, " 
+                      + "class org.apache.cxf.systest.jaxrs.Book, "
+                      + "class org.apache.cxf.systest.jaxrs.Chapter]", 
+                      "text/plain", 200);
+    }
+
+    @Test
+    public void testUriInfoMatchedUrisDecode() throws Exception {
+        String expected = "[/bookstore/booksubresource/{bookId}/, "
+                          + "/bookstore/booksubresource/{bookId}/chapters/sub/{chapterid}/,
"
+                          + "/bookstore/booksubresource/{bookId}/chapters/sub/{chapterid}/matched!uris]";
+        getAndCompare("http://localhost:9080/bookstore/"
+                      + "booksubresource/123/chapters/sub/1/matched%21uris?decode=true",

+                      expected, 
+                      "text/plain", 200);
+    }
+
+    @Test
+    public void testUriInfoMatchedUrisNoDecode() throws Exception {
+        //note '%21' instead of '!'
+        String expected = "[/bookstore/booksubresource/{bookId}/, "
+            + "/bookstore/booksubresource/{bookId}/chapters/sub/{chapterid}/, "
+            + "/bookstore/booksubresource/{bookId}/chapters/sub/{chapterid}/matched%21uris]";
+        getAndCompare("http://localhost:9080/bookstore/"
+                      + "booksubresource/123/chapters/sub/1/matched%21uris?decode=false",

+                      expected,
+                      "text/plain", 200);
+    }
+    
     private void getAndCompareAsStrings(String address, 
                                         String resourcePath,
                                         String acceptType,



Mime
View raw message