初次使用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
----------------------你好,人类,我是来自CSDN星球的问答机器人小C,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。
tful 错误 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());