Can't get Active Objects to work in Jira Plugin

I am currently doing an internship that involves creating Jira plugins to solve some problems the users at the company experience with Jira. For the first extension I need to create a new section on the view issue page where users can put input and edit the input. In order to do this I’ve created a web-panel which contains a input. But no matter what I try (And I’ve been trying different things for the last 3 weeks) I can’t get active objects to work.

Currently the moment the plugin tries to load in jira it shows the error: “Error rendering ‘tig.jira.extension.tigPasswordExtension:issue-page-input’. Please contact your JIRA administrators.” and when I try to test the REST API call in the restbrowser it shows the error:

"“message”: “AOP configuration seems to be invalid: tried calling method [public abstract net.java.ao.RawEntity[] com.atlassian.activeobjects.external.ActiveObjects.find(java.lang.Class,net.java.ao.Query)] on target [com.atlassian.activeobjects.osgi.TenantAwareActiveObjects@12bfb51b]; nested exception is java.lang.IllegalArgumentException: object is not an instance of declaring class”,
_ “status-code”: 500,"_

Is there anyone here that can replicate my problem and pinpoint what I am screwing up?

My current files are as follows:

Atlassian-plugin.xml

<atlassian-plugin key="${atlassian.plugin.key}" name="${project.name}" plugins-version="2">
    <plugin-info>
        <description>${project.description}</description>
        <version>${project.version}</version>
        <vendor name="${project.organization.name}" url="${project.organization.url}"/>
        <param name="plugin-icon">images/pluginIcon.png</param>
        <param name="plugin-logo">images/pluginLogo.png</param>
    </plugin-info>
    <!-- add our i18n resource -->
    <resource type="i18n" name="i18n" location="tigPasswordExtension"/>
    <!-- add our web resources -->
    <web-resource key="tigPasswordExtension-resources" name="tigPasswordExtension Web Resources">
        <dependency>com.atlassian.auiplugin:ajs</dependency>

        <resource type="download" name="tigPasswordExtension.css" location="/css/tigPasswordExtension.css"/>
        <resource type="download" name="tigPasswordExtension.js" location="/js/tigPasswordExtension.js"/>
        <resource type="download" name="images/" location="/images"/>
        <context>tigPasswordExtension.resource</context>
    </web-resource>

    <web-panel name="IssuePageInput" i18n-name-key="issue-page-input.name" key="issue-page-input" location="atl.jira.view.issue.right.context" weight="1">
        <description key="issue-page-input.description">Passwords en SSH</description>
        <context-provider class="tig.jira.extension.tigPasswordExtension.PasswordContextProvider"/>
        <component-import key="appProps" interface="com.atlassian.sal.api.ApplicationProperties"/>
        <resource name="view" type="velocity" location="/vm/password-input.vm"/>
        <label key="issue-page-input.title"/>
    </web-panel>

        <!-- Active Objects module -->
    <ao key="password-ao">
        <description>The configuration of the Active Objects service</description>
        <entity>tig.jira.extension.tigPasswordExtension.ao.PasswordModel</entity>
    </ao>

    <rest name="Password Resource" i18n-name-key="password-resource.name" key="password-resource" path="/passwordresource" version="1.0">
        <description key="password-resource.description">The Password Resource Plugin</description>
    </rest>
</atlassian-plugin>

tigPasswordExtension.js

AJS.toInit(function($) {
    AJS.$('#searchButton2').click(function (){
        var test = "lol";
        AJS.$.ajax({
            url:"jira/rest/passwordresource/1.0/password",
            type: "post",
            dataType: 'json',
            async: false,
            data: ({issueKey : document.getElementById("issueKeyInput").value, content: document.getElementById("passwordInput").value}),
            success: function(data)
            {
                test = data;
                console.log(test);
            }
        })
    });
});

PasswordDto

package tig.jira.extension.tigPasswordExtension.dto;

public class PasswordDto {

    private String issueKey;
    private String content;

    public PasswordDto(){}

    public String getIssueKey(){return this.issueKey;}

    public void setIssueKey(String issueKey){this.issueKey = issueKey;}

