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.
Community moderators have prevented the ability to post new answers.
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>
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
sorry it is a GET method
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you get anwhere with this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Additional information - response received back to my client calling the service is 404
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.