cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1359097 - in /cxf/branches/2.4.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
Date Mon, 09 Jul 2012 12:11:31 GMT
Author: sergeyb
Date: Mon Jul  9 12:11:30 2012
New Revision: 1359097

URL: http://svn.apache.org/viewvc?rev=1359097&view=rev
Log:
Merged revisions 1359090 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.5.x-fixes

................
  r1359090 | sergeyb | 2012-07-09 12:59:30 +0100 (Mon, 09 Jul 2012) | 16 lines
  
  Merged revisions 1359081 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes
  
  ................
    r1359081 | sergeyb | 2012-07-09 12:50:29 +0100 (Mon, 09 Jul 2012) | 9 lines
    
    Merged revisions 1359078 via svnmerge from 
    https://svn.apache.org/repos/asf/cxf/trunk
    
    ........
      r1359078 | sergeyb | 2012-07-09 12:44:36 +0100 (Mon, 09 Jul 2012) | 1 line
      
      CXF-4413,CXF-3949:Getting CXFNonSpringJAXRSServlet to support out fault interceptors
and invokers, as well as load early RuntimeDelegate implementation as suggested by Stephan
Klevenz
    ........
  ................
................

Modified:
    cxf/branches/2.4.x-fixes/   (props changed)
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/branches/2.5.x-fixes:r1359090
  Merged /cxf/trunk:r1359078
  Merged /cxf/branches/2.6.x-fixes:r1359081

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

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java?rev=1359097&r1=1359096&r2=1359097&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
Mon Jul  9 12:11:30 2012
@@ -32,6 +32,7 @@ import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 import javax.ws.rs.core.Application;
+import javax.ws.rs.ext.RuntimeDelegate;
 
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.logging.LogUtils;
@@ -46,10 +47,15 @@ import org.apache.cxf.jaxrs.utils.Inject
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageUtils;
+import org.apache.cxf.service.invoker.Invoker;
 import org.apache.cxf.transport.servlet.CXFNonSpringServlet;
 
 public class CXFNonSpringJaxrsServlet extends CXFNonSpringServlet {
-
+    static { 
+        // Ensure that the correct JAX-RS implementation is loaded 
+        RuntimeDelegate runtimeDelegate = new org.apache.cxf.jaxrs.impl.RuntimeDelegateImpl();

+        RuntimeDelegate.setInstance(runtimeDelegate);
+    }
     private static final Logger LOG = LogUtils.getL7dLogger(CXFNonSpringJaxrsServlet.class);
     
     private static final String USER_MODEL_PARAM = "user.model";
@@ -58,7 +64,9 @@ public class CXFNonSpringJaxrsServlet ex
     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 OUT_FAULT_INTERCEPTORS_PARAM = "jaxrs.outFaultInterceptors";
     private static final String IN_INTERCEPTORS_PARAM = "jaxrs.inInterceptors";
+    private static final String INVOKER_PARAM = "jaxrs.invoker";
     private static final String SERVICE_SCOPE_PARAM = "jaxrs.scope";
     private static final String EXTENSIONS_PARAM = "jaxrs.extensions";
     private static final String LANGUAGES_PARAM = "jaxrs.languages";
@@ -98,6 +106,7 @@ public class CXFNonSpringJaxrsServlet ex
         
         setSchemasLocations(bean, servletConfig);
         setAllInterceptors(bean, servletConfig);
+        setInvoker(bean, servletConfig);
         
         Map<Class, Map<String, String>> resourceClasses = 
             getServiceClasses(servletConfig, modelRef != null);
@@ -150,8 +159,10 @@ public class CXFNonSpringJaxrsServlet ex
         }
     }
     
-    protected void setAllInterceptors(JAXRSServerFactoryBean bean, ServletConfig servletConfig)
{
+    protected void setAllInterceptors(JAXRSServerFactoryBean bean, ServletConfig servletConfig)

+        throws ServletException {
         setInterceptors(bean, servletConfig, OUT_INTERCEPTORS_PARAM);
+        setInterceptors(bean, servletConfig, OUT_FAULT_INTERCEPTORS_PARAM);
         setInterceptors(bean, servletConfig, IN_INTERCEPTORS_PARAM);
     }
     
@@ -175,7 +186,7 @@ public class CXFNonSpringJaxrsServlet ex
     
     @SuppressWarnings("unchecked")
     protected void setInterceptors(JAXRSServerFactoryBean bean, ServletConfig servletConfig,
-                                   String paramName) {
+                                   String paramName) throws ServletException {
         String value  = servletConfig.getInitParameter(paramName);
         if (value == null) {
             return;
@@ -187,32 +198,54 @@ public class CXFNonSpringJaxrsServlet ex
             String theValue = getClassNameAndProperties(interceptorVal, props);
             if (theValue.length() != 0) {
                 try {
-                    Class<?> intClass = ClassLoaderUtils.loadClass(theValue,
-                                                                   CXFNonSpringJaxrsServlet.class);
+                    Class<?> intClass = loadClass(theValue, "Interceptor");
                     Object object = intClass.newInstance();
                     injectProperties(object, props);
                     list.add((Interceptor<? extends Message>)object);
-                } 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());

+                } catch (ServletException ex) {
+                    throw ex;
+                } catch (Exception ex) {
+                    LOG.warning("Interceptor class " + theValue + " can not be created");
+                    throw new ServletException(ex);
                 }
             }
         }
         if (list.size() > 0) {
             if (OUT_INTERCEPTORS_PARAM.equals(paramName)) {
                 bean.setOutInterceptors(list);
+            } else if (OUT_FAULT_INTERCEPTORS_PARAM.equals(paramName)) {
+                bean.setOutFaultInterceptors(list);
             } else {
                 bean.setInInterceptors(list);
             }
         }
     }
     
+    protected void setInvoker(JAXRSServerFactoryBean bean, ServletConfig servletConfig) 
+        throws ServletException {
+        String value  = servletConfig.getInitParameter(INVOKER_PARAM);
+        if (value == null) {
+            return;
+        }
+        Map<String, String> props = new HashMap<String, String>();
+        String theValue = getClassNameAndProperties(value, props);
+        if (theValue.length() != 0) {
+            try {
+                Class<?> intClass = loadClass(theValue, "Invoker");
+                Object object = intClass.newInstance();
+                injectProperties(object, props);
+                bean.setInvoker((Invoker)object);
+            } catch (ServletException ex) {
+                throw ex;
+            } catch (Exception ex) {
+                LOG.warning("Invoker class " + theValue + " can not be created");
+                throw new ServletException(ex);
+            }
+        }
+        
+        
+    }
+    
     protected Map<Class, Map<String, String>> getServiceClasses(ServletConfig
servletConfig,
                                             boolean modelAvailable) throws ServletException
{
         String serviceBeans = servletConfig.getInitParameter(SERVICE_CLASSES_PARAM);
@@ -363,6 +396,7 @@ public class CXFNonSpringJaxrsServlet ex
                                             MessageUtils.isTrue(ignoreParam),
                                             getStaticSubResolutionValue(servletConfig));
         setAllInterceptors(bean, servletConfig);
+        setInvoker(bean, servletConfig);
         setExtensions(bean, servletConfig);
         setSchemasLocations(bean, servletConfig);
         



Mime
View raw message