[usando Apache Tomcat/7.0.27]muy peculiar: HTTP Status 405 - Método no permitido
parece que sólo se sale este error
- (HTTP Status 405 - Método no permitido)
cuando intento realizar una solicitud REST directamente desde el navegador.
por ejemplo pegando esto en la barra de direcciones:
http://localhost:8080/restExample/rest/catalog/video/14951/hello
Cuando ejecuto mi cliente de prueba Main.java todo funciona bien.
¿Alguna idea de por qué no me deja ejecutar un REST a través del navegador?
lado del cliente:
public class Main{
public static void main(String [] args){
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(getBaseURI(_package));
runPutRequest(service,"video/128/This is the content with the new description");
}
}
...
private static void runPutRequest(WebResource service,String path){
String response = service.path("rest/catalog/"+path).accept(MediaType.APPLICATION_XML).put(String.class);
System.out.println("Post Response :"+response);
}
lado del servidor:
@PUT
@Path("/video/{video-id}/{short-descr}")
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.APPLICATION_XML)
public Video updateVideo(@PathParam("video-id") int contentid,
@PathParam("short-descr") String descr)
{
//Video video = searchByContentId(contentid);
Video video = videoMap.get(contentid);
video.setDescription(descr);
videoMap.put(contentid,video);
if(videoMap.get(contentid) != null){
return videoMap.get(contentid);
}else{
throw new UnsupportedOperationException("NO object found");
}
}
Put versus Get .... – esej