cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1518712 - in /cxf/branches/2.7.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ systests/jaxrs/src/te...
Date Thu, 29 Aug 2013 17:09:57 GMT
Author: sergeyb
Date: Thu Aug 29 17:09:56 2013
New Revision: 1518712

URL: http://svn.apache.org/r1518712
Log:
Merged revisions 1518703,1518708 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1518703 | sergeyb | 2013-08-29 17:49:10 +0100 (Thu, 29 Aug 2013) | 1 line
  
  [CXF-5245] Improving the way SpringResourceFactory deals with lifecycle methods
........
  r1518708 | sergeyb | 2013-08-29 18:00:10 +0100 (Thu, 29 Aug 2013) | 1 line
  
  [CXF-5245] Minor updates
........

Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/SpringResourceFactory.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
    cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreStorage.java
    cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface.java
    cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface2.java
    cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/LifecycleInterface.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1518703-1518708

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

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=1518712&r1=1518711&r2=1518712&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
Thu Aug 29 17:09:56 2013
@@ -115,8 +115,9 @@ public class JAXRSInvoker extends Abstra
                 }
             } else {
                 exchange.put(REQUEST_WAS_SUSPENDED, true);
+            } else {
+                persistRoots(exchange, rootInstance, provider);
             }
-            persistRoots(exchange, rootInstance, provider);
         }
     }
 

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/SpringResourceFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/SpringResourceFactory.java?rev=1518712&r1=1518711&r2=1518712&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/SpringResourceFactory.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/SpringResourceFactory.java
Thu Aug 29 17:09:56 2013
@@ -43,7 +43,11 @@ public class SpringResourceFactory imple
     private Method postConstructMethod;
     private Method preDestroyMethod;
     private boolean isSingleton;
-    private boolean callLifecycleMethods = true;
+    private boolean isPrototype;
+    private boolean callPostConstruct;
+    private boolean callPreDestroy = true;
+    private String postConstructMethodName;
+    private String preDestroyMethodName;
     
     public SpringResourceFactory() {
         
@@ -63,9 +67,12 @@ public class SpringResourceFactory imple
             throw new RuntimeException("Resource class " + type
                                        + " has no valid constructor");
         }
-        postConstructMethod = ResourceUtils.findPostConstructMethod(type);
-        preDestroyMethod = ResourceUtils.findPreDestroyMethod(type);
+        postConstructMethod = ResourceUtils.findPostConstructMethod(type, postConstructMethodName);
+        preDestroyMethod = ResourceUtils.findPreDestroyMethod(type, preDestroyMethodName);
         isSingleton = ac.isSingleton(beanId);
