-
大小: 54.14MB文件类型: .zip金币: 1下载: 0 次发布日期: 2022-05-20
- 语言: 其他
- 标签: cxf restful webservice spring
资源简介
CXF 开发RESTful WebService服务(Maven+Spring+JPA服务端,JAXRS2.0+WebClient客户端),案例多,写有注释,附赠cxf restful开发学习资料,绝对超值.欢迎大家共同交流.
代码片段和文件信息
import java.util.List;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.junit.Test;
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
import com.fndsoft.entites.User;
//使用JAXRS2.0发布REST服务
public class JAXRSClientTest {
private static final String url = “http://localhost:8080/restfulServer/ws/user“;
private static final JacksonJsonProvider jsonProvider = new JacksonJsonProvider();
@Test
public void sayHiTest() {
String result = ClientBuilder.newClient()
.target(url).path(“/sayHi“).queryParam(“name“ “呢喃北上“)
.request().get(String.class);
System.out.println(result);
}
@Test
public void queryByIdTest() {
System.out.println(“根据id查询用户“);
Client client = ClientBuilder.newClient().register(jsonProvider);// 注册json 支持
WebTarget target = client.target(url + “/queryById“).queryParam(“uno“ 2);
Invocation.Builder builder = target.request();
Response response = builder.get();
User user = response.readEntity(User.class);
System.out.println(user.getUname());
response.close();
System.out.println(“over“);
}
@Test
public void queryAllTest(){
System.out.println(“查询所有的用户“);
List users = ClientBuilder.newClient().register(jsonProvider)
.target(url).path(“/queryAll“)
.request().get(new GenericType>() {});
for (User user : users) {
System.out.println(user);
}
System.out.println(“over“);
}
@Test
public void addUserTest(){
System.out.println(“增加一位用户“);
User user = new User(0 “mokeychan“);
Client client = ClientBuilder.newClient().register(jsonProvider);
WebTarget target = client.target(url+“/addUser“);
Response response = target.request().buildPost(Entity.entity(user MediaType.APPLICATION_JSON)).invoke();
response.close();
System.out.println(“over“);
}
@Test
public void updUserTest(){
System.out.println(“更新一名用户“);
User user = new User(22“雷蒙磨咯“);
Client client = ClientBuilder.newClient().register(jsonProvider);
WebTarget target = client.target(url+“/updUser“);
Response response = target.request().buildPut(Entity.entity(user MediaType.APPLICATION_JSON)).invoke();
response.close();
queryAllTest();
System.out.println(“over“);;
}
@Test
public void delUser(){
System.out.println(“删除一名用户“);
Client client = ClientBuilder.newClient().register(jsonProvider);
WebTarget target = client.target(url+“/delUser?uno=18“);
Response response = target.request().delete();
response.close();
System.out.println(“ov
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-12-29 14:15 restful webservice\
文件 328951 2014-03-09 18:11 restful webservice\jaxrs-1.0-final-spec - 副本.pdf
目录 0 2017-12-29 14:11 restful webservice\restfulClient\
文件 920 2017-12-28 14:06 restful webservice\restfulClient\.classpath
文件 1224 2017-12-28 09:14 restful webservice\restfulClient\.project
目录 0 2017-12-29 14:11 restful webservice\restfulClient\.settings\
文件 503 2017-12-28 09:14 restful webservice\restfulClient\.settings\.jsdtscope
文件 664 2017-12-28 09:14 restful webservice\restfulClient\.settings\org.eclipse.jdt.core.prefs
文件 656 2017-12-28 09:15 restful webservice\restfulClient\.settings\org.eclipse.wst.common.component
文件 252 2017-12-28 09:14 restful webservice\restfulClient\.settings\org.eclipse.wst.common.project.facet.core.xm
文件 49 2017-12-28 09:14 restful webservice\restfulClient\.settings\org.eclipse.wst.jsdt.ui.superType.container
文件 6 2017-12-28 09:14 restful webservice\restfulClient\.settings\org.eclipse.wst.jsdt.ui.superType.name
文件 218 2017-12-28 09:13 restful webservice\restfulClient\.settings\org.maven.ide.eclipse.prefs
文件 4622 2017-12-28 16:54 restful webservice\restfulClient\pom.xm
目录 0 2017-12-29 14:11 restful webservice\restfulClient\src\
目录 0 2017-12-29 14:11 restful webservice\restfulClient\src\main\
目录 0 2017-12-28 09:15 restful webservice\restfulClient\src\main\java\
目录 0 2017-12-28 09:13 restful webservice\restfulClient\src\main\resources\
目录 0 2017-12-29 14:11 restful webservice\restfulClient\src\main\webapp\
文件 52 2017-12-28 09:13 restful webservice\restfulClient\src\main\webapp\index.jsp
目录 0 2017-12-29 14:11 restful webservice\restfulClient\src\main\webapp\me
文件 39 2017-12-28 09:14 restful webservice\restfulClient\src\main\webapp\me
目录 0 2017-12-29 14:11 restful webservice\restfulClient\src\main\webapp\WEB-INF\
文件 215 2017-12-28 09:13 restful webservice\restfulClient\src\main\webapp\WEB-INF\web.xm
目录 0 2017-12-29 14:11 restful webservice\restfulClient\src\test\
目录 0 2017-12-29 14:11 restful webservice\restfulClient\src\test\java\
文件 3115 2017-12-29 14:11 restful webservice\restfulClient\src\test\java\JAXRSClientTest.java
文件 930 2017-12-29 14:00 restful webservice\restfulClient\src\test\java\WebClientTest.java
目录 0 2017-12-29 14:11 restful webservice\restfulClient\target\
目录 0 2017-12-29 14:11 restful webservice\restfulClient\target\classes\
文件 564 2017-12-29 14:11 restful webservice\restfulClient\target\classes\JAXRSClientTest$1.class
............此处省略59个文件信息
相关资源
- 用Sping发布WebService
- WebService 简单使用(天气查询)
- Spring+SpringMVC+Mybatis CXF
- Node.js Webservice
- QT使用GSoap发布WebService的Demo
- WebService天气预报.rar
- 连接webservice数据接口,获取数据的小
- WebService应用及教程
- T100 WebService 调用传送数据说明
- 泛微OA e-cology 8 最新webservice接口文档
- 使用JSON构建WebService的
- cxf+spring+tomcat
- CXF打印SOAP报文,记录WebService日志
- springboot-cxf-webservice
- NC57下发布WEBservice方法
- Spring-Boot Rest学习
- WebService加密 for SoapHeader
- CXF实现SSL安全验证
- 使用cxf和spring开发基于https的webservi
- Delphi调用webservice
- springboot+CXF发布webservice接口
- SpringBoot集成Redis,Webservice,kafka,q
- webservice 网页实现天气预报
- WebService实现天气预报
- CXF 文件记录报文日志,非控制台打印
- SAP Webservice监控程序使用手册和常见问
- WebService调用第三方服务的案例
- WebService测试工具[WebServiceStudio]
- 调用webservice,通过post传参读取返回的
- WebService_通过工具来监控WebService请求
评论
共有 条评论