参考文档

http://cxf.apache.org/docs/jaxrs-services-description.html

获取项目

git@github.com:witaste/cxf-2.7.6-server-client-wadl.git

说明:

2.7.6 生成了简单的wadl, 不能生成所需的bean?可以。关键点在@XmlRootElement

注意不适用于3.1.1

package cn.zno.pojo;

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class News {
    
    private String title;
    
    private String content;

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }
    
}

 

指定服务器可以处理的类型

    @POST
    @Path("/requestNews")
    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
    @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
    public News requestNews(Param param);

 

具体发送接收类型需要客户端自己指定

        // 创建客户端
        WebClient client = WebClient
                .create("http://localhost:8080/wadl/news/requestNews", provider)
                .accept("application/json")
                .type("application/json");

 

provider 有 json 和 xml 两种

        <jaxrs:providers>
            <bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
            <bean class="org.apache.cxf.jaxrs.provider.JAXBElementProvider" />
        </jaxrs:providers>

 

通过wadl生成bean。在client文件夹下执行wadl2java.bat 参数是wadl地址

E:\client>%CXF_HOME%\bin\wadl2java http://localhost:8080/wadl?_wadl

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2021-11-29
  • 2022-02-14
  • 2022-12-23
猜你喜欢
  • 2021-06-28
  • 2021-08-17
  • 2021-11-22
  • 2021-12-27
  • 2021-11-04
  • 2021-12-08
  • 2022-12-23
相关资源
相似解决方案