Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

241
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda