cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jordan <>
Subject Configuration and Constructor Context Injection problem when using CXF
Date Wed, 20 Aug 2014 06:13:33 GMT
Hi dear all,

We would like to use JAXRS-2.0 and CXF in our project.

And we would like use some @Context injection in our test.

But I found the Configuration and Singleton Constructor @Context injection
don't work. I also searched cxf and test project, but didn't find any
related test and usage.

I'm not sure do you have any related test or work, and could your please
give some suggestion?

Appreciate it! :)

*1, Configuration injection doesn't work in both Resource and Filter:*

Here is one my test resource:

    private UriInfo uriInfo1;

    private UriInfo uriInfo2;

   private Configuration config1;
    private Configuration config2;

    public void setUriInfo(UriInfo ui) {
        uriInfo1 = ui;

    public void setConfiguration (Configuration co) {
        config1= co;

    @Path("/" + ContextUtil.URIINFONAME1)
    public String listQueryParamNames1() {
    	if(config1 == null || config1.equals(null)){
    		System.out.println("CXF config test: config1 is null");
    	} else{
    		System.out.println("CXF config test: config1 is not null: " +
    	if(config2 == null || config2.equals(null)){
    		System.out.println("CXF config test: config2 is null");
    	} else{
    		System.out.println("CXF config test: config2 is not null: " +
        return ContextUtil.URIINFONAME1 + ": " +

All other @context injection work fine, such as uriinfo, request,
httpheaders and so on...
But only Configuration doesn't work

My test report:
CXF config test: config1 is null
CXF config test: config2 is null

Sometime, I also see this error:
Caused by: java.lang.NullPointerException:
context class has not been injected. Check if ContextProvider supporting
this class is registered

*2, Does @Context work/available in Application class?*

I write some injection in Application like this:

public class DemoApplication extends {

    private UriInfo ui;

    private HttpHeaders hh;

    private Request re;

    private Application ap;

    private ResourceContext rc;

    private Providers pr;

But I cannot use them in anywhere in Application code, all report null. is
this work as design?

And I see the standard, we could use @Context for Constructor.

If we cannot use @Context in Application, how can we new Resource for

Such as, here is my resource Constructor :

    public AbstractRestService(@Context UriInfo ui, @Context HttpHeaders hh,
@Context Request r, @Context Providers p) {
        this.uriInfo3 = ui;
        this.httpheaders3 = hh;
        this.request3 = r;
        this.providers3 = p;

When init, getClasses() works fine because we don't need write Constructor.
But getSingletons() doesn't work, because I need provide @context in

    public Set<Class&lt;?>> getClasses() {
        Set<Class&lt;?>> classes = new HashSet<Class&lt;?>>();
        return classes;

    public Set getSingletons() {
        Set objs = new HashSet();
*        objs.add(new SingletonsRestService(ui, hh, re, pr));*
        objs.add(new SingletonsRestService2(rc));
        objs.add(new ContextRequestFilter1());
        objs.add(new ContextRequestFilter2());
//        objs.add(new ContextRequestFilter3(ui, ap, pr));
        objs.add(new ContextRequestFilter4());
        objs.add(new JordanExceptionMapProvider());
        return objs;

I have tested  by using CXF, they all don't work, and I didn't see any
related test in CXF project.

Could you please help take a look?

Thanks all and have a good day~ :)

View this message in context:
Sent from the cxf-dev mailing list archive at

View raw message