cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1366740 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml
Date Sat, 28 Jul 2012 18:57:05 GMT
Author: sergeyb
Date: Sat Jul 28 18:57:05 2012
New Revision: 1366740

URL: http://svn.apache.org/viewvc?rev=1366740&view=rev
Log:
[CXF-4445] Making a comma a default char for splitting multiple parameters, supporting 'space'
for backward comp

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java?rev=1366740&r1=1366739&r2=1366740&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
Sat Jul 28 18:57:05 2012
@@ -37,6 +37,7 @@ import javax.ws.rs.ext.RuntimeDelegate;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.PrimitiveUtils;
+import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
@@ -81,15 +82,22 @@ public class CXFNonSpringJaxrsServlet ex
     private static final String SERVICE_SCOPE_SINGLETON = "singleton";
     private static final String SERVICE_SCOPE_REQUEST = "prototype";
     
+    private static final String PARAMETER_SPLIT_CHAR = "class.parameter.split.char";
+    private static final String DEFAULT_PARAMETER_SPLIT_CHAR = ",";
+    private static final String SPACE_PARAMETER_SPLIT_CHAR = "space";
+    
     private static final String JAXRS_APPLICATION_PARAM = "javax.ws.rs.Application";
     
     
     @Override
     public void init(ServletConfig servletConfig) throws ServletException {
         super.init(servletConfig);
+        
+        String splitChar = getParameterSplitChar(servletConfig);
+                
         String applicationClass = servletConfig.getInitParameter(JAXRS_APPLICATION_PARAM);
         if (applicationClass != null) {
-            createServerFromApplication(applicationClass, servletConfig);
+            createServerFromApplication(applicationClass, servletConfig, splitChar);
             return;
         }
         
@@ -110,15 +118,15 @@ public class CXFNonSpringJaxrsServlet ex
         }
         setDocLocation(bean, servletConfig);
         setSchemasLocations(bean, servletConfig);
-        setAllInterceptors(bean, servletConfig);
+        setAllInterceptors(bean, servletConfig, splitChar);
         setInvoker(bean, servletConfig);
         
         Map<Class<?>, Map<String, String>> resourceClasses = 
-            getServiceClasses(servletConfig, modelRef != null);
+            getServiceClasses(servletConfig, modelRef != null, splitChar);
         Map<Class<?>, ResourceProvider> resourceProviders = 
             getResourceProviders(servletConfig, resourceClasses);
         
-        List<?> providers = getProviders(servletConfig);
+        List<?> providers = getProviders(servletConfig, splitChar);
                 
         bean.setResourceClasses(new ArrayList<Class<?>>(resourceClasses.keySet()));
         bean.setProviders(providers);
@@ -130,6 +138,14 @@ public class CXFNonSpringJaxrsServlet ex
         bean.create();
     }
 
+    protected String getParameterSplitChar(ServletConfig servletConfig) {
+        String param = servletConfig.getInitParameter(PARAMETER_SPLIT_CHAR);
+        if (!StringUtils.isEmpty(param) && SPACE_PARAMETER_SPLIT_CHAR.equals(param.trim()))
{
+            return " ";
+        } else {
+            return DEFAULT_PARAMETER_SPLIT_CHAR;
+        }
+    }
     protected boolean getStaticSubResolutionValue(ServletConfig servletConfig) {
         String param = servletConfig.getInitParameter(STATIC_SUB_RESOLUTION_PARAM);
         if (param != null) {
@@ -149,11 +165,12 @@ public class CXFNonSpringJaxrsServlet ex
                 String.class, Object.class));
     }
     
-    protected void setAllInterceptors(JAXRSServerFactoryBean bean, ServletConfig servletConfig)

