cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1414828 - in /cxf/branches/2.6.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/ rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ systests...
Date Wed, 28 Nov 2012 17:17:38 GMT
Author: sergeyb
Date: Wed Nov 28 17:17:36 2012
New Revision: 1414828

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

........
  r1414825 | sergeyb | 2012-11-28 17:13:36 +0000 (Wed, 28 Nov 2012) | 1 line
  
  [CXF-4660] Making it posible to set primitive and list properties of providers at the servlet
configuration level
........

Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
    cxf/branches/2.6.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:1414825

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

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java?rev=1414828&r1=1414827&r2=1414828&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
Wed Nov 28 17:17:36 2012
@@ -24,6 +24,7 @@ import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.logging.Logger;
@@ -121,7 +122,7 @@ public class CXFNonSpringJaxrsServlet ex
         setAllInterceptors(bean, servletConfig, splitChar);
         setInvoker(bean, servletConfig);
         
-        Map<Class<?>, Map<String, String>> resourceClasses = 
+        Map<Class<?>, Map<String, List<String>>> resourceClasses
= 
             getServiceClasses(servletConfig, modelRef != null, splitChar);
         Map<Class<?>, ResourceProvider> resourceProviders = 
             getResourceProviders(servletConfig, resourceClasses);
@@ -209,7 +210,7 @@ public class CXFNonSpringJaxrsServlet ex
         String[] values = value.split(splitChar);
         List<Interceptor<? extends Message>> list = new ArrayList<Interceptor<?
