You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by "Robert A. Decker" <de...@robdecker.com> on 2012/06/26 00:34:42 UTC

How to debug adapterfactory?

Hi,

I've written an AdapterFactory that appears to be set up correctly. It shows up in my services and has adaptables and adapters. And when I look under the System Console 'Sling Adapters' tab it shows up as well with the proper values under the Adaptable Class column and under the AdapterClass column.

However, when I adaptTo on a Resource instance to one of my classes I get null.

Out of curiosity I tried adapting the Resource instance to a Node instance and adapting that. However, I get compile time error that I'm unable to resolve the method adaptTo with my class type.

I don't get this compile error with Resource or ResourceResolver, but perhaps that's being resolved by something like the AdapterManager… I'm really not sure.

But one thing I'm pretty sure is that no code is ever called in my AdapterFactory. I'm not sure when the getAdapter method is called normally but when I put a breakpoint in the method during a bundle install or when I try to do the apaption my breakpoint is never hit…

Any ideas? Am I missing a step?

Rob

Re: How to debug adapterfactory?

Posted by Justin Edelson <ju...@justinedelson.com>.
Created https://issues.apache.org/jira/browse/SLING-2522 for this.

On Tue, Jun 26, 2012 at 8:16 AM, Felix Meschberger <fm...@adobe.com>wrote:

