Issue Details (XML | Word | Printable)

Key: GLASSFISH-20794
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Jakub Podlesak
Reporter: replicant77
Votes: 4
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
glassfish

GF4: Non-working injection of JAX-RS resoures into CDI interceptors

Created: 04/Sep/13 10:19 AM   Updated: 04/Apr/14 01:39 PM
Component/s: jax-rs
Affects Version/s: 4.0_b89_RC5
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments: 1. Zip Archive GLASSFISH-20794.zip (4 kB) 10/Sep/13 07:23 AM - TangYong

Environment:

Win 7 Pro 64Bit
GlassFish Server Open Source Edition 4.0 (build 89)
jdk1.7.0_21


Tags: glassfish4 jax-rs jersey interceptor cdi
Participants: Jakub Podlesak, jjsnyder83, obfischer, replicant77, TangYong and tcke83


 Description  « Hide

We are currently evaluating glassfish 4 for migration of our enterprise projects from glassfish 3.1.2.2. We are making heavy use of interceptors for our jax-rs based rest services. In glassfish 3.1.2 injection of jax-rs based resources (e.g. @Context private HttpHeaders headers) into those interceptors worked fine. But with GF4 this doesn't work anymore.
Ways to reproduce:


@RequestScoped
@Path("test")
@Test
public class TestService {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String greet() { return "Hello World"; }
}

@Test
@Interceptor
public class TestInterceptor {
@Context
private HttpHeaders headers;

@AroundInvoke
public Object intercept(InvocationContext ic) throws Exception { System.out.println("httpHeaders: " + headers); return ic.proceed(); }
}

@Inherited
@InterceptorBinding
@Target({ ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface Test {
}

beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
<interceptors>
<class>TestInterceptor</class>
</interceptors>
</beans>

On GF3.1.2 the output is something like:
INFO: httpHeaders: com.sun.jersey.spi.container.ContainerRequest@4e7cb67f

On GF4:
INFO: httpHeaders: null



obfischer added a comment - 05/Sep/13 06:57 AM

Did you try to update to CDI 1.1? I also had CDI related issues when migrating my application to GF 4. It was needed to to update all beans.xml to CDI 1.1. At the end I ended with updating to GF 4.0.1-SNAPSHOT.


replicant77 added a comment - 05/Sep/13 07:38 AM

I followed your advice and updated the beans.xml in the example (see below). But the problem stays the same: HttpHeaders stays null.


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="all">
<interceptors>
<class>TestInterceptor</class>
</interceptors>
</beans>


replicant77 added a comment - 05/Sep/13 08:35 AM - edited

Note: i was still using 4.0_b89_RC5 for the updated beans.xml


TangYong added a comment - 10/Sep/13 07:23 AM - edited

I made an attachment based on the issue's description, and the issue can be re-produced using 4.0.1-b02.

[Steps]
1 mvn install
2 asadmin deploy ...
3 accessing "http://localhost:8080/glassfish-20794/webapi/test/"

You can see the following in server.log,
...
[2013-09-10T16:16:04.140+0900] [glassfish 4.0] [INFO] [] [javax.enterprise.system.tools.deployment.common] [tid: _ThreadID=54 _ThreadName=admin-listener(4)] [timeMillis: 1378797364140] [levelValue: 800] [[
visiting unvisited references]]

[2013-09-10T16:16:04.140+0900] [glassfish 4.0] [INFO] [] [javax.enterprise.system.tools.deployment.common] [tid: _ThreadID=54 _ThreadName=admin-listener(4)] [timeMillis: 1378797364140] [levelValue: 800] [[
visiting unvisited references]]

[2013-09-10T16:16:04.155+0900] [glassfish 4.0] [INFO] [] [javax.enterprise.system.tools.deployment.common] [tid: _ThreadID=54 _ThreadName=admin-listener(4)] [timeMillis: 1378797364155] [levelValue: 800] [[
visiting unvisited references]]

[2013-09-10T16:16:04.718+0900] [glassfish 4.0] [INFO] [] [org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer] [tid: _ThreadID=54 _ThreadName=admin-listener(4)] [timeMillis: 1378797364718] [levelValue: 800] [[
Registering the Jersey servlet application, named javax.ws.rs.core.Application, with the following root resource and provider classes: [class TestService]]]

[2013-09-10T16:16:04.968+0900] [glassfish 4.0] [INFO] [] [org.glassfish.jersey.server.ApplicationHandler] [tid: _ThreadID=54 _ThreadName=admin-listener(4)] [timeMillis: 1378797364968] [levelValue: 800] [[
Initiating Jersey application, version Jersey: 2.2 2013-08-14 08:51:58...]]

[2013-09-10T16:16:05.140+0900] [glassfish 4.0] [INFO] [AS-WEB-GLUE-00172] [javax.enterprise.web] [tid: _ThreadID=54 _ThreadName=admin-listener(4)] [timeMillis: 1378797365140] [levelValue: 800] [[
Loading application [glassfish-20794] at [/glassfish-20794]]]

[2013-09-10T16:16:05.155+0900] [glassfish 4.0] [INFO] [] [javax.enterprise.system.core] [tid: _ThreadID=54 _ThreadName=admin-listener(4)] [timeMillis: 1378797365155] [levelValue: 800] [[
glassfish-20794 was successfully deployed in 1,203 milliseconds.]]

[2013-09-10T16:16:26.749+0900] [glassfish 4.0] [INFO] [] [] [tid: _ThreadID=29 _ThreadName=Thread-7] [timeMillis: 1378797386749] [levelValue: 800] [[
httpHeaders: null]]
...

So,

1) pl. JJ firstly evaluates whether being a bug from CDI?
2) if not, forwarding to jax-rs comp to evaluate deeply.

Thanks
Tang


jjsnyder83 added a comment - 10/Sep/13 02:21 PM

@Context is not an annotation processed by Weld nor the GF CDI integration. I looked at the call stack for when the interceptor is created and it is created by
org.jboss.weld.bean.ManagedBean#create

This create method calls the following code

T instance = getProducer().produce(creationalContext);

to create the interceptor and then

getProducer().inject(instance, creationalContext);

to do the injection. For this the getProducer() returns an instance of

org.glassfish.jersey.gf.cdi.CdiComponentProvider

I would expect this class to handle the injection of non-CDI annotations. I do not have this source code handy so I can't verify.

I think the Jersey folks should take a look and see if they're handling the @Context annotation correctly.


TangYong added a comment - 10/Sep/13 02:53 PM

Thanks JJ's confirmation and forwards to JAX-RS Comp to evaluate deeply.


tcke83 added a comment - 04/Apr/14 01:39 PM

Is there an easy work around to get the context? I have the same issue.