Forums

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

Another solution for jira rest api response 415

m_yumen
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 15, 2020

I encountered this 415 issue a few days ago. When I searched on goolgle, the most common solution was adding correct 'Content-Type' in request header. It didn't work for me.

After doing a lot of research, finally, I found my solution:

Add annotation @Context to your method parameters. Annotation class' Qualified name is javax.ws.rs.core.Context.

eg:


@GET
@AnonymousAllowed
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Context
public Response getMessage(@Context HttpServletRequest request) {
return Response.ok(new SprintBoardRestResourceModel("Hello World")).build();
}


@GET
@Path("/searchUser")
@Produces({MediaType.APPLICATION_JSON})
public Response searchUsers(@Context @QueryParam("query") String query) {
List<UserSearchResourceModel> userSearchResourceModels = new ArrayList<UserSearchResourceModel>();
if (query != null && query.length() > 0) {
UserSearchParams searchParams = UserSearchParams.builder().includeActive(true).sorted(true).build();
List<String> users = userSearchService.findUserNames(query, searchParams);
if (users != null) {
for (String user : users) {
userSearchResourceModels.add(new UserSearchResourceModel(user, user));
}
}
}
return Response.ok(userSearchResourceModels).build();
}

 

1 answer

0 votes
Veera
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 15, 2020

Good to know. Thanks for sharing @m_yumen 

Suggest an answer

Log in or Sign up to answer