Cette conversation a été verrouillée en raison de son inactivité. Veuillez créer une nouvelle publication.
Niveau 1
Niveau 2
Se connecter à la communauté
Connectez-vous pour voir tous les badges
Cette conversation a été verrouillée en raison de son inactivité. Veuillez créer une nouvelle publication.
I'm working with handler. I'm trying to use the slingRepository. However, when I added to my class It's not deploying my handler and its not showing any error.
Any idea?
@Component(
metatype = true,
immediate = false
)
@Service
public class MyAuthenticationHandler extends DefaultAuthenticationFeedbackHandler implements AuthenticationHandler {
| @Reference | |
private SlingRepository slingRepository; |
Résolu ! Accéder à la solution.
Vues
Réponses
Nombre de J’aime
Avalers,
As a workaround you can get the service reference for sling repository inside activate method using component context as shown below.
@Service
public class TestAuthHandler extends DefaultAuthenticationFeedbackHandler implements AuthenticationHandler
{
private SlingRepository repo;
protected void activate(ComponentContext context) {
try {
BundleContext bundleContext = FrameworkUtil.getBundle(TestAuthHandler.class).getBundleContext();
ServiceReference factoryRef = bundleContext.getServiceReference(SlingRepository.class.getName());
repo = (SlingRepository) bundleContext.getService(factoryRef);
} catch (Exception e) {
}
}.........
Hope this will work fine for you. Tested on 5.5/6.0.
Note : I also faced the same issue some long time back when i tried to use sling repository reference inside service. Still debugging on that.
Thanks,
Karthi
Vues
Réponses
Nombre de J’aime
Is component activated?
Vues
Réponses
Nombre de J’aime
Avalers,
As a workaround you can get the service reference for sling repository inside activate method using component context as shown below.
@Service
public class TestAuthHandler extends DefaultAuthenticationFeedbackHandler implements AuthenticationHandler
{
private SlingRepository repo;
protected void activate(ComponentContext context) {
try {
BundleContext bundleContext = FrameworkUtil.getBundle(TestAuthHandler.class).getBundleContext();
ServiceReference factoryRef = bundleContext.getServiceReference(SlingRepository.class.getName());
repo = (SlingRepository) bundleContext.getService(factoryRef);
} catch (Exception e) {
}
}.........
Hope this will work fine for you. Tested on 5.5/6.0.
Note : I also faced the same issue some long time back when i tried to use sling repository reference inside service. Still debugging on that.
Thanks,
Karthi
Vues
Réponses
Nombre de J’aime
When I added the slingRepository, the service its not longer activated.
Vues
Réponses
Nombre de J’aime
Thanks for the example. I tried, However, the factoryref is returning null.
ServiceReference factoryRef = bundleContext.getServiceReference(SlingRepository.class.getName());
Vues
Réponses
Nombre de J’aime
Hi,
First of all, never call FrameworkUtil.getBundle() in a component's activate method. You have access to the BundleContext via the ComponenContext. You should actually try to avoid using FrameworkUtil.getBundle() in general as it isn't very performant.
As to the original post, I would suggest looking at the log files and see if there is anything interesting there. It is hard to say what could be causing this for sure; one possibility is that you are embedding the SlingRespository class into your bundle. That would make the service not assignable because the service does not implement the target interface (it implements an interface with the same name but not actually the same interface because they come from different class loaders). Calling getServiceReference() from the activate method may or may not work (although if the service class isn't assignable, it will similarly not work) depending upon the activation order. This is why using DS is preferable to directly accessing the service registry - you don't have to deal with a null result from getServiceReference().
Justin
Vues
Réponses
Nombre de J’aime
justin_at_adobe wrote...
Hi,
First of all, never call FrameworkUtil.getBundle() in a component's activate method. You have access to the BundleContext via the ComponenContext. You should actually try to avoid using FrameworkUtil.getBundle() in general as it isn't very performant.
As to the original post, I would suggest looking at the log files and see if there is anything interesting there. It is hard to say what could be causing this for sure; one possibility is that you are embedding the SlingRespository class into your bundle. That would make the service not assignable because the service does not implement the target interface (it implements an interface with the same name but not actually the same interface because they come from different class loaders). Calling getServiceReference() from the activate method may or may not work (although if the service class isn't assignable, it will similarly not work) depending upon the activation order. This is why using DS is preferable to directly accessing the service registry - you don't have to deal with a null result from getServiceReference().
Justin
I do not have any error in my logs. :S
Vues
Réponses
Nombre de J’aime
avalers wrote...![]()
justin_at_adobe wrote...
Hi,
First of all, never call FrameworkUtil.getBundle() in a component's activate method. You have access to the BundleContext via the ComponenContext. You should actually try to avoid using FrameworkUtil.getBundle() in general as it isn't very performant.
As to the original post, I would suggest looking at the log files and see if there is anything interesting there. It is hard to say what could be causing this for sure; one possibility is that you are embedding the SlingRespository class into your bundle. That would make the service not assignable because the service does not implement the target interface (it implements an interface with the same name but not actually the same interface because they come from different class loaders). Calling getServiceReference() from the activate method may or may not work (although if the service class isn't assignable, it will similarly not work) depending upon the activation order. This is why using DS is preferable to directly accessing the service registry - you don't have to deal with a null result from getServiceReference().
Justin
I do not have any error in my logs. :S
In that case, I'd suggest looking at the classloader issue I mentioned.
Vues
Réponses
Nombre de J’aime
justin_at_adobe wrote...![]()
avalers wrote...![]()
justin_at_adobe wrote...
Hi,
First of all, never call FrameworkUtil.getBundle() in a component's activate method. You have access to the BundleContext via the ComponenContext. You should actually try to avoid using FrameworkUtil.getBundle() in general as it isn't very performant.
As to the original post, I would suggest looking at the log files and see if there is anything interesting there. It is hard to say what could be causing this for sure; one possibility is that you are embedding the SlingRespository class into your bundle. That would make the service not assignable because the service does not implement the target interface (it implements an interface with the same name but not actually the same interface because they come from different class loaders). Calling getServiceReference() from the activate method may or may not work (although if the service class isn't assignable, it will similarly not work) depending upon the activation order. This is why using DS is preferable to directly accessing the service registry - you don't have to deal with a null result from getServiceReference().
Justin
I do not have any error in my logs. :S
In that case, I'd suggest looking at the classloader issue I mentioned.
I couldn't find the problem.
This is my pom:
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.auth.core</artifactId>
<scope>provided</scope>
</dependency>
Vues
Réponses
Nombre de J’aime
avalers wrote...![]()
justin_at_adobe wrote...![]()
avalers wrote...![]()
justin_at_adobe wrote...
Hi,
First of all, never call FrameworkUtil.getBundle() in a component's activate method. You have access to the BundleContext via the ComponenContext. You should actually try to avoid using FrameworkUtil.getBundle() in general as it isn't very performant.
As to the original post, I would suggest looking at the log files and see if there is anything interesting there. It is hard to say what could be causing this for sure; one possibility is that you are embedding the SlingRespository class into your bundle. That would make the service not assignable because the service does not implement the target interface (it implements an interface with the same name but not actually the same interface because they come from different class loaders). Calling getServiceReference() from the activate method may or may not work (although if the service class isn't assignable, it will similarly not work) depending upon the activation order. This is why using DS is preferable to directly accessing the service registry - you don't have to deal with a null result from getServiceReference().
Justin
I do not have any error in my logs. :S
In that case, I'd suggest looking at the classloader issue I mentioned.
I couldn't find the problem.
This is my pom:
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.auth.core</artifactId>
<scope>provided</scope>
</dependency>
Could you give me some directions?
Vues
Réponses
Nombre de J’aime
Perhaps post the whole pom?
Vues
Réponses
Nombre de J’aime
I resolved. 🙂 You were right!
The problem was in the pom file.
Vues
Réponses
Nombre de J’aime
Vues
Likes
Réponses
Vues
Likes
Réponses
Vues
Likes
Réponses
Vues
Likes
Réponses