Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Crowd 2.1+ Annotation Based Event Listeners - does anyone have one working? the example is clear but seems to fail

Brendan Patterson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 8, 2011

Creating an AnnotationBasedEventListner for Crowd seems to be really well documented here:

http://confluence.atlassian.com/display/CROWDDEV/Event+Listeners

but after a couple of hours I simply cannot get Crowd to see the listener.

I've actually copied the code verbatim for the atlassian-plugin.xml file and the basic UserCreatedListener class example verbatim aside from changing the package name.

Here are the two files - really simple. Any guidance tips or especially working code with Crowd 2.2.7+ would be hugely appreciated!

What would be most useful would be a working code snippet.

Here is the error:

 2011-06-09 10:16:25,200 main INFO [atlassian.plugin.loaders.ScanningPluginLoader] Plugin Unit: /Users/brendan/Desktop/java/crowd-home-2.2.7/plugins/AddUserToLdapPlugin-1.0.jar (1307636154000) created
2011-06-09 10:16:25,204 main INFO [atlassian.plugin.manager.DefaultPluginManager] Updating plugin 'crowd.listeners.core:1.0' to 'crowd.listeners.core:1.0'
2011-06-09 10:16:25,211 main ERROR [atlassian.event.internal.EventPublisherImpl] There was an exception thrown trying to dispatch event 'com.atlassian.config.lifecycle.events.ApplicationStartedEvent@54856d00' from the invoker 'com.atlassian.event.internal.SingleParameterMethodListenerInvoker@27cc75cb'.
java.lang.RuntimeException: Error initialising plugin manager: Duplicate plugin found (installed version is the same or older) and could not be unloaded: 'crowd.listeners.core'
        at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:54)
 

The code:

 
package com.xyz.crowd.plugins;
import com.atlassian.crowd.event.user.UserCreatedEvent;
public class UserCreatedListener
{
    @com.atlassian.event.api.EventListener
    public void printUserCreatedEvent(UserCreatedEvent event)
    {
        System.out.println("User " + event.getUser().getDisplayName() + " has been created.");
    }
}
-------------
 
 <atlassian-plugin name="Example Listeners" key="crowd.listeners.core" system="false">
    <plugin-info>
        <description>This contains example listeners</description>
        <vendor name="Atlassian Software Systems" url="http://www.atlassian.com"/>
        <version>1.0</version>
    </plugin-info>
    <listener name="User Created Listener" key="usercreatedlistener" class="com.xyz.crowd.plugins.UserCreatedListener">
        <description>Will listen for user creation events.</description>
    </listener>
</atlassian-plugin>

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Olli Nevalainen
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 15, 2011

The example atlassian-plugin.xml in http://confluence.atlassian.com/display/CROWDDEV/Event+Listeners had atlassian-plugin key attribute set to "crowd.listeners.core" which is used by Crowd, and seems to have caused the duplicate plugin error that you encountered. I fixed the page, and your listener should start working after you change the atlassian-plugin key attribute in atlassian-plugin.xml to something unique like "example.listeners".

Brendan Patterson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 15, 2011
Additionally the Crowd plugin you get from using the Atlassian-SDK: atlas-create-crowd-plugin Does not seem to work.
Brendan Patterson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 15, 2011
Hi Olli, Thanks very much for looking at this and good catch. You were right about that duplicate error however this was after several other iterations where I was using unique keys. I'm reasonably confident the annotation based EventListeners simply don't work in Crowd 2.2.7 as shown in the example. A working example would convince me otherwise :) This is the error I get: " No listener invokers were found for listener " https://img.skitch.com/20110616-fan22nnpu9hgpupqsk2hw1si6g.jpg thanks!
Olli Nevalainen
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 16, 2011
Hi Brendan, Thank you for letting us know that http://confluence.atlassian.com/display/CROWDDEV/Event+Listeners page needed some care. I have now updated it to better reflect what current Atlassian Plugins SDK would produce. I also attached a minimal example project to that page that hopefully will work for you. Remember that version 2 plugins need to be installed to $CROWD_HOME/plugins directory and the System.out.println statement will only be visible in $CROWD/apache-tomcat/logs/catalina.out file.
Brendan Patterson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 16, 2011
Thanks for the working example code! That DID work. I'll let you know if I figure out what I did wrong. A few lines of working code are worth ten pages of documentation to me :) A great enhancement to documentation would be links to working code - it doesn't have to be attached but could be in BitBucket or wherever. Easily fixed by anyone and would be obvious if it worked or didn't. Simple unit tests where possible would be optimal as we'd automatically know when documentation had become obsolete.
Brendan Patterson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 17, 2011
Just trying to figure out where I went wrong the first time. I now see that the original documentation did need some love as it was missing the plugins-version="2" attribute which was likely part of what tripped me up. Thx again.
1 vote
Brendan Patterson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 8, 2011
To get this working on a temporary basis I dug through the Crowd source to see how listeners work there. I added my class directly to the crowd-server-2.2.7.jar and updated it's system-listeners.xml entires to add my listener. This worked. Based on the fact that I just copy/pasted everything into the Crowd core-stuff and it worked there.....I'm pretty sure the AnnotationBasedEventListener plugin is not working. I will open an issue on j.a.c. and post the actual plugin created from the documentation.
TAGS
AUG Leaders

Atlassian Community Events