官方文档 http://cxf.apache.org/docs/jaxrs-services-description.html
举例:
package cn.zno; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; import org.apache.cxf.jaxrs.model.wadl.Description; import org.apache.cxf.jaxrs.model.wadl.DocTarget; @Path("/c") @Description(value = "Resource", target = DocTarget.RESOURCE) public class HelloWorld { @GET @Path("/echo/{input}") @Produces("text/plain") public String ping(@PathParam("input") String input) { return input; } @POST @Produces("application/json") @Consumes("application/json") @Path("/jsonBean") public Response modifyJson(InputBean input) { input.setVal2(input.getVal1()); return Response.ok().entity(input).build(); } }
1. cxf-2.7.6 可以自动生成wadl
2. cxf-3.1.1 不可以自动生成,需要加注解
3. request path:
http://ip:port/project name/CXF url partten?_wadl
http://ip:port/project name/CXF url partten/resource path/sub resource path?_wadl
4. 用到了json provider 和 xml provider
5. client 可以传json 或者 xml (xstream)
时间: 2024-12-08 08:41:36