EventListener plugin for JIRA 7.3.7

vhj5cob November 15, 2017

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

2 votes
Answer accepted
vhj5cob November 16, 2017

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);
        
    }

}

Daniel Wester
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.
November 21, 2017

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
Vítek Urban December 23, 2017

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){

}
0 votes
Alexey Matveev
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.
November 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

vhj5cob November 15, 2017

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
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.
November 15, 2017

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

Mizan
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.
November 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 ?

vhj5cob November 15, 2017

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
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.
November 15, 2017

@vhj5cob 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.

vhj5cob November 15, 2017

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.

Suggest an answer

Log in or Sign up to answer