    public String getContent(){return this.content;}

    public void setContent(String content){this.content = content;}
}

PasswordModel

package tig.jira.extension.tigPasswordExtension.ao;


import net.java.ao.Entity;
import net.java.ao.Preload;

@Preload
public interface PasswordModel extends Entity {

    String getIssue();
    void setIssue(String issue);

    String getContent();
    void setContent(String content);
}

PasswordDao

package tig.jira.extension.tigPasswordExtension.ao;

import com.atlassian.activeobjects.external.ActiveObjects;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import com.google.common.collect.ImmutableMap.Builder;
import net.java.ao.Query;

import javax.inject.Inject;
import javax.inject.Named;
import java.util.Map;


@Named
public class PasswordDao {

    private final ActiveObjects activeObjects;

    @Inject
    public PasswordDao(@ComponentImport ActiveObjects activeObjects){this.activeObjects = activeObjects;}

    public PasswordModel getByIssueKey(String issueKey){
        Query query = this.buildIssueQuery(issueKey);

        PasswordModel[] passwordModels = this.activeObjects.find(PasswordModel.class, query);
        return passwordModels.length > 0 ? passwordModels[0] : null;
    }

    public void update(String issueKey, String content){

       PasswordModel passwordModel = this.getByIssueKey(issueKey);
        if (passwordModel == null){
            Map<String, Object> params = (new Builder()).put("ISSUE_KEY", issueKey).put("CONTENT", content).build();
            this.activeObjects.create(PasswordModel.class, params);
        } else {
            passwordModel.setContent(content);
            passwordModel.save();
        }
    }

    private Query buildIssueQuery(String issueKey){
        return Query.select().where("ISSUE_KEY = ?", issueKey);
    }
}

PasswordResource

package tig.jira.extension.tigPasswordExtension.rest;

import tig.jira.extension.tigPasswordExtension.service.PasswordService;

import javax.ws.rs.*;


@Path("/password")
public class PasswordResource{

    private final PasswordService passwordService;

    public PasswordResource(PasswordService passwordService){this.passwordService = passwordService;}

    @POST
    public void update(@QueryParam("issue") String issueKey, @QueryParam("content") String content) {
        this.passwordService.update(issueKey, content);
    }
}

PasswordService

package tig.jira.extension.tigPasswordExtension.service;

import tig.jira.extension.tigPasswordExtension.ao.PasswordDao;
import tig.jira.extension.tigPasswordExtension.ao.PasswordModel;
import tig.jira.extension.tigPasswordExtension.dto.PasswordDto;

import javax.inject.Inject;
import javax.inject.Named;

@Named
public class PasswordService {

    private final PasswordDao passwordDao;

    @Inject
    public PasswordService(PasswordDao passwordDao){
        this.passwordDao = passwordDao;
    }

    public void update(String issueKey, String content){
        this.passwordDao.update(issueKey, content);
    }

    public PasswordDto getByIssueKey(String issueKey){
        PasswordModel passwordModel = this.passwordDao.getByIssueKey(issueKey);
        if (passwordModel == null){
            return null;
        } else {
            PasswordDto dto = new PasswordDto();
            dto.setIssueKey(issueKey);
            dto.setContent(passwordModel.getContent());
            return dto;
        }
    }
}

PasswordContextProvider

package tig.jira.extension.tigPasswordExtension;

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.plugin.webfragment.contextproviders.AbstractJiraContextProvider;
import com.atlassian.jira.plugin.webfragment.model.JiraHelper;
import com.atlassian.jira.user.ApplicationUser;
import tig.jira.extension.tigPasswordExtension.dto.PasswordDto;
import tig.jira.extension.tigPasswordExtension.service.PasswordService;

import java.util.HashMap;
import java.util.Map;

public class PasswordContextProvider extends AbstractJiraContextProvider {

    Map contextMap = new HashMap();
    private String issueKey;

    private final PasswordService passwordService;

    public PasswordContextProvider(PasswordService passwordRepository){
        this.passwordService = passwordRepository;
    }

