[mit Apache Tomcat/7.0.27]Sehr eigentümlich: HTTP-Status 405 - Methode nicht erlaubt
Es scheint nur ich diesen Fehler
- (HTTP-Status 405 - Methode nicht erlaubt)
wenn ich versuche, eine REST-Anfrage direkt aus dem Browser zu machen.
Z. B durch das Einfügen in die Adressleiste:
http://localhost:8080/restExample/rest/catalog/video/14951/hello
Wenn ich meinen Test-Client laufen Main.java alles funktioniert.
Irgendwelche Ideen, warum es mich nicht erlaubt, einen REST durch den Browser auszuführen?
Client Side:
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);
}
Server-Seite:
@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 vs Get .... – esej