Skip to content

Commit

Permalink
JERSEY-3126: Spring AOP and @context were not being injected.
Browse files Browse the repository at this point in the history
Change-Id: I9d3c90d2fe313ef82e450b52232b9f63ac26111a
  • Loading branch information
Max Norris authored and pavelbucek committed Nov 1, 2016
1 parent 0849bd5 commit 090860b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 15 deletions.
17 changes: 7 additions & 10 deletions ext/spring4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!--
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright (c) 2012-2015 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2012-2016 Oracle and/or its affiliates. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -131,6 +131,12 @@
<version>${spring4.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring4.version}</version>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
Expand All @@ -145,21 +151,12 @@
<scope>test</scope>
</dependency>

<!-- Spring AOP + AspectJ -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring4.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.11</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2013-2015 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013-2016 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -57,7 +57,7 @@

import org.jvnet.hk2.spring.bridge.api.SpringBridge;
import org.jvnet.hk2.spring.bridge.api.SpringIntoHK2Bridge;

import org.springframework.aop.framework.Advised;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.annotation.AnnotationUtils;
Expand Down Expand Up @@ -188,7 +188,18 @@ private SpringManagedBeanFactory(ApplicationContext ctx, ServiceLocator locator,
@Override
public Object provide() {
Object bean = ctx.getBean(beanName);
locator.inject(bean);
if (bean instanceof Advised) {
try {
// Unwrap the bean and inject the values inside of it
Object localBean = ((Advised) bean).getTargetSource().getTarget();
locator.inject(localBean);
} catch (Exception e) {
// Ignore and let the injection happen as it normally would.
locator.inject(bean);
}
} else {
locator.inject(bean);
}
return bean;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2014-2015 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014-2016 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -78,4 +78,10 @@ public void methodCallShouldBeIntercepted() {
target("test2").request().get(String.class);
assertEquals(1, applicationContext.getBean(TestAspect.class).getInterceptions());
}

@Test
public void JERSEY_3126() {
final String result = target("JERSEY-3126").request().get(String.class);
assertEquals("test ok", result);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2014-2015 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014-2016 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -41,6 +41,8 @@

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;

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

@Autowired
private TestComponent1 testComponent1;
@Context
private UriInfo uriInfo;

@Path("test2")
@GET
public String test2() {
return testComponent1.result();
}

@Path("JERSEY-3126")
@GET
public String JERSEY_3126() {
return uriInfo == null ? "test failed" : "test ok";
}

}

0 comments on commit 090860b

Please sign in to comment.