Reputation: 1189
I have a class as a sub resource and when ran, everything works with no errors except for eclipse show red underline, how can I make eclipse "know" that the parent @Path is part of it.
ex.
in MessageResouce
@Path("/{messageId}/comments")
public CommentResource getCommentResource() {
return new CommentResource();
}
and in CommentResource
@Path("/") // optional for subresources
@Produces(MediaType.APPLICATION_XML)
@Consumes(MediaType.APPLICATION_XML)
public class CommentResource {
private CommentService commentService = new CommentService();
@GET
public List<Comment> getAllComments(@PathParam("messageId") long messageId) {
return commentService.getAllComments(messageId);
}
@POST
public Comment addMessage(@PathParam("messageId") long messageId,
Comment comment) {
return commentService.addComment(messageId, comment);
}
@PUT
@Path("/{commentId}")
public Comment updateMessage(@PathParam("messageId") long messageId,
@PathParam("commentId") long commentId, Comment comment) {
comment.setId(commentId);
return commentService.updateComment(messageId, comment);
}
@GET
@Path("/{commentId}")
public String test2(@PathParam("messageId") long messageId,
@PathParam("commentId") long commentId) { // messageId still gets
// passed from parent
// resource
return "Method return commment id: " + commentId + " and messageId: "
+ messageId;
}
@DELETE
@Path("/{commentId}")
public void deleteComment(@PathParam("messageId") long messageId,
@PathParam("commentId") long commentId) {
commentService.removeComment(messageId, commentId);
}
}
All the messageId path parameters are underlined with red with error but everything runs fine, it's annoying to see that there and I don't want anyone that might look at my code to freak out.
Thanks
Upvotes: 1
Views: 2212
Reputation: 1
you need to put your PathParam in the @Path(), wrapped in { }
like this
@POST @Path("/availabilityForTopic/{idTopic}") public Response addUserToAvailabilityForTopicList(@HeaderParam("token") String token, @PathParam("idTopic") int idTopic)
Upvotes: 0
Reputation: 441
I had this kind of problem because I used the wrong import javax.websocket.server.PathParam;
for my @PathParam
. My API's test worked but JAXRS was not happy with it. Using javax.ws.rs.PathParam;
can fix your problem.
Upvotes: 1
Reputation: 11
In my experience, the JAX-RS validation in Eclipse/JBoss Developer Studio, stumbles when multiple annotated HTTP method functions are included in the same injected class. For instance, a single @GET method sets off no alarms, but adding a @POST method makes the validator unable to accurately detect the bindings between the various @PathParam and @Path statements.
It's annoying, but does not negatively impact code compilation or execution.
As Corina explains, the only real option is to edit the IDE preferences to downgrade the severity of the exception. I choose "warning" rather than "ignore", so as not to completely suppress any legitimate errors.
Upvotes: 1
Reputation: 21
I had the same problem but I resolved it by going to Preferences -> JAX-RS -> JAX-RS Validator -> JAX-RS Resource Methods and I check Unbound @PathParam annotation value as a warning or ignore (default was error). In case of ignore you will no longer see that message. From what I've read there might be something which has to do with the JAX-RS validation. I'm using JAX-RS 1.1 with Jersey 1.19 (not sure if in JAX-RS 2.0 you would have the same behavior).
Upvotes: 2