cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r723394 - in /cxf/branches/2.1.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/sr...
Date Thu, 04 Dec 2008 18:45:24 GMT
Author: sergeyb
Date: Thu Dec  4 10:45:24 2008
New Revision: 723394

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

........
  r720497 | sergeyb | 2008-11-25 13:46:07 +0000 (Tue, 25 Nov 2008) | 1 line
  
  JAXRS : support for FormParams, improving the way MatrixParam are dealt with
........

Added:
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java
      - copied unchanged from r720497, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.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/provider/FormEncodingReaderProvider.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/FormEncodingReaderProviderTest.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java

Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Dec  4 10:45:24 2008
@@ -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,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,718439,718448,718565,718620,718640,718665,718970,719017,719210,719215-719218,719222,719273,719305,719327,719354,719362,719368,719382,719649,719680,720053,720119,720238,723024
+/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,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,718439,718448,718565,718620,718640,718665,718970,719017,719210,719215-719218,719222,719273,719305,719327,719354,719362,719368,719382,719649,719680,720053,720119,720238,720497,723024

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/provider/FormEncodingReaderProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingReaderProvider.java?rev=723394&r1=723393&r2=723394&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingReaderProvider.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingReaderProvider.java
Thu Dec  4 10:45:24 2008
@@ -19,40 +19,29 @@
 
 package org.apache.cxf.jaxrs.provider;
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
-import java.util.Arrays;
-import java.util.List;
 
 import javax.ws.rs.ConsumeMime;
+import javax.ws.rs.Encoded;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.Provider;
 
