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();
}
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.