extends Message>>();
         for (String interceptorVal : values) {
-            Map<String, String> props = new HashMap<String, String>();
+            Map<String, List<String>> props = new HashMap<String, List<String>>();
             String theValue = getClassNameAndProperties(interceptorVal, props);
             if (theValue.length() != 0) {
                 try {
@@ -242,7 +243,7 @@ public class CXFNonSpringJaxrsServlet ex
         if (value == null) {
             return;
         }
-        Map<String, String> props = new HashMap<String, String>();
+        Map<String, List<String>> props = new HashMap<String, List<String>>();
         String theValue = getClassNameAndProperties(value, props);
         if (theValue.length() != 0) {
             try {
@@ -261,7 +262,7 @@ public class CXFNonSpringJaxrsServlet ex
         
     }
     
-    protected Map<Class<?>, Map<String, String>> getServiceClasses(ServletConfig
servletConfig,
+    protected Map<Class<?>, Map<String, List<String>>> getServiceClasses(ServletConfig
servletConfig,
                                             boolean modelAvailable,
                                             String splitChar) throws ServletException {
         String serviceBeans = servletConfig.getInitParameter(SERVICE_CLASSES_PARAM);
@@ -272,9 +273,10 @@ public class CXFNonSpringJaxrsServlet ex
             throw new ServletException("At least one resource class should be specified");
         }
         String[] classNames = serviceBeans.split(splitChar);
-        Map<Class<?>, Map<String, String>> map = new HashMap<Class<?>,
Map<String, String>>();
+        Map<Class<?>, Map<String, List<String>>> map = 
+            new HashMap<Class<?>, Map<String, List<String>>>();
         for (String cName : classNames) {
-            Map<String, String> props = new HashMap<String, String>();
+            Map<String, List<String>> props = new HashMap<String, List<String>>();
             String theName = getClassNameAndProperties(cName, props);
             if (theName.length() != 0) {
                 Class<?> cls = loadClass(theName);
@@ -295,7 +297,7 @@ public class CXFNonSpringJaxrsServlet ex
         String[] classNames = providersList.split(splitChar);
         List<Object> providers = new ArrayList<Object>();
         for (String cName : classNames) {
-            Map<String, String> props = new HashMap<String, String>();
+            Map<String, List<String>> props = new HashMap<String, List<String>>();
             String theName = getClassNameAndProperties(cName, props);
             if (theName.length() != 0) {
                 Class<?> cls = loadClass(theName);
@@ -305,18 +307,51 @@ public class CXFNonSpringJaxrsServlet ex
         return providers;
     }
     
-    private String getClassNameAndProperties(String cName, Map<String, String> props)
{
+    private String getClassNameAndProperties(String cName, Map<String, List<String>>
props) {
         String theName = cName.trim();
         int ind = theName.indexOf("(");
         if (ind != -1 && theName.endsWith(")")) {
-            props.putAll(parseMapSequence(theName.substring(ind + 1, theName.length() - 1)));
+            props.putAll(parseMapListSequence(theName.substring(ind + 1, theName.length()
- 1)));
             theName = theName.substring(0, ind).trim();
         }
         return theName;
     }
     
+    protected static Map<String, List<String>> parseMapListSequence(String sequence)
{
+        if (sequence != null) {
+            sequence = sequence.trim();
+            Map<String, List<String>> map = new HashMap<String, List<String>>();
+            String[] pairs = sequence.split(" ");
+            for (String pair : pairs) {
+                String thePair = pair.trim();
+                if (thePair.length() == 0) {
+                    continue;
+                }
+                String[] values = thePair.split("=");
+                String key;
+                String value;
+                if (values.length == 2) {
+                    key = values[0].trim();
+                    value = values[1].trim();
+                } else {
+                    key = thePair;
+                    value = "";
+                }
+                List<String> list = map.get(key);
+                if (list == null) {
+                    list = new LinkedList<String>();
+                    map.put(key, list);
+                }
+                list.add(value);
+            }
+            return map;
+        } else {
+            return Collections.emptyMap();
+        }
+    }
+    
     protected Map<Class<?>, ResourceProvider> getResourceProviders(ServletConfig
servletConfig,
-            Map<Class<?>, Map<String, String>> resourceClasses) throws
ServletException {
+            Map<Class<?>, Map<String, List<String>>> resourceClasses)
throws ServletException {
         String scope = servletConfig.getInitParameter(SERVICE_SCOPE_PARAM);
         if (scope != null && !SERVICE_SCOPE_SINGLETON.equals(scope)
             && !SERVICE_SCOPE_REQUEST.equals(scope)) {
@@ -324,7 +359,7 @@ public class CXFNonSpringJaxrsServlet ex
         }
         boolean isPrototype = SERVICE_SCOPE_REQUEST.equals(scope);
         Map<Class<?>, ResourceProvider> map = new HashMap<Class<?>,
ResourceProvider>();
-        for (Map.Entry<Class<?>, Map<String, String>> entry : resourceClasses.entrySet())
{
+        for (Map.Entry<Class<?>, Map<String, List<String>>> entry
: resourceClasses.entrySet()) {
             Class<?> c = entry.getKey();
             map.put(c, isPrototype ? new PerRequestResourceProvider(c)
                                    : new SingletonResourceProvider(
@@ -335,7 +370,7 @@ public class CXFNonSpringJaxrsServlet ex
     }    
     
     
-    protected Object createSingletonInstance(Class<?> cls, Map<String, String>
props, ServletConfig sc) 
+    protected Object createSingletonInstance(Class<?> cls, Map<String, List<String>>
props, ServletConfig sc) 
         throws ServletException {
         Constructor<?> c = ResourceUtils.findResourceConstructor(cls, false);
         if (c == null) {
@@ -370,7 +405,7 @@ public class CXFNonSpringJaxrsServlet ex
         }
     }
     
-    private void injectProperties(Object instance, Map<String, String> props) {
+    private void injectProperties(Object instance, Map<String, List<String>>
props) {
         if (props == null || props.isEmpty()) {
             return;
         }
@@ -379,16 +414,16 @@ public class CXFNonSpringJaxrsServlet ex
         for (Method m : methods) {
             methodsMap.put(m.getName(), m);
         }
-        for (Map.Entry<String, String> entry : props.entrySet()) {
+        for (Map.Entry<String, List<String>> entry : props.entrySet()) {
             Method m = methodsMap.get("set" + Character.toUpperCase(entry.getKey().charAt(0))
                            + entry.getKey().substring(1));
             if (m != null) {
                 Class<?> type = m.getParameterTypes()[0];
-                Object value = entry.getValue();
+                Object value;
                 if (InjectionUtils.isPrimitive(type)) {
-                    value = PrimitiveUtils.read(entry.getValue(), type);
-                } else if (List.class.isAssignableFrom(type)) {
-                    value = Collections.singletonList(value);
+                    value = PrimitiveUtils.read(entry.getValue().get(0), type);
+                } else {
+                    value = entry.getValue();
                 } 
                 InjectionUtils.injectThroughMethod(instance, m, value);
             }
@@ -402,7 +437,7 @@ public class CXFNonSpringJaxrsServlet ex
     protected void createServerFromApplication(String cName, ServletConfig servletConfig,
                                                String splitChar) 
         throws ServletException {
-        Map<String, String> props = new HashMap<String, String>();
+        Map<String, List<String>> props = new HashMap<String, List<String>>();
         cName = getClassNameAndProperties(cName, props);
         Class<?> appClass = loadClass(cName, "Application");
         Application app = (Application)createSingletonInstance(appClass, props, servletConfig);

Modified: cxf/branches/2.6.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java?rev=1414828&r1=1414827&r2=1414828&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
Wed Nov 28 17:17:36 2012
@@ -123,11 +123,15 @@ public abstract class AbstractHTTPServle
             Map<String, String> map = new HashMap<String, String>();
             String[] pairs = sequence.split(" ");
             for (String pair : pairs) {
-                String[] value = pair.split("=");
+                String thePair = pair.trim();
+                if (thePair.length() == 0) {
+                    continue;
+                }
+                String[] value = thePair.split("=");
                 if (value.length == 2) {
                     map.put(value[0].trim(), value[1].trim());
                 } else {
-                    map.put(pair.trim(), "");
+                    map.put(thePair, "");
                 }
             }
             return map;

Modified: cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java?rev=1414828&r1=1414827&r2=1414828&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
(original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
Wed Nov 28 17:17:36 2012
@@ -19,6 +19,7 @@
 package org.apache.cxf.systest.jaxrs;
 
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import javax.servlet.ServletContext;
@@ -68,7 +69,11 @@ public class BookApplication extends App
         defaultName = name;
     }
     
-    public void setDefaultId(long id) {
-        defaultId = id;
+    public void setDefaultId(List<String> ids) {
+        StringBuilder sb = new StringBuilder();
+        for (String id : ids) {
+            sb.append(id);
+        }
+        defaultId = Long.valueOf(sb.toString());
     }
 }

Modified: cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml?rev=1414828&r1=1414827&r2=1414828&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml
(original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml
Wed Nov 28 17:17:36 2012
@@ -43,7 +43,12 @@
 		<init-param>
 		      <param-name>jaxrs.providers</param-name>
 		      <param-value>
-		           org.apache.cxf.jaxrs.provider.json.JSONProvider(dropRootElement=false attributesToElements=true),
+		           org.apache.cxf.jaxrs.provider.json.JSONProvider(
+		             dropRootElement=false 
+		             attributesToElements=true
+		             arrayKeys=a
+		             arrayKeys=b
+		           ),
 		           org.apache.cxf.jaxrs.provider.JAXBElementProvider
 		      </param-value>    
 		</init-param>



Mime
View raw message