cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r822312 - /cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
Date Tue, 06 Oct 2009 15:19:11 GMT
Author: sergeyb
Date: Tue Oct  6 15:19:10 2009
New Revision: 822312

URL: http://svn.apache.org/viewvc?rev=822312&view=rev
Log:
JAXRS : minor update to CXFNonSpringJaxrsServlet to support out/in interceptors

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java

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=822312&r1=822311&r2=822312&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
Tue Oct  6 15:19:10 2009
@@ -38,6 +38,7 @@
 
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
 import org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider;
 import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
@@ -53,6 +54,8 @@
     private static final String SERVICE_ADDRESS_PARAM = "jaxrs.address";
     private static final String SERVICE_CLASSES_PARAM = "jaxrs.serviceClasses";
     private static final String PROVIDERS_PARAM = "jaxrs.providers";
+    private static final String OUT_INTERCEPTORS_PARAM = "jaxrs.outInterceptors";
+    private static final String IN_INTERCEPTORS_PARAM = "jaxrs.inInterceptors";
     private static final String SERVICE_SCOPE_PARAM = "jaxrs.scope";
     private static final String SCHEMAS_PARAM = "jaxrs.schemaLocations";
     private static final String SERVICE_SCOPE_SINGLETON = "singleton";
@@ -83,6 +86,8 @@
         }
         
         setSchemasLocations(bean, servletConfig);
+        setInterceptors(bean, servletConfig, OUT_INTERCEPTORS_PARAM);
+        setInterceptors(bean, servletConfig, IN_INTERCEPTORS_PARAM);
         
         List<Class> resourceClasses = getServiceClasses(servletConfig, modelRef !=
null);
         Map<Class, ResourceProvider> resourceProviders = 
@@ -116,6 +121,42 @@
         }
     }
     
+    protected void setInterceptors(JAXRSServerFactoryBean bean, ServletConfig servletConfig,
+                                   String paramName) {
+        String value  = servletConfig.getInitParameter(paramName);
+        if (value == null) {
+            return;
+        }
+        String[] values = value.split(" ");
+        List<Interceptor> list = new ArrayList<Interceptor>();
+        for (String interceptorVal : values) {
+            String theValue = interceptorVal.trim();
+            if (theValue.length() != 0) {
+                try {
+                    Class<?> intClass = ClassLoaderUtils.loadClass(theValue,
+                                                                   CXFNonSpringJaxrsServlet.class);
+                    list.add((Interceptor)intClass.newInstance());
+                } catch (ClassNotFoundException ex) {
+                    LOG.warning("Interceptor class " + theValue + " can not be found");
+                } catch (InstantiationException ex) {
+                    LOG.warning(theValue + " class can not be instantiated");
+                    ex.printStackTrace();
+                } catch (IllegalAccessException ex) {
+                    LOG.warning("CXF Interceptor can not be instantiated due to IllegalAccessException");

+                } catch (ClassCastException ex) {
+                    LOG.warning(theValue + " class does not implement " + Interceptor.class.getName());

+                }
+            }
+        }
+        if (list.size() > 0) {
+            if (OUT_INTERCEPTORS_PARAM.equals(paramName)) {
+                bean.setOutInterceptors(list);
+            } else {
+                bean.setInInterceptors(list);
+            }
+        }
+    }
+    
     protected List<Class> getServiceClasses(ServletConfig servletConfig,
                                             boolean modelAvailable) throws ServletException
{
         String serviceBeans = servletConfig.getInitParameter(SERVICE_CLASSES_PARAM);



Mime
View raw message