I am getting
Error 405: Method not allowed
MessageEnd.java:
package com.example.wordcount;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@Path("/jersey")
public class MessageEnd {
@GET
@Path("/getvalue/{word}")
@Produces(MediaType.TEXT_PLAIN)
public Response sayHello(@PathParam("word") String word){
String output = " Count of word " + word;
return Response.status(200).entity(output).build();
}
@PUT
@Path("/sendvalue/{msg}")
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public Response sendMsg(@PathParam("msg") String msg){
String output = "Received message= " + msg;
return Response.status(200).entity(output).build();
}
}
FYI, @GET
is working fine.
I am using following URI:
http://localhost:8080/message/jersey/sendvalue/hi
You browser only sends GET
requests when you type anything in the address bar. You can learn the difference between HTTP methods here: http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods
You should use proper REST client in order to create PUT
requests. The one I'm using and which is pretty good is Postman extension for Chrome: link
The reason for the error above is that you're trying to send GET
request to /sendvalue and there is nothing mapped for this method/path pair.
Even I was goofing up, using a browser to send POST request! You can use POSTMAN chrome client to test your POST requests. (For that matter you can use POSTMAN for all the http methods)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.