Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Preethihr March 29, 2022

Hi Team,

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("AIDT Plugin: 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?

 

Thanks & Regards,

Preethi H R

 

0 answers

Suggest an answer

Log in or Sign up to answer