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

Writing a new Jira Rest Service - The ResourceConfig instance does not contain any root resource classes

Graeme Mitchell April 16, 2013

I'm trying to create Jira rest services for the first time using the SDK kit. At the moment, I'm just trying to get the default example working creating by the SDK kit (template). The plugin created the following:-

@Path("/message")
public class restTest {

    @GET
    @AnonymousAllowed
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response getMessage()
    {
       return Response.ok(new restTestModel("Hello World")).build();
    }
}

My atlassian-plugin.xml file looks like this:-

<rest name="rest Test" i18n-name-key="rest-test.name" key="rest-test" path="/resttest" version="1.0">
    <description key="rest-test.description">The Rest Test Plugin</description>
  </rest>

I'm starting up a local dev instance using the atlas-run command. My baseUrl is http://localhost:2990/jira

I see my plugin is enabled and the rest test module is also enabled, but I cannot access the rest service. I'm expecting to use the following address:-

http://localhost:2990/jira/rest/resttest/1.0/message

When I try to call the rest service, I see the following exception returned to my cmd prompt running the Jira instance:-

Caused by: com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.

I've installed the rest api browser as part of the developers toolbox. I can see the plugin in the drop-down, but when I select it the list services remain as whatever I had previously selected (as though it's not able to load up properly). Can someone advise where I'm going wrong here? I tried adding an extra @Path("/helloworld") to getMessage() and using http://localhost:2990/jira/rest/resttest/1.0/message/helloworld but it doesn't work.

7 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Phillip Ponzer [Cprime]
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.
February 24, 2014

I have found the reason why I was getting this issue was because I had both javax.ws.rs AND jersey-client as dependencies in my pom.xml.

Since I was only relying on jersey-client for Base64-encoding, I was able to replace it with Apache's version of Base64: http://stackoverflow.com/questions/13109588/base64-encoding-in-java

import org.apache.commons.codec.binary.Base64;

Once I removed my reliance on jersey-client from the pom.xml, I no longer received this issue.

i.e. deleted the following from my pom.xml:

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-client</artifactId>
    <version>1.8</version>
</dependency>

0 votes
Jannik Luyten
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.
May 14, 2013

Indeed, creating a new plugin with a new rest-plugin module does the trick. This is because the Atlassian REST module depends on Jersey 1.0.2 (https://developer.atlassian.com/display/DOCS/REST+Plugin+Module), which is exactly the version that is supplied when creating a new plugin project with a new rest plugin-module.

Concretely, the following two dependencies need to be added to your pom.xml (notice the version):

<dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>jsr311-api</artifactId>
            <version>1.1.1</version>
            <scope>provided</scope>
 </dependency>
 <dependency> <!-- this dependency contains the common jersey dependencies -->
            <groupId>com.atlassian.plugins.rest</groupId>
            <artifactId>atlassian-rest-common</artifactId>
            <version>1.0.2</version>
            <scope>provided</scope>
</dependency>

And the following element to your atlassian-plugin.xml file

<rest key="rest-services" path="/foo-bar" version="1.0">
    <description>Provides the REST-services.</description>
</rest>

This solved it for me!

Adrien Ragot 2
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.
August 7, 2015

Hi, that was in 2013. What are the up-to-date REST library versions for JIRA and how can we check we're using the right ones?

0 votes
Graeme Mitchell May 2, 2013

For any one else having this problem, I found that if I started a brand new simple project and setup a new rest service then it worked perfectly. I'm starting to wonder if I have some conflicts in my POM as I have some third party jars. Pretty sure that some of them have some of the jersey jars in the pom

0 votes
RambanamP
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.
April 29, 2013

try with the following code

@GET
	@Produces("application/json")
	@Path("/helloworld")
	public Response getMessage() {
		JSONObject response = new JSONObject();
		try {
		response.append("message", "hello World Example");
			
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return Response.ok(response.toString()).build();
	}

URL should be :http://localhost:2990/jira/rest/resttest/1.0/message/helloworld

Graeme Mitchell April 29, 2013

Same error in this case. I was a little dubious on this as you've suggested using a PUT method instead of a GET. I don't think would be right in this instance as what I'm really performing is a GET.

RambanamP
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.
April 29, 2013

sorry it is a GET method

0 votes
Colin Goudie
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.
April 29, 2013

Did you get anwhere with this?

Graeme Mitchell April 29, 2013

Hi Colin,

I've not had the time to look into this problem any further beyond Rambanam's answer below. I'm a bit stuck at this stage.

Graeme

0 votes
Graeme Mitchell April 16, 2013

Additional information - I noticed I also get the same exception (The ResourceConfig.....) returned in my cmd prompt (used for atlas-run) when trying to access the service using the Rest API browser

0 votes
Graeme Mitchell April 16, 2013

Additional information - response received back to my client calling the service is 404

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events