Hi,
In JIRA plugin development, i plan to create REST API by follow below link and create such "MyRestResource" class which will have SAVE and retrival methods.
Can you please let me know how it could be achievable for calling REST API from vm template file (webwork module) in Jira Plugin and REST API will be also in same plugin project.
Thank You
Community moderators have prevented the ability to post new answers.
I have called REST requests from velocity files before, what I did was use jQuery's ajax function.
For example:
<script type="text/javascript"> #set($D = '$') AJS.${D}.ajax({ url: "/rest/auth/1/session", type: "get", dataType: "json", context: document.body }).done(function(data) { alert(data.name); }); </script>
Note the #set part in the code. Since $ is a keyword for velocity, this is my way of escaping it.
This code uses JIRA's REST api and i'm quite sure, you can call your own functions like that as well.
here, in my case url shows not found.
i have created rest resource class in my JIRA Plugin at location - "[FOLDER]/Src/Main/JAVA/com.company.jira.plugin.REST/PlanIssuesRestResources"
when i try to access below url then ,
http://localhost:2990/jira/rest/auth/1/PlanIssuesRestResource
shows me as below in browser:
<status> <status-code>404</status-code> <message> null for uri: http://localhost:2990/jira/rest/auth/1/PlanIssuesRestResource </message> </status>
@Path("/message") public class PlanIssuesRestResource { @GET @AnonymousAllowed @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Path("/{key}") public Response getMessageFromPath(@PathParam("key") String key) { return Response.ok(new PlanIssuesResourceModel(key, getMessageFromKey(key))).build(); }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your path is incorrect. According to the tutorial, the path is defined like this:
http://myhost.com:port/myapp/rest/api-name/api-version/resource-name
So for you, it should be something like this:
http://localhost:2990/jira/rest/<api-name>/latest/message/<key>
<api-name> should be taken from atlassian-plugin.xml file, for example, if you have:
<
rest
key
=
"helloWorldRest"
path
=
"/helloworld"
version
=
"1.0"
>
<
description
>Provides hello world services.</
description
>
</
rest
>
then it would be helloworld.
<key> part is whatever you have defined there in the function.
Have a look here for more details: https://developer.atlassian.com/display/DOCS/REST+Plugin+Module
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank You, by follow that link URL composition, It works for below stuff:
@GET @AnonymousAllowed @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public Response getMessage() { return Response.ok(new PlanIssuesRestResourceModel("Hello World")).build(); }
i can access through
host:2990/jira/rest/planissuesrestresource/1.0/message
Now, i have updated the stuff as below:
@GET @AnonymousAllowed @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Path("/{key}") public Response getMessageFromPath(@PathParam("key") String key) { return Response.ok(new PlanIssuesRestResourceModel(key, getMessageFromKey(key))).build(); }
public Response getMessage(@QueryParam("key") String key) { if(key!=null) return Response.ok(new PlanIssuesRestResourceModel(key, getMessageFromKey(key))).build(); else return Response.ok(new PlanIssuesRestResourceModel("default","Hello World")).build(); }
and tried to access as below but, it shows me "Internal Server error" and not worked.
http://localhost:2990/jira/rest/planissuesrestresource/1.0/message/keyVal
http://localhost:2990/jira/rest/planissuesrestresource/1.0/message/key/value
How it could be accessible for query string/query path ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It works now,
http://localhost:2990/jira/rest/planissuesrestresource/1.0/message/keyvalue
i had removed default constructore from resourceModel class so.
Thank You for your comments.
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.