+        if (!isSingleton) {
+            isPrototype = ac.isPrototype(beanId);
+        }
     }
     
     /**
@@ -79,8 +86,8 @@ public class SpringResourceFactory imple
     }
 
     protected void initInstance(Message m, Object instance) {
-        if (callLifecycleMethods && (!isSingleton() || m == null)) {
-            InjectionUtils.invokeLifeCycleMethod(instance, postConstructMethod);
+        if (isCallPostConstruct()) {
+            InjectionUtils.invokeLifeCycleMethod(ClassHelper.getRealObject(instance), postConstructMethod);
         }
     }
 
@@ -97,10 +104,14 @@ public class SpringResourceFactory imple
      * {@inheritDoc}
      */
     public void releaseInstance(Message m, Object o) {
-        if (callLifecycleMethods && !isSingleton()) {
+        if (doCallPreDestroy()) {
             InjectionUtils.invokeLifeCycleMethod(o, preDestroyMethod);
         }
     }
+    
+    protected boolean doCallPreDestroy() {
+        return isCallPreDestroy() && isPrototype;
+    }
 
     public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
{
         ac = applicationContext;
@@ -126,7 +137,27 @@ public class SpringResourceFactory imple
         return c.getDeclaringClass();
     }
 
-    public void setCallLifecycleMethods(boolean callLifecycleMethods) {
-        this.callLifecycleMethods = callLifecycleMethods;
+    public void setCallPostConstruct(boolean callPostConstruct) {
+        this.callPostConstruct = callPostConstruct;
+    }
+    
+    public boolean isCallPostConstruct() {
+        return this.callPostConstruct;
+    }
+
+    public void setCallPreDestroy(boolean callPreDestroy) {
+        this.callPreDestroy = callPreDestroy;
+    }
+
+    public boolean isCallPreDestroy() {
+        return this.callPreDestroy;
+    }
+    
+    public void setPreDestroyMethodName(String preDestroyMethodName) {
+        this.preDestroyMethodName = preDestroyMethodName;
+    }
+
+    public void setPostConstructMethodName(String postConstructMethodName) {
+        this.postConstructMethodName = postConstructMethodName;
     }
 }

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java?rev=1518712&r1=1518711&r2=1518712&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
Thu Aug 29 17:09:56 2013
@@ -117,22 +117,28 @@ public final class ResourceUtils {
     private ResourceUtils() {
         
     }
-    
     public static Method findPostConstructMethod(Class<?> c) {
+        return findPostConstructMethod(c, null);
+    }
+    public static Method findPostConstructMethod(Class<?> c, String name) {
         if (Object.class == c || null == c) {
             return null;
         }
         for (Method m : c.getDeclaredMethods()) {
-            if (m.getAnnotation(PostConstruct.class) != null) {
+            if (name != null) {
+                if (m.getName().equals(name)) {
+                    return m;
+                }
+            } else if (m.getAnnotation(PostConstruct.class) != null) {
                 return m;
             }
         }
-        Method m = findPostConstructMethod(c.getSuperclass());
+        Method m = findPostConstructMethod(c.getSuperclass(), name);
         if (m != null) {
             return m;
         }
         for (Class<?> i : c.getInterfaces()) {
-            m = findPostConstructMethod(i);
+            m = findPostConstructMethod(i, name);
             if (m != null) {
                 return m;
             }
@@ -141,20 +147,28 @@ public final class ResourceUtils {
     }
     
     public static Method findPreDestroyMethod(Class<?> c) {
+        return findPreDestroyMethod(c, null);
+    }
+    
+    public static Method findPreDestroyMethod(Class<?> c, String name) {
         if (Object.class == c || null == c) {
             return null;
         }
         for (Method m : c.getDeclaredMethods()) {
-            if (m.getAnnotation(PreDestroy.class) != null) {
+            if (name != null) {
+                if (m.getName().equals(name)) {
+                    return m;
+                }
+            } else if (m.getAnnotation(PreDestroy.class) != null) {
                 return m;
             }
         }
-        Method m = findPreDestroyMethod(c.getSuperclass());
+        Method m = findPreDestroyMethod(c.getSuperclass(), name);
         if (m != null) {
             return m;
         }
         for (Class<?> i : c.getInterfaces()) {
-            m = findPreDestroyMethod(i);
+            m = findPreDestroyMethod(i, name);
             if (m != null) {
                 return m;
             }

Modified: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreStorage.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreStorage.java?rev=1518712&r1=1518711&r2=1518712&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreStorage.java
(original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreStorage.java
Thu Aug 29 17:09:56 2013
@@ -22,10 +22,25 @@ package org.apache.cxf.systest.jaxrs;
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
 import javax.ws.rs.Path;
 
 @Path("/bookstorestorage/")
-public abstract class BookStoreStorage {
+public abstract class BookStoreStorage implements LifecycleInterface {
     protected Map<Long, Book> books = new HashMap<Long, Book>();
     protected long bookId = 123;
+    protected boolean postConstructCalled;
+    
+    @PostConstruct
+    public void postConstruct() {
+        if (postConstructCalled) {
+            throw new RuntimeException();
+        }
+        postConstructCalled = true;
+    }
+    @PreDestroy
+    public void preDestroy() {
+        // System.out.println("PreDestroy called");
+    }
 }

Modified: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface.java?rev=1518712&r1=1518711&r2=1518712&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface.java
(original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface.java
Thu Aug 29 17:09:56 2013
@@ -42,11 +42,8 @@ package org.apache.cxf.systest.jaxrs;
 
 
 
-public class BookStoreWithInterface extends BookStoreStorage 
-    implements BookInterface, LifecycleInterface {
+public class BookStoreWithInterface extends BookStoreStorage implements BookInterface {
 
-    private boolean postConstructCalled;
-    
     public BookStoreWithInterface() {
         Book book = new Book();
         book.setId(bookId);
@@ -54,14 +51,6 @@ public class BookStoreWithInterface exte
         books.put(book.getId(), book);
     }
     
-    public void postConstruct() {
-        postConstructCalled = true;
-    }
-    
-    public void preDestroy() {
-        //System.out.println("PreDestroy called");
-    }
-    
     public Book getThatBook(Long id, String s) throws BookNotFoundFault {
         if (!postConstructCalled) {
             throw new RuntimeException();

Modified: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface2.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface2.java?rev=1518712&r1=1518711&r2=1518712&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface2.java
(original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface2.java
Thu Aug 29 17:09:56 2013
@@ -38,6 +38,7 @@
 
 package org.apache.cxf.systest.jaxrs;
 
+import javax.annotation.PreDestroy;
 import javax.servlet.ServletContext;
 import javax.ws.rs.core.Context;
 
@@ -58,6 +59,11 @@ public class BookStoreWithInterface2 ext
         this.servletContext = scontext;
     }
     
+    @PreDestroy
+    public void preDestroy() {
+        System.out.println("PreDestroy called");
+    }
+    
     public Book getThatBook(Long id, String s) throws BookNotFoundFault {
         if (servletContext == null) {
             throw new RuntimeException();

Modified: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/LifecycleInterface.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/LifecycleInterface.java?rev=1518712&r1=1518711&r2=1518712&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/LifecycleInterface.java
(original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/LifecycleInterface.java
Thu Aug 29 17:09:56 2013
@@ -18,12 +18,8 @@
  */
 package org.apache.cxf.systest.jaxrs;
 
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
 
 public interface LifecycleInterface {
-    @PostConstruct
     void postConstruct();
-    @PreDestroy
     void preDestroy();
 }



Mime
View raw message