Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

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

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As per your code snippet, you are not returning any object in the response body.

return Response.noContent().build(); 
or 
return Response.status(401).build();

@Consumes expects a json response being returned from your API.

Do you want the API to return any response?

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!