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:{
<span>'Content-Type'</span>:<span>'application/json'</span>,
<span>'Accept'</span>: <span>'application/json'</span>
},
url : serviceUrl + <span>"rules/update"</span>,
<span>type</span>: <span>"POST"</span>,
data : ruleObj
}) This API call will invoke the following REST API:
<span>@Path("/rules")</span>
<span>public</span> <span>class</span> <span>fieldsResource</span> {
<span>@POST</span>
<span>@Path("/update")</span>
<span>@Produces({ MediaType.APPLICATION_JSON })</span>
<span>@Consumes({ MediaType.APPLICATION_JSON })</span>
<span>public</span> Response <span>update</span><span>(@Context
HttpServletRequest req, @Context
HttpServletResponse res)</span> {
jiraAuthenticationContext = ComponentAccessor.getJiraAuthenticationContext();
appuser = jiraAuthenticationContext.getLoggedInUser();
<span>// Fetch rule id of rule which need to be updated</span>
<span>final</span> <span>int</span> <span>ruleId</span> <span>=</span> Integer.parseInt(req.getParameter(<span>"id"</span>));
<span>Rules</span> <span>rule</span> <span>=</span> rule.findRuleById(ruleId);
<span>boolean</span> <span>ifUserHasRequiredAccess</span> <span>=</span> ifUserHasRequiredAccess(req, res, projectKey, appuser,
userManager, jiraAuthenticationContext, loginUriProvider);
<span>if</span> (ifUserHasRequiredAccess) {
log.warn(<span>"AIDT Plugin: Update API is invoked for rule "</span> + ruleId + <span>" to update Action triggered by : "</span> + appuser);
<span>return</span> Response.noContent().build();
}
<span>return</span> Response.status(<span>401</span>).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