Re: Wicket, Guice and the $Proxy object
Here's a post that helped me understand this better: http://stackoverflow.com/questions/16047829/proxy-cannot-be-cast-to-class On Tue, Jul 23, 2013 at 2:15 PM, Daniel Watrous wrote: > Dan, > > Good point. After considering I decided to modify my interface to expose > the function I need and let the implementation worry about casting where > necessary. > > Thanks, > Daniel > > > On Tue, Jul 23, 2013 at 9:58 AM, Dan Retzlaff wrote: > >> @Inject the implementation, not the interface. @Inject'd implementations >> have some code smell, but no more than downcasting. >> >> >> On Tue, Jul 23, 2013 at 8:40 AM, Daniel Watrous > >wrote: >> >> > That being the case, is there any way to get an instance that I can >> cast to >> > a concrete type? >> > >> > >> > On Tue, Jul 23, 2013 at 9:27 AM, Martin Grigorov > > >wrote: >> > >> > > Hi, >> > > >> > > >> > > On Tue, Jul 23, 2013 at 6:20 PM, Daniel Watrous > > > >wrote: >> > > >> > > > Hi, >> > > > >> > > > I'm having an issue that I suspect is related to the wicket >> integration >> > > > with Guice. Any help is appreciated. >> > > > >> > > > I have a Page class that uses field injection to inject a DAO. I >> then >> > > want >> > > > to cast my DAO to a more specific type (what I inject is the >> > interface). >> > > > Here's what that looks like >> > > > >> > > > public class CnavModify extends ConsoleBasePage { >> > > > >> > > > @Inject private CnavUrlDAO cnavUrlDAO; >> > > > public CnavModify(PageParameters parameters) { >> > > > super(parameters); >> > > > if (parameters.get("cnavid").toString() != null) { >> > > > cnavid = new >> ObjectId(parameters.get("cnavid").toString()); >> > > > } >> > > > if (cnavid != null) { >> > > > cnavUrlModel = new >> > > > >> > > > >> > > >> > >> DetachableCnavUrlModel(((MorphiaCnavUrlDAO)cnavUrlDAO).getCnavById(cnavid)); >> > > > } >> > > > } >> > > > } >> > > > >> > > > When I try to cast it I get the following error: >> > > > >> > > > Last cause: $Proxy23 cannot be cast to >> > > > com.hp.honeybadger.persistence.dao.morphia.MorphiaCnavUrlDAO >> > > > >> > > > I am able to use the CnavUrlDAO as a CnavUrlDAO, but its type is >> > $Proxy23 >> > > > and I am unable to cast it to a concrete type. >> > > > >> > > > Is this Guice or Wicket related? Any idea how to get around this? >> > > > >> > > >> > > It is an error in your assumption. >> > > >> > > Wicket injects a proxy that implements CnavUrlDAO but knows nothing >> about >> > > the specific implementation about this interface. >> > > Whenever the proxy is used it delegates the call to the bean/service >> > > returned by Guice's injector (something like: >> > > Injector.getBinding(CnavUrlDAO.class).doSomething()). >> > > >> > > >> > > > >> > > > Thanks, >> > > > Daniel >> > > > >> > > >> > >> > >
Re: Wicket, Guice and the $Proxy object
Dan, Good point. After considering I decided to modify my interface to expose the function I need and let the implementation worry about casting where necessary. Thanks, Daniel On Tue, Jul 23, 2013 at 9:58 AM, Dan Retzlaff wrote: > @Inject the implementation, not the interface. @Inject'd implementations > have some code smell, but no more than downcasting. > > > On Tue, Jul 23, 2013 at 8:40 AM, Daniel Watrous >wrote: > > > That being the case, is there any way to get an instance that I can cast > to > > a concrete type? > > > > > > On Tue, Jul 23, 2013 at 9:27 AM, Martin Grigorov > >wrote: > > > > > Hi, > > > > > > > > > On Tue, Jul 23, 2013 at 6:20 PM, Daniel Watrous > > >wrote: > > > > > > > Hi, > > > > > > > > I'm having an issue that I suspect is related to the wicket > integration > > > > with Guice. Any help is appreciated. > > > > > > > > I have a Page class that uses field injection to inject a DAO. I then > > > want > > > > to cast my DAO to a more specific type (what I inject is the > > interface). > > > > Here's what that looks like > > > > > > > > public class CnavModify extends ConsoleBasePage { > > > > > > > > @Inject private CnavUrlDAO cnavUrlDAO; > > > > public CnavModify(PageParameters parameters) { > > > > super(parameters); > > > > if (parameters.get("cnavid").toString() != null) { > > > > cnavid = new > ObjectId(parameters.get("cnavid").toString()); > > > > } > > > > if (cnavid != null) { > > > > cnavUrlModel = new > > > > > > > > > > > > > > DetachableCnavUrlModel(((MorphiaCnavUrlDAO)cnavUrlDAO).getCnavById(cnavid)); > > > > } > > > > } > > > > } > > > > > > > > When I try to cast it I get the following error: > > > > > > > > Last cause: $Proxy23 cannot be cast to > > > > com.hp.honeybadger.persistence.dao.morphia.MorphiaCnavUrlDAO > > > > > > > > I am able to use the CnavUrlDAO as a CnavUrlDAO, but its type is > > $Proxy23 > > > > and I am unable to cast it to a concrete type. > > > > > > > > Is this Guice or Wicket related? Any idea how to get around this? > > > > > > > > > > It is an error in your assumption. > > > > > > Wicket injects a proxy that implements CnavUrlDAO but knows nothing > about > > > the specific implementation about this interface. > > > Whenever the proxy is used it delegates the call to the bean/service > > > returned by Guice's injector (something like: > > > Injector.getBinding(CnavUrlDAO.class).doSomething()). > > > > > > > > > > > > > > Thanks, > > > > Daniel > > > > > > > > > >
Re: Wicket, Guice and the $Proxy object
@Inject the implementation, not the interface. @Inject'd implementations have some code smell, but no more than downcasting. On Tue, Jul 23, 2013 at 8:40 AM, Daniel Watrous wrote: > That being the case, is there any way to get an instance that I can cast to > a concrete type? > > > On Tue, Jul 23, 2013 at 9:27 AM, Martin Grigorov >wrote: > > > Hi, > > > > > > On Tue, Jul 23, 2013 at 6:20 PM, Daniel Watrous > >wrote: > > > > > Hi, > > > > > > I'm having an issue that I suspect is related to the wicket integration > > > with Guice. Any help is appreciated. > > > > > > I have a Page class that uses field injection to inject a DAO. I then > > want > > > to cast my DAO to a more specific type (what I inject is the > interface). > > > Here's what that looks like > > > > > > public class CnavModify extends ConsoleBasePage { > > > > > > @Inject private CnavUrlDAO cnavUrlDAO; > > > public CnavModify(PageParameters parameters) { > > > super(parameters); > > > if (parameters.get("cnavid").toString() != null) { > > > cnavid = new ObjectId(parameters.get("cnavid").toString()); > > > } > > > if (cnavid != null) { > > > cnavUrlModel = new > > > > > > > > > DetachableCnavUrlModel(((MorphiaCnavUrlDAO)cnavUrlDAO).getCnavById(cnavid)); > > > } > > > } > > > } > > > > > > When I try to cast it I get the following error: > > > > > > Last cause: $Proxy23 cannot be cast to > > > com.hp.honeybadger.persistence.dao.morphia.MorphiaCnavUrlDAO > > > > > > I am able to use the CnavUrlDAO as a CnavUrlDAO, but its type is > $Proxy23 > > > and I am unable to cast it to a concrete type. > > > > > > Is this Guice or Wicket related? Any idea how to get around this? > > > > > > > It is an error in your assumption. > > > > Wicket injects a proxy that implements CnavUrlDAO but knows nothing about > > the specific implementation about this interface. > > Whenever the proxy is used it delegates the call to the bean/service > > returned by Guice's injector (something like: > > Injector.getBinding(CnavUrlDAO.class).doSomething()). > > > > > > > > > > Thanks, > > > Daniel > > > > > >
Re: Wicket, Guice and the $Proxy object
That being the case, is there any way to get an instance that I can cast to a concrete type? On Tue, Jul 23, 2013 at 9:27 AM, Martin Grigorov wrote: > Hi, > > > On Tue, Jul 23, 2013 at 6:20 PM, Daniel Watrous >wrote: > > > Hi, > > > > I'm having an issue that I suspect is related to the wicket integration > > with Guice. Any help is appreciated. > > > > I have a Page class that uses field injection to inject a DAO. I then > want > > to cast my DAO to a more specific type (what I inject is the interface). > > Here's what that looks like > > > > public class CnavModify extends ConsoleBasePage { > > > > @Inject private CnavUrlDAO cnavUrlDAO; > > public CnavModify(PageParameters parameters) { > > super(parameters); > > if (parameters.get("cnavid").toString() != null) { > > cnavid = new ObjectId(parameters.get("cnavid").toString()); > > } > > if (cnavid != null) { > > cnavUrlModel = new > > > > > DetachableCnavUrlModel(((MorphiaCnavUrlDAO)cnavUrlDAO).getCnavById(cnavid)); > > } > > } > > } > > > > When I try to cast it I get the following error: > > > > Last cause: $Proxy23 cannot be cast to > > com.hp.honeybadger.persistence.dao.morphia.MorphiaCnavUrlDAO > > > > I am able to use the CnavUrlDAO as a CnavUrlDAO, but its type is $Proxy23 > > and I am unable to cast it to a concrete type. > > > > Is this Guice or Wicket related? Any idea how to get around this? > > > > It is an error in your assumption. > > Wicket injects a proxy that implements CnavUrlDAO but knows nothing about > the specific implementation about this interface. > Whenever the proxy is used it delegates the call to the bean/service > returned by Guice's injector (something like: > Injector.getBinding(CnavUrlDAO.class).doSomething()). > > > > > > Thanks, > > Daniel > > >
Re: Wicket, Guice and the $Proxy object
Hi, On Tue, Jul 23, 2013 at 6:20 PM, Daniel Watrous wrote: > Hi, > > I'm having an issue that I suspect is related to the wicket integration > with Guice. Any help is appreciated. > > I have a Page class that uses field injection to inject a DAO. I then want > to cast my DAO to a more specific type (what I inject is the interface). > Here's what that looks like > > public class CnavModify extends ConsoleBasePage { > > @Inject private CnavUrlDAO cnavUrlDAO; > public CnavModify(PageParameters parameters) { > super(parameters); > if (parameters.get("cnavid").toString() != null) { > cnavid = new ObjectId(parameters.get("cnavid").toString()); > } > if (cnavid != null) { > cnavUrlModel = new > > DetachableCnavUrlModel(((MorphiaCnavUrlDAO)cnavUrlDAO).getCnavById(cnavid)); > } > } > } > > When I try to cast it I get the following error: > > Last cause: $Proxy23 cannot be cast to > com.hp.honeybadger.persistence.dao.morphia.MorphiaCnavUrlDAO > > I am able to use the CnavUrlDAO as a CnavUrlDAO, but its type is $Proxy23 > and I am unable to cast it to a concrete type. > > Is this Guice or Wicket related? Any idea how to get around this? > It is an error in your assumption. Wicket injects a proxy that implements CnavUrlDAO but knows nothing about the specific implementation about this interface. Whenever the proxy is used it delegates the call to the bean/service returned by Guice's injector (something like: Injector.getBinding(CnavUrlDAO.class).doSomething()). > > Thanks, > Daniel >
Re: Wicket, Guice and the $Proxy object
Here's a little more detail when I debug and attempt to do just the cast: Cannot cast an instance of "class $Proxy23 (loaded by instance of org.eclipse.jetty.webapp.WebAppClassLoader(id=3511))" to an instance of "class com.hp.honeybadger.persistence.dao.morphia.MorphiaCnavUrlDAO (loaded by instance of sun.misc.Launcher$AppClassLoader(id=2450))" On Tue, Jul 23, 2013 at 9:20 AM, Daniel Watrous wrote: > Hi, > > I'm having an issue that I suspect is related to the wicket integration > with Guice. Any help is appreciated. > > I have a Page class that uses field injection to inject a DAO. I then want > to cast my DAO to a more specific type (what I inject is the interface). > Here's what that looks like > > public class CnavModify extends ConsoleBasePage { > > @Inject private CnavUrlDAO cnavUrlDAO; > public CnavModify(PageParameters parameters) { > super(parameters); > if (parameters.get("cnavid").toString() != null) { > cnavid = new ObjectId(parameters.get("cnavid").toString()); > } > if (cnavid != null) { > cnavUrlModel = new > DetachableCnavUrlModel(((MorphiaCnavUrlDAO)cnavUrlDAO).getCnavById(cnavid)); > } > } > } > > When I try to cast it I get the following error: > > Last cause: $Proxy23 cannot be cast to > com.hp.honeybadger.persistence.dao.morphia.MorphiaCnavUrlDAO > > I am able to use the CnavUrlDAO as a CnavUrlDAO, but its type is $Proxy23 > and I am unable to cast it to a concrete type. > > Is this Guice or Wicket related? Any idea how to get around this? > > Thanks, > Daniel >