Return-Path: X-Original-To: apmail-cxf-dev-archive@www.apache.org Delivered-To: apmail-cxf-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BF3D711253 for ; Wed, 20 Aug 2014 12:36:23 +0000 (UTC) Received: (qmail 94436 invoked by uid 500); 20 Aug 2014 12:36:23 -0000 Delivered-To: apmail-cxf-dev-archive@cxf.apache.org Received: (qmail 94370 invoked by uid 500); 20 Aug 2014 12:36:23 -0000 Mailing-List: contact dev-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list dev@cxf.apache.org Delivered-To: moderator for dev@cxf.apache.org Received: (qmail 27353 invoked by uid 99); 20 Aug 2014 06:14:00 -0000 X-ASF-Spam-Status: No, hits=2.9 required=5.0 tests=HK_RANDOM_ENVFROM,HK_RANDOM_FROM,SPF_SOFTFAIL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: softfail (nike.apache.org: transitioning domain of zhangtbj@cn.ibm.com does not designate 216.139.236.26 as permitted sender) Date: Tue, 19 Aug 2014 23:13:33 -0700 (PDT) From: jordan To: dev@cxf.apache.org Message-ID: <1408515213432-5747973.post@n5.nabble.com> Subject: Configuration and Constructor Context Injection problem when using CXF MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org 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; @Context private UriInfo uriInfo2; private Configuration config1; @Context private Configuration config2; @Context public void setUriInfo(UriInfo ui) { uriInfo1 = ui; } @Context public void setConfiguration (Configuration co) { config1= co; } @GET @Path("/" + ContextUtil.URIINFONAME1) @Produces("text/plain") 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: " + config1.toString()); } 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: " + config2.toString()); } return ContextUtil.URIINFONAME1 + ": " + ContextUtil.testUriInfo(uriInfo1); } 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: javax.ws.rs.core.Configuration 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: @ApplicationPath("/context") public class DemoApplication extends javax.ws.rs.core.Application { @Context private UriInfo ui; @Context private HttpHeaders hh; @Context private Request re; @Context private Application ap; @Context private ResourceContext rc; @Context 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 Singleton? 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 Application: @Override public Set> getClasses() { Set> classes = new HashSet>(); classes.add(ClassesRestService.class); classes.add(ClassesRestService2.class); classes.add(ContextRequestFilter1.class); classes.add(ContextRequestFilter2.class); classes.add(ContextRequestFilter3.class); classes.add(ContextRequestFilter4.class); classes.add(JordanExceptionMapProvider.class); return classes; } @Override 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: http://cxf.547215.n5.nabble.com/Configuration-and-Constructor-Context-Injection-problem-when-using-CXF-tp5747973.html Sent from the cxf-dev mailing list archive at Nabble.com.