Quantcast
Channel: Active questions tagged atlassian-plugin-sdk - Stack Overflow
Viewing all articles
Browse latest Browse all 280

Using @Consumes annotation on Rest API call giving 500 Internal Server Error

$
0
0

I am trying to build a custom build plugin using Atlassian sdk framework and in that I have developed a custom build Rest API to update data stored in database.

I am invoking the rest API using AJAX call from JavaScript file as given below:

            $.ajax({                headers:{         'Content-Type':'application/json','Accept': 'application/json'                },                url : serviceUrl +"rules/update",                type: "POST",                data : ruleObj            })

This API call will invoke the following REST API:

@Path("/rules")public class fieldsResource {    @POST    @Path("/update")    @Produces({ MediaType.APPLICATION_JSON })    @Consumes({ MediaType.APPLICATION_JSON })    public Response update(@Context    HttpServletRequest req, @Context    HttpServletResponse res) {        jiraAuthenticationContext = ComponentAccessor.getJiraAuthenticationContext();        appuser = jiraAuthenticationContext.getLoggedInUser();        // Fetch rule id of rule which need to be updated        final int ruleId = Integer.parseInt(req.getParameter("id"));        Rules rule = rule.findRuleById(ruleId);        boolean ifUserHasRequiredAccess = ifUserHasRequiredAccess(req, res, projectKey, appuser,                userManager, jiraAuthenticationContext, loginUriProvider);        if (ifUserHasRequiredAccess) {            log.warn("Update API is invoked for rule " + ruleId +" to update Action triggered by : " + appuser);               return Response.noContent().build();        }        return Response.status(401).build();    }}

Initially without adding Content-Type, Accept in JS file and without adding @Consumes({ MediaType.APPLICATION_JSON })The API call was successful, but After adding @Consumes({ MediaType.APPLICATION_JSON }), I am getting 500 Internal Server Error.

I tried adding 'text/plain' also, then also it is throwing 500 Internal Server Error.

I need to add @Consumes({ MediaType.APPLICATION_JSON }) for this API call.Can anyone please guide me on resolving this issue?


Viewing all articles
Browse latest Browse all 280

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>