@Context HttpServletRequest httpServletRequest is injected as null in constructor. Howewer if I do field injection it injected proper context
--
/**
* Copyright (c) 2007, Peace Technology, Inc.
* $Author: Roytman, Alex$
* $Revision: 1$
* $Date: 2/11/2009 11:49:26 PM$
* $NoKeywords$
*/
package com.peacetech.jaxrs.providers;
import com.sun.jersey.core.spi.component.ComponentContext;
import com.sun.jersey.core.spi.component.ComponentScope;
import com.sun.jersey.spi.inject.Injectable;
import com.sun.jersey.spi.inject.InjectableProvider;
import javax.jws.WebParam;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.Provider;
import java.lang.reflect.Type;
@Provider
public class TestInjector implements InjectableProvider<WebParam, Type> {
private final HttpServletRequest httpServletRequestConstructor;
@Context private HttpServletRequest httpServletRequestField;
public TestInjector(@Context HttpServletRequest httpServletRequest) {
this.httpServletRequestConstructor = httpServletRequest;
System.out.println("httpServletRequestConstructor = " + httpServletRequest);
}
@Override public ComponentScope getScope() {
return ComponentScope.PerRequest;
}
@Override public Injectable<Integer> getInjectable(ComponentContext ic, final WebParam i, Type type) {
return new Injectable<Integer>() {
@Override public Integer getValue() {
System.out.println("httpServletRequestField = " + httpServletRequestField);
return 123;
}
};
}
}