You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2011/03/14 18:35:27 UTC
svn commit: r1081489 - in /cxf/branches/2.3.x-fixes: ./
common/common/src/main/java/org/apache/cxf/common/util/
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/
systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
systests/jaxrs/src/test/res...
Author: sergeyb
Date: Mon Mar 14 17:35:26 2011
New Revision: 1081489
URL: http://svn.apache.org/viewvc?rev=1081489&view=rev
Log:
Merged revisions 1081488 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1081488 | sergeyb | 2011-03-14 17:31:19 +0000 (Mon, 14 Mar 2011) | 1 line
[CXF-3400] Better handling of request-scoped beans
........
Added:
cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/RequestScopeResourceFactory.java
- copied unchanged from r1081488, cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/RequestScopeResourceFactory.java
Modified:
cxf/branches/2.3.x-fixes/ (props changed)
cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/SpringAopClassHelper.java
cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java
cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml
cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/resources/jaxrs_proxy/WEB-INF/web.xml
Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
svn:mergeinfo = /cxf/trunk:1081488
Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/SpringAopClassHelper.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/SpringAopClassHelper.java?rev=1081489&r1=1081488&r2=1081489&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/SpringAopClassHelper.java (original)
+++ cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/SpringAopClassHelper.java Mon Mar 14 17:35:26 2011
@@ -19,8 +19,10 @@
package org.apache.cxf.common.util;
+import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
+import org.springframework.beans.factory.BeanCreationException;
/**
*
@@ -56,12 +58,22 @@ class SpringAopClassHelper extends Class
if (AopUtils.isAopProxy(o)) {
Advised advised = (Advised)o;
try {
- Object target = advised.getTargetSource().getTarget();
+ TargetSource targetSource = advised.getTargetSource();
+
+ Object target = null;
+
+ try {
+ target = targetSource.getTarget();
+ } catch (BeanCreationException ex) {
+ // some scopes such as 'request' may not
+ // be active on the current thread yet
+ return getRealClassFromClassInternal(targetSource.getTargetClass());
+ }
if (target == null) {
Class targetClass = AopUtils.getTargetClass(o);
if (targetClass != null) {
- return targetClass;
+ return getRealClassFromClassInternal(targetClass);
}
} else {
return getRealClassInternal(target);
Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=1081489&r1=1081488&r2=1081489&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java (original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java Mon Mar 14 17:35:26 2011
@@ -120,13 +120,14 @@ public class JAXRSInvoker extends Abstra
pushOntoStack(ori, ClassHelper.getRealClass(resourceObject), exchange.getInMessage());
if (cri.isRoot()) {
- JAXRSUtils.handleSetters(ori, resourceObject,
+ Object realResourceObject = ClassHelper.getRealObject(resourceObject);
+ JAXRSUtils.handleSetters(ori, realResourceObject,
exchange.getInMessage());
- InjectionUtils.injectContextFields(resourceObject,
+ InjectionUtils.injectContextFields(realResourceObject,
ori.getClassResourceInfo(),
exchange.getInMessage());
- InjectionUtils.injectResourceFields(resourceObject,
+ InjectionUtils.injectResourceFields(realResourceObject,
ori.getClassResourceInfo(),
exchange.getInMessage());
}
Modified: cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java?rev=1081489&r1=1081488&r2=1081489&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java (original)
+++ cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java Mon Mar 14 17:35:26 2011
@@ -26,7 +26,9 @@ import java.net.URLConnection;
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.io.CachedOutputStream;
+import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+
import org.junit.BeforeClass;
import org.junit.Test;
@@ -36,7 +38,7 @@ public class JAXRSClientServerProxySprin
@BeforeClass
public static void startServers() throws Exception {
assertTrue("server did not launch correctly",
- launchServer(BookServerProxySpring.class));
+ launchServer(BookServerProxySpring.class, true));
}
@Test
@@ -139,6 +141,17 @@ public class JAXRSClientServerProxySprin
assertEquals(getStringFromInputStream(expected), getStringFromInputStream(in));
}
+ @Test
+ public void testGetBookWithRequestScope() {
+ // the BookStore method which will handle this request depends on the injected HttpHeaders
+ WebClient wc = WebClient.create("http://localhost:" + PORT + "/test/request/bookstore/booksecho2");
+ wc.type("text/plain").accept("text/plain");
+ wc.header("CustomHeader", "custom-header");
+ String value = wc.post("CXF", String.class);
+ assertEquals("CXF", value);
+ assertEquals("custom-header", wc.getResponse().getMetadata().getFirst("CustomHeader"));
+ }
+
private String getStringFromInputStream(InputStream in) throws Exception {
CachedOutputStream bos = new CachedOutputStream();
IOUtils.copy(in, bos);
Modified: cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml?rev=1081489&r1=1081488&r2=1081489&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml (original)
+++ cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml Mon Mar 14 17:35:26 2011
@@ -40,6 +40,8 @@ http://cxf.apache.org/schemas/jaxrs.xsd"
<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
+ <bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"/>
+
<bean id="bookstore" class="org.apache.cxf.systest.jaxrs.BookStore"/>
<bean id="bookstoreInterface" class="org.apache.cxf.systest.jaxrs.BookStoreWithInterface"/>
@@ -95,6 +97,18 @@ http://cxf.apache.org/schemas/jaxrs.xsd"
</jaxrs:server>
+ <jaxrs:server id="requestScopeEndpoint" address="/request">
+ <jaxrs:serviceFactories>
+ <bean class="org.apache.cxf.systest.jaxrs.RequestScopeResourceFactory">
+ <property name="beanId" value="requestScopeBean"/>
+ </bean>
+ </jaxrs:serviceFactories>
+ </jaxrs:server>
+
+ <bean id="requestScopeBean" class="org.apache.cxf.systest.jaxrs.BookStore" scope="request">
+ <aop:scoped-proxy />
+ </bean>
+
<bean id="sfactory1" class="org.apache.cxf.jaxrs.spring.SpringResourceFactory">
<property name="beanId" value="bookstore"/>
</bean>
Modified: cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/resources/jaxrs_proxy/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/resources/jaxrs_proxy/WEB-INF/web.xml?rev=1081489&r1=1081488&r2=1081489&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/resources/jaxrs_proxy/WEB-INF/web.xml (original)
+++ cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/resources/jaxrs_proxy/WEB-INF/web.xml Mon Mar 14 17:35:26 2011
@@ -33,6 +33,11 @@
</listener-class>
</listener>
+ <!-- makes request-scoped beans work -->
+ <listener>
+ <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
+ </listener>
+
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-name>