cxf restful 错误 HTTP 405 Method Not Allowed

问题描述

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;
}

解决方案

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

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

时间: 2024-08-18 02:25:41

cxf restful 错误 HTTP 405 Method Not Allowed的相关文章

Nginx HTTP Post Method: 405 Method not allowed错误

最近维护一台RedHat 5.4 X64系统,环境是Nginx,跑着一个论坛,需要向HTML页面提交POST数据,结果都被拦截下来了,显示错误:"nginx 405 Not Allowed",是乎没有很好的解决办法,唯一能做的就是重新编译Nginx源码和编辑conf文件. 后来得知Apache.IIS.Nginx等绝大多数web服务器,都不允许静态文件响应POST请求,否则会返回"HTTP/1.1 405 Method not allowed"错误 需要修改Ngin

php采用curl访问域名返回405 method not allowed提示的解决方法_php技巧

/** * http测试 * 注:PHP版本5.2以上才支持CURL_IPRESOLVE_V4 * @param $url 网站域名 * @param $type 网站访问协议 * @param $ipresolve 解析方式 */ public function web_http($url,$type,$ipresolve) { //设置Header头 $header[] = "Accept: application/json"; $header[] = "Accept-E

解决php curl获取网页内容提示405 method not allowed状态码

1.php curl ipv4使用例子  代码如下 复制代码 /**  * http测试  * 注:PHP版本5.2以上才支持CURL_IPRESOLVE_V4  * @param $url 网站域名  * @param $type 网站访问协议  * @param $ipresolve 解析方式  */ public function web_http($url,$type,$ipresolve) { //设置Header头 $header[] = "Accept: application/j

使用jqgrid没有数据,前台样式也有问题,url报405(Method Not Allowed)

问题描述 使用jqgrid没有数据,前台样式也有问题,url报405(Method Not Allowed) 下面是servlet public void ajaxTriggerList(HttpServletRequest request, HttpServletResponse response) throws Exception{ List> results = this.schedulerService .getQrtzTriggers(); String page = request.

SVN 错误;: Server sent unexpected return value (405 method not allowed)

原因:上面有一个已经建立的同名文件夹了,只要删除同名中的一个就很好解决了!

cxf restful 参数中有map,调用报错,如何处理(不能二次封装map),请大神帮解一下

问题描述 cxf restful 参数中有map,调用报错,如何处理(不能二次封装map),请大神帮解一下 service代码: @GET @Path("/map") @Produces({"application/json","application/xml"}) public String mapTest(@QueryParam("map")Map map){ return "a"; } 调用代码: M

cxf +restful项目,实现一个以图片二进制流做参数的接口,接口和客户端怎么写?

问题描述 cxf +restful项目,实现一个以图片二进制流做参数的接口,接口和客户端怎么写? 以图片路径为参数的接口: @GET @Path("/vcardBean/{path}") @Produces({"application/json","application/xml"}) public VCardBean getVCardBean(@PathParam("path") String path) { //path

cxf restful webservice

问题描述 cxf restful webservice 3C 请求参数,和返回参数都是实体对像,但是发布后:请求参数解析显示: 返回参数解析显示:

cxf restful 多接口-cxf restful能否把多个接口绑定到一个address里?

问题描述 cxf restful能否把多个接口绑定到一个address里? rt,现在接口太多,有近60个,如果单个发布太麻烦了,有没有可能把多个接口绑定到一个address进行发布? 解决方案 08-一个IP绑定多个域名(根据ServerName)一个命令按钮绑定多个事件