    public Map getContextMap(ApplicationUser user, JiraHelper jiraHelper) {

        Issue currentIssue = (Issue) jiraHelper.getContextParams().get("issue");
        issueKey = currentIssue.getKey();

        //passwordService.update(issueKey, "klote");

        PasswordDto passwordDto = this.passwordService.getByIssueKey(issueKey);

       if (passwordDto != null){
           contextMap.put("AO", "1");
           contextMap.put("content", "Staat nog niks in gek");
           if (passwordDto.getContent() != null) {
               contextMap.put("content", passwordDto.getContent());
           }
       }
        contextMap.put("issueKey", issueKey);
        return contextMap;
    }
}

Make sure that these:
String getIssue();
void setIssue(String issue);

String getContent();
void setContent(String content);

Are public in scope. I haven’t seen this error before but the above will cause issues. If you still have errors - can you post your Pom.xml?(or the dependencies and plugins parts?

Thanks for the fast reply daniel. I just tried it and it still doesn’t work. I forgot to add to the initial question that during debugging the extensions stops working during the line PasswordDto passwordDto = this.passwordService.getByIssueKey(issueKey); or passwordService.update(issueKey, “klote”); if it isn’t commented out.

This is my current pom.xml file"

Pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>tig.jira.extension</groupId>
    <artifactId>tigPasswordExtension</artifactId>
    <version>1.0</version>
    <organization>
        <name>Example Company</name>
        <url>http://www.example.com/</url>
    </organization>
    <name>tigPasswordExtension</name>
    <description>This is the tig.jira.extension:tigPasswordExtension plugin for Atlassian JIRA.</description>
    <packaging>atlassian-plugin</packaging>
    <dependencies>
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-api</artifactId>
            <version>${jira.version}</version>
            <scope>provided</scope>
        </dependency>
        <!-- Add dependency on jira-core if you want access to JIRA implementation classes as well as the sanctioned API. -->
        <!-- This is not normally recommended, but may be required eg when migrating a plugin originally developed against JIRA 4.x -->
        <!--
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-core</artifactId>
            <version>${jira.version}</version>
            <scope>provided</scope>
        </dependency>
        -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.plugin</groupId>
            <artifactId>atlassian-spring-scanner-annotation</artifactId>
            <version>${atlassian.spring.scanner.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.plugin</groupId>
            <artifactId>atlassian-spring-scanner-runtime</artifactId>
            <version>${atlassian.spring.scanner.version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
            <scope>provided</scope>
        </dependency>
        <!-- WIRED TEST RUNNER DEPENDENCIES -->
        <dependency>
            <groupId>com.atlassian.plugins</groupId>
            <artifactId>atlassian-plugins-osgi-testrunner</artifactId>
            <version>${plugin.testrunner.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>jsr311-api</artifactId>
            <version>1.1.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.2.2-atlassian-1</version>
        </dependency>
        <dependency>
            <groupId>com.atlassian.sal</groupId>
            <artifactId>sal-api</artifactId>
            <version>3.0.2</version>
        </dependency>
        <!-- Uncomment to use TestKit in your project. Details at https://bitbucket.org/atlassian/jira-testkit -->
        <!-- You can read more about TestKit at https://developer.atlassian.com/display/JIRADEV/Plugin+Tutorial+-+Smarter+integration+testing+with+TestKit -->
        <!--
        <dependency>
            <groupId>com.atlassian.jira.tests</groupId>
            <artifactId>jira-testkit-client</artifactId>
            <version>${testkit.version}</version>
            <scope>test</scope>
        </dependency>
        -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.plugins.rest</groupId>
            <artifactId>atlassian-rest-common</artifactId>
            <version>1.0.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.wink</groupId>
            <artifactId>wink-client</artifactId>
            <version>1.1.3-incubating</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.8.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.activeobjects</groupId>
            <artifactId>activeobjects-core</artifactId>
            <version>1.4.0</version>
        </dependency>
        <dependency>
            <groupId>net.java.dev.activeobjects</groupId>
            <artifactId>activeobjects</artifactId>
            <version>1.4.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>maven-jira-plugin</artifactId>
                <version>${amps.version}</version>
                <extensions>true</extensions>
                <configuration>
                    <productVersion>${jira.version}</productVersion>
                    <productDataVersion>${jira.version}</productDataVersion>
                    <productDataPath>${project.basedir}/src/test/resources/generated-test-resources.zip</productDataPath>
                    <applications>
                        <application>
                            <applicationKey>jira-servicedesk</applicationKey>
                            <version>${jira.servicedesk.application.version}</version>
                        </application>
                    </applications>
                    <!-- Uncomment to install TestKit backdoor in JIRA. -->
                    <!--
                    <pluginArtifacts>
                        <pluginArtifact>
                            <groupId>com.atlassian.jira.tests</groupId>
                            <artifactId>jira-testkit-plugin</artifactId>
                            <version>${testkit.version}</version>
                        </pluginArtifact>
                    </pluginArtifacts>
                    -->
                    <enableQuickReload>true</enableQuickReload>
                    <enableFastdev>false</enableFastdev>
                    <!-- See here for an explanation of default instructions: -->
                    <!-- https://developer.atlassian.com/docs/advanced-topics/configuration-of-instructions-in-atlassian-plugins -->
                    <instructions>
                        <Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>
                        <!-- Add package to export here -->
                        <Export-Package>tig.jira.extension.tigPasswordExtension.api,</Export-Package>
                        <!-- Add package import here -->
                        <Import-Package>org.springframework.osgi.*;resolution:="optional",
                            org.eclipse.gemini.blueprint.*;resolution:="optional",
                            avax.ws.rs*;version="[1,2)",
                            javax.servlet*;version="2.5",
                            javax.xml.bind*;version="[2.1,3)",
                            *;version="0";resolution:=optional, *</Import-Package>
                        <!-- Ensure plugin is spring powered -->
                        <Spring-Context>*</Spring-Context>
                    </instructions>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.atlassian.plugin</groupId>
                <artifactId>atlassian-spring-scanner-maven-plugin</artifactId>
                <version>${atlassian.spring.scanner.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>atlassian-spring-scanner</goal>
                        </goals>
                        <phase>process-classes</phase>
                    </execution>
                </executions>
                <configuration>
                    <scannedDependencies>
                        <dependency>
                            <groupId>com.atlassian.plugin</groupId>
                            <artifactId>atlassian-spring-scanner-external-jar</artifactId>
                        </dependency>
                    </scannedDependencies>
                    <verbose>false</verbose>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <properties>
        <jira.version>7.2.2</jira.version>
        <amps.version>6.2.11</amps.version>
        <plugin.testrunner.version>1.2.3</plugin.testrunner.version>
        <jira.servicedesk.application.version>3.2.2</jira.servicedesk.application.version>
        <atlassian.spring.scanner.version>1.2.13</atlassian.spring.scanner.version>
        <!-- This key is used to keep the consistency between the key in atlassian-plugin.xml and the key to generate bundle. -->
        <atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key>
        <!-- TestKit version 6.x for JIRA 6.x -->
        <testkit.version>6.3.11</testkit.version>
    </properties>
</project>

Change:


        <dependency>
            <groupId>com.atlassian.activeobjects</groupId>
            <artifactId>activeobjects-core</artifactId>
            <version>1.4.0</version>
        </dependency>
        <dependency>
            <groupId>net.java.dev.activeobjects</groupId>
            <artifactId>activeobjects</artifactId>
            <version>1.4.0</version>
        </dependency>

to:


        <dependency>
            <groupId>com.atlassian.activeobjects</groupId>
            <artifactId>activeobjects-plugin</artifactId>
            <version>1.1.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.atlassian.activeobjects</groupId>
            <artifactId>activeobjects-jira-spi</artifactId>
            <version>1.1.0</version>
            <scope>provided</scope>
        </dependency>

after that I think things should start working for you.

I changed it and it still doesn’t work. Do you happen to have any other ideas?

Edit: I manged to get it working using your solution and a new project. Not sure what the problem was but I am glad I got it working in the end.

Hi @daniel
I’ve got another strange behaviour of AO service. could you check the post?