-import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
+import org.apache.cxf.jaxrs.utils.AnnotationUtils;
+import org.apache.cxf.jaxrs.utils.FormUtils;
 
 @ConsumeMime("application/x-www-form-urlencoded")
 @Provider
 public final class FormEncodingReaderProvider implements MessageBodyReader<Object>
{
 
-    private static final char SPACE_CHAR = '+';
-    private static final String NEXT_LINE = "%0D%0A";
-    
-    
-    private boolean decode;
     private FormValidator validator;
     
-    public void setDecode(boolean formDecoding) {
-        decode = formDecoding;
-    }
-    
     public void setValidator(FormValidator formValidator) {
         validator = formValidator;
     }
@@ -68,14 +57,9 @@
         throws IOException {
         try {
 
-            String charset = "UTF-8";
-
-            ByteArrayOutputStream bos = new ByteArrayOutputStream();
-            copy(is, bos, 1024);
-            String postBody = new String(bos.toByteArray(), charset);
-
             MultivaluedMap<String, String> params = createMap(clazz);
-            populateMap(params, postBody);
+            populateMap(params, is, 
+                        AnnotationUtils.getAnnotation(annotations, Encoded.class) == null);
             validateMap(params);
             return params;
         } catch (WebApplicationException e) {
@@ -85,17 +69,6 @@
         }
     }
 
-    public static void copy(final InputStream input, final OutputStream output, final int
bufferSize)
-        throws IOException {
-        final byte[] buffer = new byte[bufferSize];
-        int n = 0;
-        n = input.read(buffer);
-        while (-1 != n) {
-            output.write(buffer, 0, n);
-            n = input.read(buffer);
-        }
-    }
-
     @SuppressWarnings("unchecked")
     protected MultivaluedMap<String, String> createMap(Class<?> clazz) throws
Exception {
         if (clazz == MultivaluedMap.class) {
@@ -111,27 +84,9 @@
      * @return a Map of parameters.
      */
     protected void populateMap(MultivaluedMap<String, String> params, 
-                               String body) {
-        if (!StringUtils.isEmpty(body)) {
-            List<String> parts = Arrays.asList(body.split("&"));
-            for (String part : parts) {
-                String[] keyValue = part.split("=");
-                // Change to add blank string if key but not value is specified
-                if (keyValue.length == 2) {
-                    if (decode) {
-                        String[] values = keyValue[1].split(NEXT_LINE);
-                        for (String value : values) {
-                            params.add(keyValue[0], 
-                                       value.replace(SPACE_CHAR, ' '));
-                        }
-                    } else {
-                        params.add(keyValue[0], keyValue[1]);
-                    }
-                } else {
-                    params.add(keyValue[0], "");
-                }
-            }
-        }
+                               InputStream is,
+                               boolean decode) {
+        FormUtils.populateMap(params, FormUtils.readBody(is), decode);
     }
     
     protected void validateMap(MultivaluedMap<String, String> params) {

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java?rev=723394&r1=723393&r2=723394&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
Thu Dec  4 10:45:24 2008
@@ -25,6 +25,7 @@
 import java.lang.reflect.Type;
 
 import javax.ws.rs.ConsumeMime;
+import javax.ws.rs.PathParam;
 import javax.ws.rs.ProduceMime;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
@@ -32,6 +33,7 @@
 import javax.ws.rs.ext.MessageBodyWriter;
 
 import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 
 @ProduceMime("text/plain")
@@ -52,7 +54,9 @@
     public Object readFrom(Class<Object> type, Type genType, Annotation[] anns, MediaType
mt, 
                            MultivaluedMap<String, String> headers, InputStream is)
throws IOException {
         return InjectionUtils.handleParameter(
-                    IOUtils.readStringFromStream(is).toString(), type);
+                    IOUtils.readStringFromStream(is).toString(), 
+                    type,
+                    AnnotationUtils.getAnnotation(anns, PathParam.class) != null);
     }
 
     public long getSize(Object t) {

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=723394&r1=723393&r2=723394&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Thu Dec  4 10:45:24 2008
@@ -44,6 +44,7 @@
 import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.SecurityContext;
 import javax.ws.rs.core.UriInfo;
@@ -54,6 +55,7 @@
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.PrimitiveUtils;
 import org.apache.cxf.jaxrs.ext.MessageContext;
+import org.apache.cxf.jaxrs.impl.PathSegmentImpl;
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalContextResolver;
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders;
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpServletRequest;
@@ -138,7 +140,17 @@
         }
     }
     
-    public static Object handleParameter(String value, Class<?> pClass) {
+    public static Object handleParameter(String value, Class<?> pClass, boolean pathParam)
{
+        
+        if (pathParam) {
+            PathSegment ps = new PathSegmentImpl(value, false);    
+            if (PathSegment.class.isAssignableFrom(pClass)) {
+                return ps;   
+            } else {
+                value = ps.getPath();                 
+            }
+        }
+        
         if (pClass.isPrimitive()) {
             return PrimitiveUtils.read(value, pClass);
         }
@@ -160,10 +172,12 @@
         } catch (Exception ex) {
             // no luck
         }
+        
         return null;
     }
     
-    public static Object handleBean(Class<?> paramType, MultivaluedMap<String, String>
values) {
+    public static Object handleBean(Class<?> paramType, MultivaluedMap<String, String>
values,
+                                    boolean pathParam) {
         Object bean = null;
         try {
             bean = paramType.newInstance();
@@ -173,7 +187,8 @@
                     if (m.getName().equalsIgnoreCase("set" + entry.getKey())
                         && m.getParameterTypes().length == 1) {
                         Object paramValue = handleParameter(entry.getValue().get(0), 
-                                                            m.getParameterTypes()[0]);
+                                                            m.getParameterTypes()[0],
+                                                            pathParam);
                         if (paramValue != null) {
                             injectThroughMethod(bean, m, paramValue);
                             injected = true;
@@ -187,7 +202,7 @@
                 for (Field f : paramType.getFields()) {
                     if (f.getName().equalsIgnoreCase(entry.getKey())) {
                         Object paramValue = handleParameter(entry.getValue().get(0), 
-                                                            f.getType());
+                                                            f.getType(), pathParam);
                         if (paramValue != null) {
                             injectFieldValue(f, bean, paramValue);
                             break;
@@ -205,14 +220,14 @@
     
     @SuppressWarnings("unchecked")
     public static Object injectIntoList(Type genericType, List<String> values,
-                                        boolean decoded) {
+                                        boolean decoded, boolean pathParam) {
         Class<?> realType = InjectionUtils.getActualType(genericType);
         List theValues = new ArrayList();
         for (String r : values) {
             if (decoded) {
                 r = JAXRSUtils.uriDecode(r);
             }
-            Object o = InjectionUtils.handleParameter(r, realType);
+            Object o = InjectionUtils.handleParameter(r, realType, pathParam);
             if (o != null) {
                 theValues.add(o);
             }
@@ -224,14 +239,14 @@
     
     @SuppressWarnings("unchecked")
     public static Object injectIntoSet(Type genericType, List<String> values, 
-                                       boolean sorted, boolean decoded) {
+                                       boolean sorted, boolean decoded, boolean pathParam)
{
         Class<?> realType = InjectionUtils.getActualType(genericType);
         Set theValues = sorted ? new TreeSet() : new HashSet();
         for (String r : values) {
             if (decoded) {
                 r = JAXRSUtils.uriDecode(r);
             }
-            Object o = InjectionUtils.handleParameter(r, realType);
+            Object o = InjectionUtils.handleParameter(r, realType, pathParam);
             if (o != null) {
                 theValues.add(o);
             }
@@ -244,7 +259,8 @@
                                                Type genericType,
                                                String defaultValue,
                                                boolean isLast,
-                                               boolean decoded) {
+                                               boolean decoded,
+                                               boolean pathParam) {
         
         if (paramValues == null) {
             if (defaultValue != null) {
@@ -260,11 +276,11 @@
         }
         
         if (List.class.isAssignableFrom(paramType)) {
-            return InjectionUtils.injectIntoList(genericType, paramValues, decoded);
+            return InjectionUtils.injectIntoList(genericType, paramValues, decoded, pathParam);
         } else if (Set.class.isAssignableFrom(paramType)) {
-            return InjectionUtils.injectIntoSet(genericType, paramValues, false, decoded);
+            return InjectionUtils.injectIntoSet(genericType, paramValues, false, decoded,
pathParam);
         } else if (SortedSet.class.isAssignableFrom(paramType)) {
-            return InjectionUtils.injectIntoSet(genericType, paramValues, true, decoded);
+            return InjectionUtils.injectIntoSet(genericType, paramValues, true, decoded,
pathParam);
         } else {
             String result = null;
             if (paramValues.size() > 0) {
@@ -275,7 +291,7 @@
                 if (decoded) {
                     result = JAXRSUtils.uriDecode(result);
                 }
-                return InjectionUtils.handleParameter(result, paramType);
+                return InjectionUtils.handleParameter(result, paramType, pathParam);
             } else {
                 return null;
             }

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=723394&r1=723393&r2=723394&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
Thu Dec  4 10:45:24 2008
@@ -389,35 +389,37 @@
         boolean isEncoded = AnnotationUtils.isEncoded(anns, ori);
         String defaultValue = AnnotationUtils.getDefaultParameterValue(anns, ori);
         
+        Object result = null;
+        
         PathParam pathParam = AnnotationUtils.getAnnotation(anns, PathParam.class);
         if (pathParam != null) {
-            return readFromUriParam(pathParam, parameterClass, genericParam, path, 
+            result = readFromUriParam(pathParam, parameterClass, genericParam, path, 
                                     values, defaultValue, !isEncoded);
         } 
         
         QueryParam qp = AnnotationUtils.getAnnotation(anns, QueryParam.class);
         if (qp != null) {
-            return readQueryString(qp, parameterClass, genericParam, message, 
+            result = readQueryString(qp, parameterClass, genericParam, message, 
                                    defaultValue, !isEncoded);
         }
         
         MatrixParam mp = AnnotationUtils.getAnnotation(anns, MatrixParam.class);
         if (mp != null) {
-            return processMatrixParam(message, mp.value(), parameterClass, genericParam,

+            result = processMatrixParam(message, mp.value(), parameterClass, genericParam,

                                       defaultValue, !isEncoded);
         }
         
         CookieParam cookie = AnnotationUtils.getAnnotation(anns, CookieParam.class);
         if (cookie != null) {
-            return processCookieParam(message, cookie.value(), parameterClass, genericParam,
defaultValue);
+            result = processCookieParam(message, cookie.value(), parameterClass, genericParam,
defaultValue);
         } 
         
         HeaderParam hp = AnnotationUtils.getAnnotation(anns, HeaderParam.class);
         if (hp != null) {
-            return processHeaderParam(message, hp.value(), parameterClass, genericParam,
defaultValue);
+            result = processHeaderParam(message, hp.value(), parameterClass, genericParam,
defaultValue);
         } 
 
-        return null;
+        return result;
     }
     
     private static Object processMatrixParam(Message m, String key, 
@@ -427,20 +429,35 @@
         List<PathSegment> segments = JAXRSUtils.getPathSegments(
                                       (String)m.get(Message.REQUEST_URI), decode);
         if (segments.size() > 0) {
-            MultivaluedMap<String, String> params = 
-                segments.get(segments.size() - 1).getMatrixParameters();
-            List<String> values = params.get(key);
-            return InjectionUtils.createParameterObject(values, 
-                                                        pClass, 
-                                                        genericType,
-                                                        defaultValue,
-                                                        false,
-                                                        false);
+            MultivaluedMap<String, String> params = new MetadataMap<String, String>();

+            for (PathSegment ps : segments) {
+                MultivaluedMap<String, String> matrix = ps.getMatrixParameters();
+                for (Map.Entry<String, List<String>> entry : matrix.entrySet())
{
+                    for (String value : entry.getValue()) {                    
+                        params.add(entry.getKey(), value);
+                    }
+                }
+            }
+            
+            if ("".equals(key)) {
+                return InjectionUtils.handleBean(pClass, params, false);
+            } else {
+                List<String> values = params.get(key);
+                return InjectionUtils.createParameterObject(values, 
+                                                            pClass, 
+                                                            genericType,
+                                                            defaultValue,
+                                                            false,
+                                                            false,
+                                                            true);
+            }
         }
         
         return null;
     }
     
+    
+    
     public static MultivaluedMap<String, String> getMatrixParams(String path, boolean
decode) {
         int index = path.indexOf(';');
         return index == -1 ? new MetadataMap<String, String>()
@@ -461,7 +478,8 @@
                 }
             }
         }
-        return sb.length() > 0 ? InjectionUtils.handleParameter(sb.toString(), pClass)
: defaultValue;
+        return sb.length() > 0 ? InjectionUtils.handleParameter(sb.toString(), pClass,
false) 
+                               : defaultValue;
     }
     
     @SuppressWarnings("unchecked")
@@ -478,7 +496,8 @@
         if (pClass.isAssignableFrom(Cookie.class)) {
             return Cookie.valueOf(value.length() == 0 ? defaultValue : value);
         }
-        return value.length() > 0 ? InjectionUtils.handleParameter(value, pClass) : defaultValue;
+        return value.length() > 0 ? InjectionUtils.handleParameter(value, pClass, false)

+                                  : defaultValue;
     }
     
     public static Object createContextValue(Message m, Type genericType, Class<?> clazz)
{
@@ -548,20 +567,16 @@
                                            boolean  decoded) {
         String parameterName = uriParamAnnotation.value();
         if ("".equals(parameterName)) {
-            return InjectionUtils.handleBean(paramType, values);
+            return InjectionUtils.handleBean(paramType, values, true);
         } else {
             List<String> results = values.get(parameterName);
-            if (PathSegment.class.isAssignableFrom(paramType)
-                && results != null && results.size() > 0) {
-                return new PathSegmentImpl(results.get(0), decoded);
-            } else {
-                return InjectionUtils.createParameterObject(results, 
-                                                        paramType, 
-                                                        genericType,
-                                                        defaultValue,
-                                                        true,
-                                                        decoded);
-            }
+            return InjectionUtils.createParameterObject(results, 
+                                                    paramType, 
+                                                    genericType,
+                                                    defaultValue,
+                                                    true,
+                                                    decoded,
+                                                    true);
         }
     }
     
@@ -577,7 +592,9 @@
         String queryName = queryParam.value();
 
         if ("".equals(queryName)) {
-            return InjectionUtils.handleBean(paramType, new UriInfoImpl(m, null).getQueryParameters());
+            return InjectionUtils.handleBean(paramType, 
+                                             new UriInfoImpl(m, null).getQueryParameters(),
+                                             false);
         } else {
             List<String> results = getStructuredParams((String)m.get(Message.QUERY_STRING),
                                        "&",
@@ -588,6 +605,7 @@
                                                         genericType,
                                                         defaultValue,
                                                         false,
+                                                        false,
                                                         false);
              
         }

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java?rev=723394&r1=723393&r2=723394&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
Thu Dec  4 10:45:24 2008
@@ -19,6 +19,8 @@
 
 package org.apache.cxf.jaxrs;
 
+import java.util.List;
+
 import javax.annotation.Resource;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
@@ -32,6 +34,7 @@
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.SecurityContext;
 import javax.ws.rs.core.UriInfo;
@@ -94,6 +97,9 @@
     public void testPathBean(@PathParam("") CustomerBean cb) {
         
     }
+    public void testMatrixBean(@MatrixParam("") CustomerBean cb) {
+        
+    }
     
     public UriInfo getUriInfo() {
         return uriInfo;
@@ -194,6 +200,12 @@
     }
     
     @ProduceMime("text/xml")   
+    public void testPathSegment(@PathParam("ps") PathSegment ps, 
+                                @PathParam("ps") String path) {
+        // complete
+    }
+    
+    @ProduceMime("text/xml")   
     public void testMultipleQuery(@QueryParam("query")  String queryString, 
                                   @QueryParam("query2") String queryString2,
                                   @QueryParam("query3") Long queryString3,
@@ -203,11 +215,15 @@
     }
     
     @ProduceMime("text/xml")   
-    public void testMatrixParam(@MatrixParam("p1")  String queryString, 
-                                @MatrixParam("p2") String queryString2) {
+    public void testMatrixParam(@MatrixParam("p1") String mp1, 
+                                @MatrixParam("p2") String mp2,
+                                @MatrixParam("p3") String mp3,
+                                @MatrixParam("p4") String mp4,
+                                @MatrixParam("p4") List<String> mp4List) {
         // complete
     }
     
+    
     public void testParams(@Context UriInfo info,
                            @Context HttpHeaders hs,
                            @Context Request r,

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/FormEncodingReaderProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/FormEncodingReaderProviderTest.java?rev=723394&r1=723393&r2=723394&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/FormEncodingReaderProviderTest.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/FormEncodingReaderProviderTest.java
Thu Dec  4 10:45:24 2008
@@ -21,13 +21,16 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
+import java.lang.annotation.Annotation;
 import java.util.List;
 
 import javax.ws.rs.ConsumeMime;
+import javax.ws.rs.Encoded;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MultivaluedMap;
 
 import org.apache.cxf.jaxrs.impl.MetadataMap;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -46,7 +49,7 @@
     public void testReadFrom() throws Exception {
         InputStream is = getClass().getResourceAsStream("singleValPostBody.txt");
         MultivaluedMap<String, String> mvMap = 
-            ferp.readFrom((Class)MultivaluedMap.class, null, null, null, null, is);
+            ferp.readFrom((Class)MultivaluedMap.class, null, new Annotation[]{}, null, null,
is);
         assertEquals("Wrong entry for foo", "bar", mvMap.getFirst("foo"));
         assertEquals("Wrong entry for boo", "far", mvMap.getFirst("boo"));
 
@@ -55,11 +58,11 @@
     @SuppressWarnings("unchecked")
     @Test
     public void testDecoded() throws Exception {
-        ferp.setDecode(true);
         String values = "foo=1+2&bar=1+3";
         
         MultivaluedMap<String, String> mvMap = 
-            ferp.readFrom((Class)MultivaluedMap.class, null, null, null, null, 
+            ferp.readFrom((Class)MultivaluedMap.class, null, 
+                          new Annotation[]{}, null, null, 
                           new ByteArrayInputStream(values.getBytes()));
         assertEquals("Wrong entry for foo", "1 2", mvMap.getFirst("foo"));
         assertEquals("Wrong entry for boo", "1 3", mvMap.getFirst("bar"));
@@ -68,12 +71,25 @@
     
     @SuppressWarnings("unchecked")
     @Test
+    public void testEncoded() throws Exception {
+        String values = "foo=1+2&bar=1+3";
+        
+        MultivaluedMap<String, String> mvMap = 
+            ferp.readFrom((Class)MultivaluedMap.class, null, 
+                          new Annotation[]{CustomMap.class.getAnnotations()[0]}, null, null,

+                          new ByteArrayInputStream(values.getBytes()));
+        assertEquals("Wrong entry for foo", "1+2", mvMap.getFirst("foo"));
+        assertEquals("Wrong entry for boo", "1+3", mvMap.getFirst("bar"));
+
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Test
     public void testCustomMapImpl() throws Exception {
-        ferp.setDecode(true);
         String values = "foo=1+2&bar=1+3&baz=4";
         
         MultivaluedMap<String, String> mvMap = 
-            ferp.readFrom((Class)CustomMap.class, null, null, null, null, 
+            ferp.readFrom((Class)CustomMap.class, null, new Annotation[]{}, null, null, 
                           new ByteArrayInputStream(values.getBytes()));
         assertEquals(3, mvMap.size());
         assertEquals(1,  mvMap.get("foo").size());
@@ -88,19 +104,19 @@
     @SuppressWarnings("unchecked")
     @Test
     public void testMultiLines() throws Exception {
-        ferp.setDecode(true);
         String values = "foo=1+2&bar=line1%0D%0Aline+2&baz=4";
         
         MultivaluedMap<String, String> mvMap = 
-            ferp.readFrom((Class)CustomMap.class, null, null, null, null, 
+            ferp.readFrom((Class)CustomMap.class, null, 
+                          new Annotation[]{}, null, null, 
                           new ByteArrayInputStream(values.getBytes()));
         assertEquals(3, mvMap.size());
         assertEquals(1,  mvMap.get("foo").size());
-        assertEquals(2,  mvMap.get("bar").size());
+        assertEquals(1,  mvMap.get("bar").size());
         assertEquals(1,  mvMap.get("baz").size());
         assertEquals("Wrong entry for foo", "1 2", mvMap.getFirst("foo"));
-        assertEquals("Wrong first line for boo", "line1", mvMap.get("bar").get(0));
-        assertEquals("Wrong first line for boo", "line 2", mvMap.get("bar").get(1));
+        assertEquals("Wrong entry line for bar", 
+            JAXRSUtils.uriDecode("line1%0D%0Aline+2"), mvMap.get("bar").get(0));
         assertEquals("Wrong entry for baz", "4", mvMap.getFirst("baz"));
 
     }
@@ -112,7 +128,7 @@
         String values = "foo=1+2&bar=1+3";
         
         try {
-            ferp.readFrom((Class)CustomMap.class, null, null, null, null, 
+            ferp.readFrom((Class)CustomMap.class, null, new Annotation[]{}, null, null, 
                 new ByteArrayInputStream(values.getBytes()));
             fail();
         } catch (WebApplicationException ex) {
@@ -128,7 +144,7 @@
         InputStream is = getClass().getResourceAsStream("multiValPostBody.txt");
         
         MultivaluedMap<String, String> mvMap = 
-            ferp.readFrom((Class)MultivaluedMap.class, null, null, null, null, is);
+            ferp.readFrom((Class)MultivaluedMap.class, null, new Annotation[]{}, null, null,
is);
         List<String> vals = mvMap.get("foo");
 
         assertEquals("Wrong size for foo params", 2, vals.size());
@@ -150,6 +166,7 @@
                      .value()[0]);
     }
 
+    @Encoded
     public static class CustomMap extends MetadataMap<String, String> {
         
     }

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=723394&r1=723393&r2=723394&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Thu Dec  4 10:45:24 2008
@@ -500,6 +500,24 @@
     }
     
     @Test
+    public void testMatrixParametersBean() throws Exception {
+        Class[] argType = {Customer.CustomerBean.class};
+        Method m = Customer.class.getMethod("testMatrixBean", argType);
+        MessageImpl messageImpl = new MessageImpl();
+        messageImpl.put(Message.REQUEST_URI, "/bar;a=aValue/baz;b=123");
+        List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
null),
+                                                           new MetadataMap<String, String>(),

+                                                           messageImpl);
+        assertEquals("Bean should be created", 1, params.size());
+        Customer.CustomerBean cb = (Customer.CustomerBean)params.get(0);
+        assertNotNull(cb);
+        
+        assertEquals("aValue", cb.getA());
+        assertEquals(new Long(123), cb.getB());
+    }
+    
+    
+    @Test
     public void testMultipleQueryParameters() throws Exception {
         Class[] argType = {String.class, String.class, Long.class, 
                            Boolean.TYPE, String.class};
@@ -522,23 +540,55 @@
                      "", params.get(4));
     }
     
+    @SuppressWarnings("unchecked")
     @Test
     public void testMatrixParameters() throws Exception {
-        Class[] argType = {String.class, String.class};
+        Class[] argType = {String.class, String.class, String.class, String.class, List.class};
         Method m = Customer.class.getMethod("testMatrixParam", argType);
         MessageImpl messageImpl = new MessageImpl();
         
-        messageImpl.put(Message.REQUEST_URI, "/foo/bar;p1=1;p2");
+        messageImpl.put(Message.REQUEST_URI, "/foo;p4=0;p3=3/bar;p1=1;p2/baz;p4=4;p4=5");
         List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
null), 
                                                            null, messageImpl);
-        assertEquals("2 Matrix params should've been identified", 2, params.size());
+        assertEquals("5 Matrix params should've been identified", 5, params.size());
         
-        assertEquals("First Matrix Parameter of multiple was not matched correctly", 
+        assertEquals("First Matrix Parameter not matched correctly", 
                      "1", params.get(0));
-        assertEquals("Second Matrix Parameter of multiple was not matched correctly", 
+        assertEquals("Second Matrix Parameter was not matched correctly", 
                      "", params.get(1));
+        assertEquals("Third Matrix Parameter was not matched correctly", 
+                     "3", params.get(2));
+        assertEquals("Fourth Matrix Parameter was not matched correctly", 
+                     "0", params.get(3));
+        List<String> list = (List<String>)params.get(4);
+        assertEquals(3, list.size());
+        assertEquals("0", list.get(0));
+        assertEquals("4", list.get(1));
+        assertEquals("5", list.get(2));
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testMatrixAndPathSegmentParameters() throws Exception {
+        Class[] argType = {PathSegment.class, String.class};
+        Method m = Customer.class.getMethod("testPathSegment", argType);
+        MessageImpl messageImpl = new MessageImpl();
+        messageImpl.put(Message.REQUEST_URI, "/bar%20foo;p4=0%201");
+        MultivaluedMap<String, String> values = new MetadataMap<String, String>();
+        values.add("ps", "bar%20foo;p4=0%201");
+        List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
null), 
+                                                           values, 
+                                                           messageImpl);
+        assertEquals("2 params should've been identified", 2, params.size());
+        
+        PathSegment ps = (PathSegment)params.get(0);
+        assertEquals("bar foo", ps.getPath());
+        assertEquals(1, ps.getMatrixParameters().size());
+        assertEquals("0 1", ps.getMatrixParameters().getFirst("p4"));
+        assertEquals("bar foo", params.get(1));
     }
     
+    
     @Test
     public void testSelectResourceMethod() throws Exception {
         ClassResourceInfo cri = new ClassResourceInfo(Customer.class);



Mime
View raw message