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 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问