> Hi,
>
> Am 26.06.2012 um 13:17 schrieb Robert A. Decker:
>
> > Thanks for the help. I figured it out.
> >
> > It as because I declared my adapter factory service like:
> >
> > @Component(metatype = false, immediate = true, label = "Brainsciences
> Facebook Adapter Factory")
> > @Service(FacebookAdapterFactory.class)
> > public class FacebookAdapterFactory implements AdapterFactory {
> >
> >
> > When I changed it to:
> >
> > @Component(metatype = false, immediate = true, label = "Brainsciences
> Facebook Adapter Factory")
> > @Service
> > public class FacebookAdapterFactory implements AdapterFactory {
> >
> > It works fine.
> >
> > It was confusing because when declared the first way above it still
> shows up in the Sling Adapters. But when you look at the services its type
> shows up as:
> > [org.brainsciences.bmn.facebook.services.FacebookAdapterFactory]
>
> Right. Maybe the Sling Adapters plugin should only list the actual
> AdapterFactory services ?
>
> Regards
> Felix
>
> >
> > And then when I change it to the second declaration above, it still
> shows up in the Sling Adapters, and now its type is:
> > [org.apache.sling.api.adapter.AdapterFactory]
> >
> > And now it works.
> >
> > Rob
> >
> > On Jun 26, 2012, at 9:47 AM, Felix Meschberger wrote:
> >
> >> Hi
> >>
> >> Am 26.06.2012 um 00:34 schrieb Robert A. Decker:
> >>
> >>> Hi,
> >>>
> >>> I've written an AdapterFactory that appears to be set up correctly. It
> shows up in my services and has adaptables and adapters. And when I look
> under the System Console 'Sling Adapters' tab it shows up as well with the
> proper values under the Adaptable Class column and under the AdapterClass
> column.
> >>>
> >>> However, when I adaptTo on a Resource instance to one of my classes I
> get null.
> >>>
> >>> Out of curiosity I tried adapting the Resource instance to a Node
> instance and adapting that. However, I get compile time error that I'm
> unable to resolve the method adaptTo with my class type.
> >>>
> >>> I don't get this compile error with Resource or ResourceResolver, but
> perhaps that's being resolved by something like the AdapterManager… I'm
> really not sure.
> >>>
> >>> But one thing I'm pretty sure is that no code is ever called in my
> AdapterFactory. I'm not sure when the getAdapter method is called normally
> but when I put a breakpoint in the method during a bundle install or when I
> try to do the apaption my breakpoint is never hit…
> >>>
> >>> Any ideas? Am I missing a step?
> >>
> >> Are you sure to not have confused adapter and adaptable in your
> AdapterFactory ? Your own class would be an adapter and Sling's Resource
> would be adaptable.
> >>
> >> Regards
> >> Felix
> >>
> >>
> >
>
>

Re: How to debug adapterfactory?

Posted by Felix Meschberger <fm...@adobe.com>.
Hi,

Am 26.06.2012 um 13:17 schrieb Robert A. Decker:

> Thanks for the help. I figured it out. 
> 
> It as because I declared my adapter factory service like:
> 
> @Component(metatype = false, immediate = true, label = "Brainsciences Facebook Adapter Factory")
> @Service(FacebookAdapterFactory.class)
> public class FacebookAdapterFactory implements AdapterFactory {
> 
> 
> When I changed it to:
> 
> @Component(metatype = false, immediate = true, label = "Brainsciences Facebook Adapter Factory")
> @Service
> public class FacebookAdapterFactory implements AdapterFactory {
> 
> It works fine.
> 
> It was confusing because when declared the first way above it still shows up in the Sling Adapters. But when you look at the services its type shows up as:
> [org.brainsciences.bmn.facebook.services.FacebookAdapterFactory]

Right. Maybe the Sling Adapters plugin should only list the actual AdapterFactory services ?

Regards
Felix

> 
> And then when I change it to the second declaration above, it still shows up in the Sling Adapters, and now its type is:
> [org.apache.sling.api.adapter.AdapterFactory]
> 
> And now it works.
> 
> Rob
> 
> On Jun 26, 2012, at 9:47 AM, Felix Meschberger wrote:
> 
>> Hi
>> 
>> Am 26.06.2012 um 00:34 schrieb Robert A. Decker:
>> 
>>> Hi,
>>> 
>>> I've written an AdapterFactory that appears to be set up correctly. It shows up in my services and has adaptables and adapters. And when I look under the System Console 'Sling Adapters' tab it shows up as well with the proper values under the Adaptable Class column and under the AdapterClass column.
>>> 
>>> However, when I adaptTo on a Resource instance to one of my classes I get null.
>>> 
>>> Out of curiosity I tried adapting the Resource instance to a Node instance and adapting that. However, I get compile time error that I'm unable to resolve the method adaptTo with my class type.
>>> 
>>> I don't get this compile error with Resource or ResourceResolver, but perhaps that's being resolved by something like the AdapterManager… I'm really not sure.
>>> 
>>> But one thing I'm pretty sure is that no code is ever called in my AdapterFactory. I'm not sure when the getAdapter method is called normally but when I put a breakpoint in the method during a bundle install or when I try to do the apaption my breakpoint is never hit…
>>> 
>>> Any ideas? Am I missing a step?
>> 
>> Are you sure to not have confused adapter and adaptable in your AdapterFactory ? Your own class would be an adapter and Sling's Resource would be adaptable.
>> 
>> Regards
>> Felix
>> 
>> 
> 


Re: How to debug adapterfactory?

Posted by "Robert A. Decker" <de...@robdecker.com>.
Thanks for the help. I figured it out. 

It as because I declared my adapter factory service like:

@Component(metatype = false, immediate = true, label = "Brainsciences Facebook Adapter Factory")
@Service(FacebookAdapterFactory.class)
public class FacebookAdapterFactory implements AdapterFactory {


When I changed it to:

@Component(metatype = false, immediate = true, label = "Brainsciences Facebook Adapter Factory")
@Service
public class FacebookAdapterFactory implements AdapterFactory {

It works fine.

It was confusing because when declared the first way above it still shows up in the Sling Adapters. But when you look at the services its type shows up as:
[org.brainsciences.bmn.facebook.services.FacebookAdapterFactory]

And then when I change it to the second declaration above, it still shows up in the Sling Adapters, and now its type is:
[org.apache.sling.api.adapter.AdapterFactory]

And now it works.

Rob

On Jun 26, 2012, at 9:47 AM, Felix Meschberger wrote:

> Hi
> 
> Am 26.06.2012 um 00:34 schrieb Robert A. Decker:
> 
>> Hi,
>> 
>> I've written an AdapterFactory that appears to be set up correctly. It shows up in my services and has adaptables and adapters. And when I look under the System Console 'Sling Adapters' tab it shows up as well with the proper values under the Adaptable Class column and under the AdapterClass column.
>> 
>> However, when I adaptTo on a Resource instance to one of my classes I get null.
>> 
>> Out of curiosity I tried adapting the Resource instance to a Node instance and adapting that. However, I get compile time error that I'm unable to resolve the method adaptTo with my class type.
>> 
>> I don't get this compile error with Resource or ResourceResolver, but perhaps that's being resolved by something like the AdapterManager… I'm really not sure.
>> 
>> But one thing I'm pretty sure is that no code is ever called in my AdapterFactory. I'm not sure when the getAdapter method is called normally but when I put a breakpoint in the method during a bundle install or when I try to do the apaption my breakpoint is never hit…
>> 
>> Any ideas? Am I missing a step?
> 
> Are you sure to not have confused adapter and adaptable in your AdapterFactory ? Your own class would be an adapter and Sling's Resource would be adaptable.
> 
> Regards
> Felix
> 
> 


Re: How to debug adapterfactory?

Posted by Felix Meschberger <fm...@adobe.com>.
Hi

Am 26.06.2012 um 00:34 schrieb Robert A. Decker:

> Hi,
> 
> I've written an AdapterFactory that appears to be set up correctly. It shows up in my services and has adaptables and adapters. And when I look under the System Console 'Sling Adapters' tab it shows up as well with the proper values under the Adaptable Class column and under the AdapterClass column.
> 
> However, when I adaptTo on a Resource instance to one of my classes I get null.
> 
> Out of curiosity I tried adapting the Resource instance to a Node instance and adapting that. However, I get compile time error that I'm unable to resolve the method adaptTo with my class type.
> 
> I don't get this compile error with Resource or ResourceResolver, but perhaps that's being resolved by something like the AdapterManager… I'm really not sure.
> 
> But one thing I'm pretty sure is that no code is ever called in my AdapterFactory. I'm not sure when the getAdapter method is called normally but when I put a breakpoint in the method during a bundle install or when I try to do the apaption my breakpoint is never hit…
> 
> Any ideas? Am I missing a step?

Are you sure to not have confused adapter and adaptable in your AdapterFactory ? Your own class would be an adapter and Sling's Resource would be adaptable.

Regards
Felix


Re: How to debug adapterfactory?

Posted by "Robert A. Decker" <de...@robdecker.com>.
I've since implemented Adaptable in my api and extended SlingAdaptable in my implementation of my class but I'm still not able to adaptTo from Resource to my class.

Rob

On Jun 26, 2012, at 12:34 AM, Robert A. Decker wrote:

> Hi,
> 
> I've written an AdapterFactory that appears to be set up correctly. It shows up in my services and has adaptables and adapters. And when I look under the System Console 'Sling Adapters' tab it shows up as well with the proper values under the Adaptable Class column and under the AdapterClass column.
> 
> However, when I adaptTo on a Resource instance to one of my classes I get null.
> 
> Out of curiosity I tried adapting the Resource instance to a Node instance and adapting that. However, I get compile time error that I'm unable to resolve the method adaptTo with my class type.
> 
> I don't get this compile error with Resource or ResourceResolver, but perhaps that's being resolved by something like the AdapterManager… I'm really not sure.
> 
> But one thing I'm pretty sure is that no code is ever called in my AdapterFactory. I'm not sure when the getAdapter method is called normally but when I put a breakpoint in the method during a bundle install or when I try to do the apaption my breakpoint is never hit…
> 
> Any ideas? Am I missing a step?
> 
> Rob


RE: How to debug adapterfactory?

Posted by Robert Munteanu <rm...@adobe.com>.
Hi Robert,

> -----Original Message-----
> From: Robert A. Decker [mailto:decker@robdecker.com]
> Sent: Tuesday, June 26, 2012 1:35 AM
> To: users@sling.apache.org
> Subject: How to debug adapterfactory?
> 
> Hi,
> 
> I've written an AdapterFactory that appears to be set up correctly. It
> shows up in my services and has adaptables and adapters. And when I
> look under the System Console 'Sling Adapters' tab it shows up as well
> with the proper values under the Adaptable Class column and under the
> AdapterClass column.
> 
> However, when I adaptTo on a Resource instance to one of my classes I
> get null.
> 
> Out of curiosity I tried adapting the Resource instance to a Node
> instance and adapting that. However, I get compile time error that I'm
> unable to resolve the method adaptTo with my class type.

That's expected , Nodes are not adaptable.

> 
> I don't get this compile error with Resource or ResourceResolver, but
> perhaps that's being resolved by something like the AdapterManager… I'm
> really not sure.
> 
> But one thing I'm pretty sure is that no code is ever called in my
> AdapterFactory. I'm not sure when the getAdapter method is called
> normally but when I put a breakpoint in the method during a bundle
> install or when I try to do the apaption my breakpoint is never hit…
> 
> Any ideas? Am I missing a step?

Can you show us the code?

Robert

> 
> Rob