java - Unable to nest custom Jersey providers -
jersey throws exception when try reference 1 custom provider another.
this test case
public class nestedproviderstest extends jerseytest { public nestedproviderstest() throws testcontainerexception { super(new lowlevelappdescriptor.builder(new defaultresourceconfig(resource.class, parentprovider.class, childprovider.class)).build()); } @test public void test() { resource().path("/").get(string.class); } @path("/") public static class resource { @context private parent parent; @get public string get() { return "hello"; } } public interface parent {} public interface child {} @provider public static class parentprovider extends perrequesttypeinjectableprovider<context, parent> { @context private child child; public parentprovider() { super(parent.class); } @override public injectable<parent> getinjectable(componentcontext ic, context context) { return new injectable<parent>() { @override public parent getvalue() { return new parent(){}; } }; } } @provider public static class childprovider extends perrequesttypeinjectableprovider<context, child> { public childprovider() { super(child.class); } @override public injectable<child> getinjectable(componentcontext ic, context context) { return new injectable<child>() { @override public child getvalue() { return new child(){}; } }; } } }
gives me exception
apr 05, 2013 7:02:41 pm com.sun.jersey.test.framework.spi.container.grizzly2.grizzlytestcontainerfactory$grizzlytestcontainer <init> info: creating low level grizzly2 container configured @ base uri http://localhost:9998/ apr 05, 2013 7:02:41 pm com.sun.jersey.server.impl.application.webapplicationimpl _initiate info: initiating jersey application, version 'jersey: 1.17.1 02/28/2013 12:47 pm' apr 05, 2013 7:02:43 pm com.sun.jersey.spi.inject.errors processerrormessages severe: following errors , warnings have been detected resource and/or provider classes: severe: missing dependency field: private nestedproviderstest$child nestedproviderstest$parentprovider.child com.sun.jersey.test.framework.spi.container.testcontainerexception: com.sun.jersey.spi.inject.errors$errormessagesexception @ com.sun.jersey.test.framework.spi.container.grizzly2.grizzlytestcontainerfactory$grizzlytestcontainer.<init>(grizzlytestcontainerfactory.java:106) @ com.sun.jersey.test.framework.spi.container.grizzly2.grizzlytestcontainerfactory.create(grizzlytestcontainerfactory.java:77) @ com.sun.jersey.test.framework.jerseytest.getcontainer(jerseytest.java:345) @ com.sun.jersey.test.framework.jerseytest.<init>(jerseytest.java:220) @ nestedproviderstest.<init>(nestedproviderstest.java:22) [snip] caused by: com.sun.jersey.spi.inject.errors$errormessagesexception @ com.sun.jersey.spi.inject.errors.processerrormessages(errors.java:170) @ com.sun.jersey.spi.inject.errors.postprocess(errors.java:136) @ com.sun.jersey.spi.inject.errors.processwitherrors(errors.java:199) @ com.sun.jersey.server.impl.application.webapplicationimpl.initiate(webapplicationimpl.java:770) @ com.sun.jersey.api.container.containerfactory.createcontainer(containerfactory.java:172) @ com.sun.jersey.api.container.containerfactory.createcontainer(containerfactory.java:134) @ com.sun.jersey.test.framework.spi.container.grizzly2.grizzlytestcontainerfactory$grizzlytestcontainer.<init>(grizzlytestcontainerfactory.java:102) ... 29 more
am doing wrong, or behaviour not supported jersey?
more appropriate question should be: is behavior not supported jersey 1.17?
i don't want play guessing game, can tell can done jersey 2.
why not work in 1.17? maybe because child
dependency not available during registration of providers.
jersey 2 uses jsr-330 @inject , , way want use javax.inject.provider.
then use kind of binder register injectables skipping details when use provider don't expect t injected during registration. retrieved later during provider#get
example request scoped filter:
@inject private provider<resourceinfo> resourceinfo;
if these:
@inject resourceinfo resourceinfo
then fail failed you.
if can upgrade 2 think it's worth it.
Comments
Post a Comment