I'm developing a Jira plugin that needs to be integrated with another service using Java 8 from the config page. Admin config page is ok, but when I do REST request to ConfigResource I got 404 Not Found. Seems that Spring Scanner 2 can't see ConfigResounce.
My ConfigResounce:
@Path("/")
public class ConfigResource
{
@ComponentImport
private final UserManager userManager;
@ComponentImport
private final PluginSettingsFactory pluginSettingsFactory;
@ComponentImport
private final TransactionTemplate transactionTemplate;
@Inject
public ConfigResource(UserManager userManager, PluginSettingsFactory pluginSettingsFactory,
TransactionTemplate transactionTemplate)
{
this.userManager = userManager;
this.pluginSettingsFactory = pluginSettingsFactory;
this.transactionTemplate = transactionTemplate;
}
@get
@Produces(MediaType.APPLICATION_JSON)
public Response get(@Context HttpServletRequest request)
{
String username = userManager.getRemoteUsername(request);
if (username == null || !userManager.isSystemAdmin(username))
{
return Response.status(Response.Status.FORBIDDEN).build();
}
return Response.ok(transactionTemplate.execute((TransactionCallback) () -> {
PluginSettings settings = pluginSettingsFactory.createGlobalSettings();
Config config = new Config();
config.setLicense((String) settings.get(Config.class.getName() + ".license"));
config.setUrl((String) settings.get(Config.class.getName() + ".url"));
String port = (String) settings.get(Config.class.getName() + ".port");
if (port != null)
{
config.setPort(Integer.parseInt(port));
}
config.setUsername((String) settings.get(Config.class.getName() + ".username"));
config.setPassword((String) settings.get(Config.class.getName() + ".password"));
return config;
})).build();
}
@PUT
@Consumes(MediaType.APPLICATION_JSON)
public Response put(final Config config, @Context HttpServletRequest request)
{
String username = userManager.getRemoteUsername(request);
if (username == null || !userManager.isSystemAdmin(username))
{
return Response.status(Response.Status.UNAUTHORIZED).build();
}
transactionTemplate.execute((TransactionCallback) () -> {
PluginSettings pluginSettings = pluginSettingsFactory.createGlobalSettings();
pluginSettings.put(Config.class.getName() + ".license", config.getLicense());
pluginSettings.put(Config.class.getName() +".url", config.getUrl());
pluginSettings.put(Config.class.getName() +".port",Integer.toString(config.getPort()));
pluginSettings.put(Config.class.getName() +".username", config.getUsername());
pluginSettings.put(Config.class.getName() +".password", config.getPassword());
return null;
});
return Response.noContent().build();
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response post(final Config config, @Context HttpServletRequest request)
{
String username = userManager.getRemoteUsername(request);
if (username == null || !userManager.isSystemAdmin(username))
{
return Response.status(Response.Status.UNAUTHORIZED).build();
}
final AuthMethod AUTH = new AuthMethod(new PasswordAuth(config.getUsername(), config.getPassword(), AuthModule.AUTO));
SaltClient client = new SaltClient(URI.create(config.getUrl()),
new HttpAsyncClientImpl(HttpClientUtils.defaultClient()));
// Ping all minions using a glob matcher
Target<String> globTarget = new Glob("*");
Map<String, Result<Boolean>> results = Test.ping().callSync(
client, globTarget, AUTH).toCompletableFuture().join();
System.out.println("--> Ping results:\n");
results.forEach((minion, result) -> System.out.println(minion + " -> " + result));
return Response.noContent().build();
}
}
My plugin-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:atlassian-scanner="http://www.atlassian.com/schema/atlassian-scanner/2"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.atlassian.com/schema/atlassian-scanner/2
http://www.atlassian.com/schema/atlassian-scanner/2/atlassian-scanner.xsd">
<atlassian-scanner:scan-indexes/>
</beans>
My 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="jira"/>
<!-- add our web resources -->
<web-resource key="jira-resources" name="jira Web Resources">
<dependency>com.atlassian.auiplugin:ajs</dependency>
<resource type="download" name="jira.css" location="/css/jira.css"/>
<resource type="download" name="jira.js" location="/js/jira.js"/>
<resource type="download" name="images/" location="/images"/>
<context>jira</context>
</web-resource>
<servlet key="admin-servlet" class="com.turtletraction.salted.jira.adminUI.AdminServlet">
<url-pattern>/salted/jira/admin</url-pattern>
</servlet>
<rest key="rest" path="/salted-jira-admin" version="1.0">
<description>Provides REST resources for the admin UI JIRA Salted API.</description>
</rest>
<web-item key="jira-menu-item" name="Salted Jira Admin" section="system.admin/globalsettings" weight="10" application="jira">
<description>Link to Salted Jira Admin Page.</description>
<label key="salted.jira.admin.label" />
<link linkId="salted-jira-admin-link">/plugins/servlet/salted/jira/admin</link>
</web-item>
</atlassian-plugin>
Looks like <rest> is not working here.
Request example:
GET http://localhost:2990/jira/rest/salted-jira-admin/1.0/
When I remove Java 8 code from ConfigResouce, REST works OK.
Please help, I spent a lot of time with that issue
My pom:
<?xml version="1.0" encoding="UTF-8"?>
<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>com.turtletraction.salted</groupId>
<artifactId>jira</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<artifactId>salted</artifactId>
<groupId>com.turtletraction.salted</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<organization>
<name>Example</name>
<url>example</url>
</organization>
<name>jira</name>
<description>This is the Salted API Jira plugin for Atlassian.</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>provided</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>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</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.templaterenderer</groupId>
<artifactId>atlassian-template-renderer-api</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.suse.salt</groupId>
<artifactId>salt-netapi-client</artifactId>
<version>0.17.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.sal</groupId>
<artifactId>sal-api</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>jira-maven-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
<configuration>
<productVersion>${jira.version}</productVersion>
<productDataVersion>${jira.version}</productDataVersion>
<!-- 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>
<!-- 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>
com.turtletraction.salted.jira.adminUI,
com.turtletraction.salted.jira.api,
</Export-Package>
<Import-Package>
org.springframework.osgi.*;resolution:="optional",
org.eclipse.gemini.blueprint.*;resolution:="optional",
*;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>
</plugins>
</build>
<properties>
<jira.version>8.0.2</jira.version>
<amps.version>8.0.2</amps.version>
<plugin.testrunner.version>2.0.1</plugin.testrunner.version>
<atlassian.spring.scanner.version>2.2.0</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>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
great work everybody, thank you for replies. The issue was in <scope>provided of external dependency that I used in pom. I removed <scope> and it worked.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.