+    protected void setAllInterceptors(JAXRSServerFactoryBean bean, ServletConfig servletConfig,

+                                      String splitChar) 
         throws ServletException {
-        setInterceptors(bean, servletConfig, OUT_INTERCEPTORS_PARAM);
-        setInterceptors(bean, servletConfig, OUT_FAULT_INTERCEPTORS_PARAM);
-        setInterceptors(bean, servletConfig, IN_INTERCEPTORS_PARAM);
+        setInterceptors(bean, servletConfig, OUT_INTERCEPTORS_PARAM, splitChar);
+        setInterceptors(bean, servletConfig, OUT_FAULT_INTERCEPTORS_PARAM, splitChar);
+        setInterceptors(bean, servletConfig, IN_INTERCEPTORS_PARAM, splitChar);
     }
     
     protected void setSchemasLocations(JAXRSServerFactoryBean bean, ServletConfig servletConfig)
{
@@ -183,12 +200,13 @@ public class CXFNonSpringJaxrsServlet ex
     
     @SuppressWarnings("unchecked")
     protected void setInterceptors(JAXRSServerFactoryBean bean, ServletConfig servletConfig,
-                                   String paramName) throws ServletException {
+                                   String paramName,
+                                   String splitChar) throws ServletException {
         String value  = servletConfig.getInitParameter(paramName);
         if (value == null) {
             return;
         }
-        String[] values = value.split(" ");
+        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>();
@@ -244,7 +262,8 @@ public class CXFNonSpringJaxrsServlet ex
     }
     
     protected Map<Class<?>, Map<String, String>> getServiceClasses(ServletConfig
servletConfig,
-                                            boolean modelAvailable) throws ServletException
{
+                                            boolean modelAvailable,
+                                            String splitChar) throws ServletException {
         String serviceBeans = servletConfig.getInitParameter(SERVICE_CLASSES_PARAM);
         if (serviceBeans == null) {
             if (modelAvailable) {
@@ -252,7 +271,7 @@ public class CXFNonSpringJaxrsServlet ex
             }
             throw new ServletException("At least one resource class should be specified");
         }
-        String[] classNames = serviceBeans.split(" ");
+        String[] classNames = serviceBeans.split(splitChar);
         Map<Class<?>, Map<String, String>> map = new HashMap<Class<?>,
Map<String, String>>();
         for (String cName : classNames) {
             Map<String, String> props = new HashMap<String, String>();
@@ -268,12 +287,12 @@ public class CXFNonSpringJaxrsServlet ex
         return map;
     }
     
-    protected List<?> getProviders(ServletConfig servletConfig) throws ServletException
{
+    protected List<?> getProviders(ServletConfig servletConfig, String splitChar) throws
ServletException {
         String providersList = servletConfig.getInitParameter(PROVIDERS_PARAM);
         if (providersList == null) {
             return Collections.EMPTY_LIST;
         }
-        String[] classNames = providersList.split(" ");
+        String[] classNames = providersList.split(splitChar);
         List<Object> providers = new ArrayList<Object>();
         for (String cName : classNames) {
             Map<String, String> props = new HashMap<String, String>();
@@ -380,7 +399,8 @@ public class CXFNonSpringJaxrsServlet ex
         
     }
     
-    protected void createServerFromApplication(String cName, ServletConfig servletConfig)

+    protected void createServerFromApplication(String cName, ServletConfig servletConfig,
+                                               String splitChar) 
         throws ServletException {
         Map<String, String> props = new HashMap<String, String>();
         cName = getClassNameAndProperties(cName, props);
@@ -391,7 +411,7 @@ public class CXFNonSpringJaxrsServlet ex
         JAXRSServerFactoryBean bean = ResourceUtils.createApplication(app, 
                                             MessageUtils.isTrue(ignoreParam),
                                             getStaticSubResolutionValue(servletConfig));
-        setAllInterceptors(bean, servletConfig);
+        setAllInterceptors(bean, servletConfig, splitChar);
         setInvoker(bean, servletConfig);
         setExtensions(bean, servletConfig);
         setDocLocation(bean, servletConfig);

Modified: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml?rev=1366740&r1=1366739&r2=1366740&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml (original)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml Sat Jul 28
18:57:05 2012
@@ -40,6 +40,14 @@
 		           org.apache.cxf.systest.jaxrs.BookStore
 		      </param-value>    
 		</init-param>
+		<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.JAXBElementProvider
+		      </param-value>    
+		</init-param>
+		
 		<load-on-startup>1</load-on-startup>
 	</servlet>
     



Mime
View raw message