Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit 33d07ca

Browse files
Max Norrispavelbucek
authored andcommitted
JERSEY-3126: Spring AOP and @context were not being injected.
Change-Id: I9d3c90d2fe313ef82e450b52232b9f63ac26111a
1 parent 601df08 commit 33d07ca

4 files changed

Lines changed: 38 additions & 14 deletions

File tree

ext/spring3/pom.xml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@
131131
<version>${spring3.version}</version>
132132
</dependency>
133133

134+
<dependency>
135+
<groupId>org.springframework</groupId>
136+
<artifactId>spring-aop</artifactId>
137+
<version>${spring3.version}</version>
138+
</dependency>
139+
134140
<dependency>
135141
<groupId>javax.servlet</groupId>
136142
<artifactId>javax.servlet-api</artifactId>
@@ -145,21 +151,12 @@
145151
<scope>test</scope>
146152
</dependency>
147153

148-
<!-- Spring AOP + AspectJ -->
149-
<dependency>
150-
<groupId>org.springframework</groupId>
151-
<artifactId>spring-aop</artifactId>
152-
<version>${spring3.version}</version>
153-
<scope>test</scope>
154-
</dependency>
155-
156154
<dependency>
157155
<groupId>org.aspectj</groupId>
158156
<artifactId>aspectjrt</artifactId>
159157
<version>1.6.11</version>
160158
<scope>test</scope>
161159
</dependency>
162-
163160
<dependency>
164161
<groupId>org.aspectj</groupId>
165162
<artifactId>aspectjweaver</artifactId>

ext/spring3/src/main/java/org/glassfish/jersey/server/spring/SpringComponentProvider.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2013-2015 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2013-2016 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -57,7 +57,7 @@
5757

5858
import org.jvnet.hk2.spring.bridge.api.SpringBridge;
5959
import org.jvnet.hk2.spring.bridge.api.SpringIntoHK2Bridge;
60-
60+
import org.springframework.aop.framework.Advised;
6161
import org.springframework.context.ApplicationContext;
6262
import org.springframework.context.support.ClassPathXmlApplicationContext;
6363
import org.springframework.core.annotation.AnnotationUtils;
@@ -188,7 +188,18 @@ private SpringManagedBeanFactory(ApplicationContext ctx, ServiceLocator locator,
188188
@Override
189189
public Object provide() {
190190
Object bean = ctx.getBean(beanName);
191-
locator.inject(bean);
191+
if (bean instanceof Advised) {
192+
try {
193+
// Unwrap the bean and inject the values inside of it
194+
Object localBean = ((Advised) bean).getTargetSource().getTarget();
195+
locator.inject(localBean);
196+
} catch (Exception e) {
197+
// Ignore and let the injection happen as it normally would.
198+
locator.inject(bean);
199+
}
200+
} else {
201+
locator.inject(bean);
202+
}
192203
return bean;
193204
}
194205

ext/spring3/src/test/java/org/glassfish/jersey/server/spring/aspect4j/Aspect4JTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2014-2016 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -78,4 +78,10 @@ public void methodCallShouldBeIntercepted() {
7878
target("test2").request().get(String.class);
7979
assertEquals(1, applicationContext.getBean(TestAspect.class).getInterceptions());
8080
}
81+
82+
@Test
83+
public void JERSEY_3126() {
84+
final String result = target("JERSEY-3126").request().get(String.class);
85+
assertEquals("test ok", result);
86+
}
8187
}

ext/spring3/src/test/java/org/glassfish/jersey/server/spring/aspect4j/ComponentResource.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2014-2016 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -41,6 +41,8 @@
4141

4242
import javax.ws.rs.GET;
4343
import javax.ws.rs.Path;
44+
import javax.ws.rs.core.Context;
45+
import javax.ws.rs.core.UriInfo;
4446

4547
import org.glassfish.jersey.server.spring.TestComponent1;
4648
import org.springframework.beans.factory.annotation.Autowired;
@@ -52,11 +54,19 @@ public class ComponentResource {
5254

5355
@Autowired
5456
private TestComponent1 testComponent1;
57+
@Context
58+
private UriInfo uriInfo;
5559

5660
@Path("test2")
5761
@GET
5862
public String test2() {
5963
return testComponent1.result();
6064
}
6165

66+
@Path("JERSEY-3126")
67+
@GET
68+
public String JERSEY_3126() {
69+
return uriInfo == null ? "test failed" : "test ok";
70+
}
71+
6272
}

0 commit comments

Comments
 (0)