Receiving 404 when making request to REST endpoint

I have a Confluence plugin with two main modules: xhtml-macro and rest. The macro displays a button that, when clicked, should make a POST request to my REST endpoint: /rest/vimeo-validator/1.0/validate. However, I am getting a 404 error returned from this request.

The complete code for the plugin can be found here: https://github.com/zenahirsch/confluence-validator

Any thoughts on what might be going on?

bah found it. You miss the “confluence” in the javascript:

$.post('/confluence/rest/vimeo-validator/1.0/validate',
            function (data, status) {
                console.log('status: ', status);
                console.log('data: ', data);
            }
        );

Your site is accessed by http://localhost:1990/confluence but you are posting in localhost:1990/rest…
Or even better change to

$.post(AJS.params.baseUrl+'/rest/vimeo-validator/1.0/validate',
            function (data, status) {
                console.log('status: ', status);
                console.log('data: ', data);
            }
        );

to ensure that when you change url that won’t be a problem

1 Like

@Panos,

Ah! Getting closer! Now I am getting a 403 (Forbidden). But I am using the @AnonymousAllowed annotation, so I’m not sure what is wrong…

Latest changes are in the repo: https://github.com/zenahirsch/confluence-validator

What happens if you login?

Hmm, I’m not quite sure I know what you mean. I am already logged into the local installation of Confluence where I am testing the plugin. Is there something else?

As a sidenote you can’t/shouldn’t have anonymous allowed and change page data.
Remove everything except the system.out and the response. Are you getting hello world back?

@Panos, yes, I still get a 403 :confused:

@POST
@Path("/validate")
@AnonymousAllowed
@Consumes(MediaType.APPLICATION_JSON)
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public final Response post(final String json) {  
    System.out.println(json); 
        
    return Response.ok(new ValidatorRestModel("Hello World")).build();
}

New thread: @AnonymousAllowed REST endpoint returns 403

Hi, I am looking for a similar solution can you please activate your git-hub link to access your code ?

Thanks in advance

She was accessing the resource from / whilst content base is /confluence