EventListener plugin for JIRA 7.3.7 Edited

I am using Latest Atlasian SDK 6.3.4, JIRA 7.3.7

Created a project using atlas-create-jira-plugin

My Listener

package com.jira.plugin.listener;

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.atlassian.event.api.EventListener;
import com.atlassian.event.api.EventPublisher;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.event.type.EventType;
import com.atlassian.jira.issue.Issue;
import com.atlassian.plugin.spring.scanner.annotation.export.ExportAsService;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;

@ExportAsService
public class JiraListener{

    private static final Logger log = LoggerFactory.getLogger(JiraListener.class);

    @ComponentImport
    private final EventPublisher eventPublisher;
    
    
    @Inject
    public JiraListener(final EventPublisher eventPublisher) {
            this.eventPublisher = eventPublisher;
     }

    @EventListener
    public void onIssueEvent(IssueEvent issueEvent) {
        log.info("inside onIssueEvent");
        Issue issue;
        Long eventTypeId;
        eventTypeId = issueEvent.getEventTypeId();
        try {
            issue = issueEvent.getIssue();
            if (EventType.ISSUE_GENERICEVENT_ID.equals(eventTypeId)) {
                log.info("Issue {} has been created", issue.getKey());
            } else if (EventType.ISSUE_CREATED_ID.equals(eventTypeId)) {
                log.info("Issue {} has been created at {}.", issue.getKey(), issue.getCreated());
            } else if (EventType.ISSUE_UPDATED_ID.equals(eventTypeId)) {
                log.info("Issue {} has been updated at {}.", issue.getKey(), issue.getUpdated());
            }
        } catch (Exception ex) {
            log.error("Caused:", ex);
        }

        if (log.isTraceEnabled()) {
            log.trace("Exit event " + issueEvent.getEventTypeId() + " on issue " + issueEvent.getIssue());
        }
    }

}

 

When i build and run it "atlas-run"

I am able to long in to url http://localhost:2990/jira/login.jsp

The add-on is enabled Setting > Add-On > Manage Add on and its enabled

But I am not able to get the logs inside

@EventListener
    public void onIssueEvent(IssueEvent issueEvent){

}

Whether my plugin is working or not im not sure. Can any one please help me in this.

3 answers

1 accepted

It Worked finally . Need to register the Event Publisher

@Inject
    public JiraListener(final EventPublisher eventPublisher) {
            eventPublisher.register(this);
     }

OR

public class JiraListener implements InitializingBean, DisposableBean{

@Inject
    public JiraListener(final EventPublisher eventPublisher) {
        
        log.info("inside JiraListener Constructor");
            this.eventPublisher = eventPublisher;
     }

@Override
    public void destroy() throws Exception {
        log.info("inside destroy unregister");
        eventPublisher.unregister(this);
        
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("inside afterPropertiesSet register");
        eventPublisher.register(this);
        
    }

}

Take a look at https://docs.atlassian.com/sal-api/3.0.0/sal-api/apidocs/com/atlassian/sal/api/lifecycle/LifecycleAware.html in SAL. If you use that you're slightly less dependent on Spring's internal beans.

Just fyi - https://community.developers.atlassian.com is an awesome place to get help with these questions in the future (you've got some of the Developer Experience folks over there to help you).

0 votes
Alexey Matveev Community Champion Nov 15, 2017

Hello,

You use log.trace which means that the logging level of your plugin must be TRACE. In order to set the TRACE level. Go to cog item->system->logging and profiling then you will see there the Configure button. Push it and enter "com.jira.plugin.listener" into package name and choose TRACE in the Logging Level. You do not need to restart Jira. If you restart Jira, then your logging level will be set to default.

You can read more here about logging

https://confluence.atlassian.com/adminjiraserver071/logging-and-profiling-802592962.html

Im not able to get the below mentioned logs

log.info("inside onIssueEvent");

or any logs below also

 if (EventType.ISSUE_GENERICEVENT_ID.equals(eventTypeId)) {
                log.info("Issue {} has been created", issue.getKey());
            } else if (EventType.ISSUE_CREATED_ID.equals(eventTypeId)) {
                log.info("Issue {} has been created at {}.", issue.getKey(), issue.getCreated());
            } else if (EventType.ISSUE_UPDATED_ID.equals(eventTypeId)) {
                log.info("Issue {} has been updated at {}.", issue.getKey(), issue.getUpdated());
            }

Configured log4j as in this

https://developer.atlassian.com/jiradev/jira-platform/guides/other/tutorial-writing-jira-event-listeners-with-the-atlassian-event-library

Alexey Matveev Community Champion Nov 15, 2017

I would actually put log.error everywhere just to exclude wrong log4j configuration. 

Mizan Community Champion Nov 15, 2017

Are these events fired ? Are you creating an issue and updating it ?

If no then what are you expecting the event listener to do ?

Im creating issues, updating, resolving it. But the fire event is not taking place. I need the event fire to take place and come inside onIssueEvent() to track the issues create, updated and resolved.

Mizan Community Champion Nov 15, 2017

@Vijaya Kumar the events are fired when you do an action on the issue . 

Are you checking the <jira_home>/logs/atlassian-jira.log file ?

try using log.error as well.

Nope ive received below logs

15-Nov-2017 18:55:38.915 WARNING [http-nio-8090-exec-4] com.sun.jersey.spi.container.servlet.WebComponent.filterFormParameters A servlet request, to the URI http://localhost:8090/rest/activity-stream/1.0/preferences?_=1510752338874, contains form parameters in the request body but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using @FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected.
15-Nov-2017 18:55:48.940 WARNING [http-nio-8090-exec-16] com.sun.jersey.spi.container.servlet.WebComponent.filterFormParameters A servlet request, to the URI http://localhost:8090/rest/activity-stream/1.0/preferences?_=1510752348896, contains form parameters in the request body but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using @FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected.
15-Nov-2017 18:55:50.200 WARNING [http-nio-8090-exec-20] com.sun.jersey.spi.container.servlet.WebComponent.filterFormParameters A servlet request, to the URI http://localhost:8090/rest/activity-stream/1.0/preferences?_=1510752350158, contains form parameters in the request body but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using @FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected.

Hi,

I' ve just faced very similar problem. My listener did not register nor do anything else. The problem was with the final specification here:

@EventListener
    public void onIssueEvent(final IssueEvent issueEvent){

}

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,968 views 12 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot