Rest Service created by SDK doesnt work. 404

I have very strange problem.

Im trying to create a rest resource module for jira 5.2 using atlassian sdk 4.1.3

i used to do this many times already, but this time im getting 404 on fresh and clean rest service created by sdk. It is so trivial that i just have no clue what could be wrong.

This is what i did.

1. ran atlas-create-jira-plugin-module

2. chosen option 14 for rest resource module

3. kept all properties at default (hit Enter 4 times)

4. ran atlas-run. server came up without problems.

5. went to /jira/rest/myrestresource/1.0/message. response: 404

huh? i did not change anything, this is sdk code and i did it already many times. Maybe i am missing something in the url?

code created by sdk

atlassian-plugin.xml

<rest name="My Rest Resource" i18n-name-key="my-rest-resource.name" key="my-rest-resource" path="/myrestresource" version="1.0">
    <description key="my-rest-resource.description">The My Rest Resource Plugin</description>
  </rest>

MyRestResource.java

/**
 * A resource of message.
 */
@Path("/message")
public class MyRestResource {

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

MyRestResourceModel.java

@XmlRootElement(name = "message")
@XmlAccessorType(XmlAccessType.FIELD)
public class MyRestResourceModel {

    @XmlElement(name = "value")
    private String message;

    public MyRestResourceModel() {
    }

    public MyRestResourceModel(String message) {
        this.message = message;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}

Im not getting any exceptions or errors. It looks like im using wrong URL. What could be wrong with this?

/jira/rest/myrestresource/1.0/message

I have also verified that My Rest Resource module is deployed and enabled in plugin manager.

5 answers

1 accepted

This widget could not be displayed.

Yes. Found it.

The problem was indeed in another service that clashed with the same path pattern /message as my new plugin.

Symtomps: 404 on correct url even when service is indicated as deployed and started. no exception on service access.

Solution: make sure there is no other rest service with the same path mapping.

This widget could not be displayed.

what is the url of your jira instance?

i mean something if you are using http://localhost:9090/jira

then use /jira/rest/myrestresource/1.0/message

or if you are using like this http://localhost:9090

then use this url

/rest/myrestresource/1.0/message

yes ive checked that. My baseUrl is set to /jira, therefore im using /jira/rest/myrestresource/1.0/message

no luck.

/rest/myrestresource/1.0/message

also no luck. But strange is that im not getting 404 but just an empty page. Which im getting basically on any URL without basePath

This widget could not be displayed.

its driving me nuts all day.I have reviewed everything 100 times and compared to the services that i have already implemented in the same plugin. I just cant see why it isnt working.

This widget could not be displayed.

change your code to as follows

/**
 * A resource of message.
 */
@Path("/message")
public class MyRestResource {
 
    @GET
    @AnonymousAllowed
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
	@Path("/getmessage")
    public Response getMessage()
    {
       return Response.ok(new MyRestResourceModel("Hello World")).build();
    }
}

then try with
/jira/rest/myrestresource/1.0/message/getmessage

intrestning aproach. But nope, still 404 with

/jira/rest/myrestresource/1.0/message/getmessage

and also with

/jira/rest/myrestresource/1.0/getmessage
This widget could not be displayed.

1. Check if your plugin is enabled in upm. Also, check if all your modules are enabled.

2. Try http://localhost:2990/jira/rest/myresource/1.0/message.json (with .json at the end of the url).

3. Check REST API tool. JIRA > Administration > System > REST API Browser (http://moborn:2990/jira/plugins/servlet/restbrowser) > Applinks Product Plugin (click and change on your plugin). You should get something like this:

1. Ive checked plugin is enabled. My Rest Resource Module is activated.

2. no luck with http://localhost:2990/jira/rest/myresource/1.0/message.json

3. is intrestning. I didnt know about this feature, very handy. I have tried your suggestions, but restbrowser seems to go crazy when i pick my plugin. It doesnt show me its rest methods like in your screenshot. But instad it shows the methods from a plugin selected before.

So if i change from Applinks Product Plugin to my plugin, i still see all the methods from Applinks Product Plugin and not from my plugin. If i change to something else, i.e baseUrl Plugin, then i see the methods from baseUrl Plugin.

wierd...

but what does it say? Something wrong with the plugin or the rest module? And i wonder why it doesnt explode and rains exceptions but instead just shows me functions from other services?

Oh it did actualy rained exceptions on selecting my plugin in rest browser. This becomes interestning. Here is the part of the log which i think is quite relevant.

2013-07-31 16:46:04,386 http-bio-2990-exec-38 ERROR admin 1006x6405x1 bl59z1 127.0.0.1 /rest/renderablefields/1.0/application.wadl [jersey.spi.inject.Errors] The following errors and warnings have been detected with resource and/or provider classes:
SEVERE: Conflicting URI templates. The URI template /message for root resource class com.bssnsoftware.jira.plugin.createandlink.rest.MyRestResource and the URI template /message transform to the same regular expression /message(/.*)?

I have another service that maps to /message and it works fine. Looks like there is a clash with that. Im gonna try another mapping and report if it worked.

> I have another service that maps to /message and it works fine.

Yeah, this is why it doesn't work. You can't have two rest services mapping to the same place. Just change:

* A resource of message.
*/
@Path("/message")

to something else :

* A resource of message.
*/
@Path("/message2")

well. This turned out to be the problem. Of course you cant map the same path to different services. This makes sense. On the other hand, i didnt realy came to the mappings. I have created a new service with SDK which has set the mapping to /message by default.

Its just an unlucky situation when you already have another service which works with that mapping. So the best practice would be to avoid using /message mapping. Or if you do that, you should be aware of what may happen if you create a new rest module with SDK.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted 8 hours ago in Jira

Atlassian Research Workshop opportunity on Sep. 28th in Austin, TX

We're looking for participants for a workshop at Atlassian! We need Jira admins who have interesting custom workflows, issue views, or boards. Think you have a story to sha...

26 views 1 2
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you