Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

242
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda