You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2007/10/08 21:00:51 UTC
svn commit: r582939 - in /incubator/cxf/branches/2.0.x-fixes: ./
common/common/src/main/java/org/apache/cxf/common/annotation/
common/common/src/main/java/org/apache/cxf/common/injection/
common/common/src/test/java/org/apache/cxf/common/injection/ rt/...
Author: dkulp
Date: Mon Oct 8 12:00:50 2007
New Revision: 582939
URL: http://svn.apache.org/viewvc?rev=582939&view=rev
Log:
Merged revisions 581781 via svnmerge from
https://svn.apache.org/repos/asf/incubator/cxf/trunk
........
r581781 | ningjiang | 2007-10-04 01:42:29 -0400 (Thu, 04 Oct 2007) | 1 line
CXF-1074 using the spring's AOPUtils.getTargetClass() as the resource injector target class.
........
Modified:
incubator/cxf/branches/2.0.x-fixes/ (props changed)
incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/annotation/AnnotationProcessor.java
incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java
incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/common/injection/ResourceInjectorTest.java
incubator/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/pom.xml
incubator/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java
Propchange: incubator/cxf/branches/2.0.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/annotation/AnnotationProcessor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/annotation/AnnotationProcessor.java?rev=582939&r1=582938&r2=582939&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/annotation/AnnotationProcessor.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/annotation/AnnotationProcessor.java Mon Oct 8 12:00:50 2007
@@ -74,9 +74,9 @@
* Visits each of the annotated elements of the object.
*
* @param visitor a visitor
- *
+ * @param claz the Class of the targe object
*/
- public void accept(AnnotationVisitor visitor) {
+ public void accept(AnnotationVisitor visitor, Class<?> claz) {
if (visitor == null) {
throw new IllegalArgumentException();
@@ -85,10 +85,14 @@
annotationTypes = visitor.getTargetAnnotations();
visitor.setTarget(target);
//recursively check annotation in super class
- processClass(visitor, target.getClass());
- processFields(visitor, target.getClass());
- processMethods(visitor, target.getClass());
+ processClass(visitor, claz);
+ processFields(visitor, claz);
+ processMethods(visitor, claz);
}
+
+ public void accept(AnnotationVisitor visitor) {
+ accept(visitor, target.getClass());
+ }
private void processMethods(AnnotationVisitor visitor, Class<? extends Object> targetClass) {
Modified: incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java?rev=582939&r1=582938&r2=582939&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java Mon Oct 8 12:00:50 2007
@@ -52,6 +52,7 @@
private static final List<Class<? extends Annotation>> ANNOTATIONS =
new ArrayList<Class<? extends Annotation>>();
+
static {
ANNOTATIONS.add(Resource.class);
ANNOTATIONS.add(Resources.class);
@@ -71,11 +72,13 @@
}
- public void inject(Object o) {
-
+ public void inject(Object o) {
+ inject(o, o.getClass());
+ }
+
+ public void inject(Object o, Class claz) {
AnnotationProcessor processor = new AnnotationProcessor(o);
- processor.accept(this);
-
+ processor.accept(this, claz);
invokePostConstruct();
}
@@ -377,4 +380,5 @@
private Object resolveResource(String resourceName, Class<?> type) {
return resourceManager.resolveResource(resourceName, type, resourceResolvers);
}
+
}
Modified: incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/common/injection/ResourceInjectorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/common/injection/ResourceInjectorTest.java?rev=582939&r1=582938&r2=582939&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/common/injection/ResourceInjectorTest.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/common/injection/ResourceInjectorTest.java Mon Oct 8 12:00:50 2007
@@ -19,7 +19,8 @@
package org.apache.cxf.common.injection;
-
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
@@ -29,6 +30,10 @@
import javax.annotation.Resource;
import javax.annotation.Resources;
+import net.sf.cglib.proxy.Enhancer;
+import net.sf.cglib.proxy.MethodInterceptor;
+import net.sf.cglib.proxy.MethodProxy;
+
import org.apache.cxf.resource.ResourceManager;
import org.apache.cxf.resource.ResourceResolver;
@@ -64,6 +69,7 @@
doInjectTest(new FieldTarget());
}
+
@Test
public void testFieldInSuperClassInjection() {
setUpResourceManager("org.apache.cxf.common.injection.FieldTarget/");
@@ -81,6 +87,12 @@
setUpResourceManager(SetterTarget.class.getCanonicalName() + "/");
doInjectTest(new SetterTarget());
}
+
+ @Test
+ public void testProxyInjection() {
+ setUpResourceManager(FieldTarget.class.getCanonicalName() + "/");
+ doInjectTest(getProxyObject());
+ }
@Test
public void testClassLevelInjection() {
@@ -111,15 +123,23 @@
assertTrue(target.preDestroyCalled());
}
- protected void doInjectTest(Target target) {
-
- injector.inject(target);
+ protected void doInjectTest(Target target) {
+ injector.inject(target);
assertNotNull(target.getResource1());
assertEquals(RESOURCE_ONE, target.getResource1());
assertNotNull(target.getResource2());
- assertEquals(RESOURCE_TWO, target.getResource2());
+ assertEquals(RESOURCE_TWO, target.getResource2());
+
+ }
+
+
+ private FieldTarget getProxyObject() {
+ Enhancer e = new Enhancer();
+ e.setSuperclass(FieldTarget.class);
+ e.setCallback(new CallInterceptor());
+ return (FieldTarget)e.create();
}
}
@@ -130,6 +150,17 @@
String getResource2();
}
+class CallInterceptor implements MethodInterceptor {
+
+ public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
+ Object retValFromSuper = null;
+ if (!Modifier.isAbstract(method.getModifiers())) {
+ retValFromSuper = proxy.invokeSuper(obj, args);
+ }
+ return retValFromSuper;
+ }
+}
+
class FieldTarget implements Target {
@@ -228,7 +259,8 @@
@Resource(name = "resource1")
class ClassTarget implements Target {
- @Resource(name = "resource2") public String resource2foo;
+ @Resource(name = "resource2")
+ public String resource2foo;
private String res1;
public final void setResource1(String res) {
Modified: incubator/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/pom.xml?rev=582939&r1=582938&r2=582939&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/pom.xml (original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/pom.xml Mon Oct 8 12:00:50 2007
@@ -107,6 +107,11 @@
</dependency>
<dependency>
<groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>test</scope>
<version>${spring.version}</version>
Modified: incubator/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java?rev=582939&r1=582938&r2=582939&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java Mon Oct 8 12:00:50 2007
@@ -45,6 +45,8 @@
import org.apache.cxf.service.invoker.Invoker;
import org.apache.cxf.service.model.BindingInfo;
+import org.springframework.aop.support.AopUtils;
+
/**
* Bean to help easily create Server endpoints for JAX-WS. Example:
* <pre>
@@ -196,7 +198,7 @@
resourceManager = new DefaultResourceManager(resolvers);
resourceManager.addResourceResolver(new WebServiceContextResourceResolver());
ResourceInjector injector = new ResourceInjector(resourceManager);
- injector.inject(instance);
+ injector.inject(instance, AopUtils.getTargetClass(instance));
}
}
}