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

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

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 (4 kB) 10/Sep/13 07:23 AM - TangYong


Win 7 Pro 64Bit
GlassFish Server Open Source Edition 4.0 (build 89)

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 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:

public class TestService {
public String greet() { return "Hello World"; }

public class TestInterceptor {
private HttpHeaders headers;

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

@Target({ ElementType.METHOD, ElementType.TYPE })
public @interface Test {

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="" xmlns:xsi=""

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="" xmlns:xsi=""
version="1.1" bean-discovery-mode="all">

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.

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] [] [] [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] [] [] [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] [] [] [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, 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]]


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


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

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

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.