a263482604 2016-05-12 03:48 采纳率: 0%
浏览 4163

cxf restful 错误 HTTP 405 Method Not Allowed

初次使用cxf+restful 遇到错误 javax.ws.rs.ClientErrorException: HTTP 405 Method Not Allowed,有谁帮忙看看

测试的客户端和服务端的类:
public class MyClient {

public static void main(String[] args) throws Exception {  
    //go("http://localhost:9000/ws/jaxrs/customer/1/info");  
    //go("http://localhost:9000/ws/jaxrs/customer/search?name=abc");  
    //go("http://localhost:9000/ws/jaxrs");  
    //go("http://localhost:9000/ws/jaxrs/customer/search?name=abc"); 
    go1("http://localhost:9000/ws/jaxrs");  
}  

private static void go(String url) throws Exception { 
    /* String result = WebClient.create(url)
                .path("/sample/map")
                .query("name", "world")
                .get(String.class);
            System.out.println(result);*/
    //room, Room.class
    RequestParam s = new RequestParam();
    Response c=WebClient.create(url).path("/sample/map").post(s);
    System.out.println(c);
        }}
        ---------------
        public class MyServer {  
public static void main(String[] args) throws Exception {  
    /*JAXRSServerFactoryBean factoryBean = new JAXRSServerFactoryBean();  
    factoryBean.getInInterceptors().add(new LoggingInInterceptor());  
    factoryBean.getOutInterceptors().add(new LoggingOutInterceptor());  
    factoryBean.setResourceClasses(CustomerServiceImpl.class);  
    factoryBean.setAddress("http://localhost:9000/ws/jaxrs");  
    factoryBean.create();*/  
    JAXRSServerFactoryBean factoryBean = new JAXRSServerFactoryBean();
    factoryBean.setResourceClasses(ResponseService.class);
    factoryBean.setAddress("http://localhost:9000/ws/jaxrs"); 
    factoryBean.create();
}  

}

用到的类:MapBean.class 、ResponseResult.class、ResponseResults.class、IResponseService.class、ResponseService.class
@Path(value = "/sample")
public class ResponseService implements IResponseService{

@Context
private UriInfo uriInfo;

@Context
private Request request;

@POST
@Path("/map")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public MapBean getMap(RequestParam requestParam) {
    System.out.println("####getMap#####");
    System.out.println("Method:" + request.getMethod());
    System.out.println("uri:" + uriInfo.getPath());
    System.out.println(uriInfo.getPathParameters());

    Map<String, ResponseResult> map = new HashMap<String, ResponseResult>();
    List<ResponseResult> list = new ArrayList<ResponseResult>();
    ResponseResult responseResult = null;
    for (int i = 0; i < 4;i ++) {
        responseResult = new ResponseResult();
        responseResult = new ResponseResult();
        responseResult.setId(i+"");
        responseResult.setName("JojO-" + i);
        map.put("key-" + i, responseResult);
        list.add(responseResult);
    }
    /*responseResult = new ResponseResult();
    responseResult.setId(i);
    responseResult.setName("JojO-" + i);*/
    MapBean bean = new MapBean();
    bean.setMap(map);
    bean.setResponseResults(list);
    bean.setCode("code");
    bean.setDesc("desc");
    bean.setErrorCode("error");
    bean.setErrorMsg("msg");
    return bean;
}

}

@Path(value = "/sample")
public interface IResponseService {

@POST
@Path("/map")
@Consumes({"application/json","application/xml"})  
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public MapBean getMap(RequestParam requestParam);

}

@XmlRootElement(name="MapBean")
public class MapBean {

private String code;
private String desc;
private String errorCode;
private String errorMsg;

private Map<String, ResponseResult> map;

private List<ResponseResult> responseResults;
}
--------------
@XmlRootElement(name="ResponseResults")

public class ResponseResults {
private List responseResults;
}
-------------
@XmlRootElement(name="ResponseResult")
public class ResponseResult {
private String id;
private String name;
}

  • 写回答

2条回答 默认 最新

  • Robot-C 2016-05-12 03:52
    关注

        今天在调试一个ASP.Net 程序的时候出现了题目中的错误,具体提示如下图:

        因为是初学者,对给出的原因提示还不是很懂,在网上找了大半晌的解决方案竟是一些同样问题却没有答案的。后来看到一张图片的提示,然后联想上图中的提示,自己去IIS管理器中瞎鼓捣最终竟然解决了。然后总结了一下,最大的原因就在于HTTP谓词。所谓......
    答案就在这里:HTTP错误405-Method Not Allowed
    ----------------------你好,人类,我是来自CSDN星球的问答机器人小C,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。

    评论

报告相同问题?

悬赏问题

  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了
  • ¥15 电脑最近经常蓝屏,求大家看看哪的问题
  • ¥60 高价有偿求java辅导。工程量较大,价格你定,联系确定辅导后将采纳你的答案。希望能给出完整详细代码,并能解释回答我关于代码的疑问疑问,代码要求如下,联系我会发文档
  • ¥50 C++五子棋AI程序编写
  • ¥30 求安卓设备利用一个typeC接口,同时实现向pc一边投屏一边上传数据的解决方案。