Fab*_*bii 13 java rest jaxb jersey
[使用Apache Tomcat/7.0.27]
我似乎只得到这个错误
当我尝试直接从浏览器发出REST请求时.
例如,通过在地址栏中粘贴它:
http://localhost:8080/restExample/rest/catalog/video/14951/hello
Run Code Online (Sandbox Code Playgroud)
当我运行我的测试客户端Main.java时,一切正常.
关于它为什么不让我通过浏览器执行REST的任何想法?
客户端:
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);
}
Run Code Online (Sandbox Code Playgroud)
服务器端:
@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");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
41165 次 |
| 最近记录: |