package com.benjiaren.client;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import javax.ws.rs.core.Response;
import org.apache.cxf.jaxrs.client.WebClient;
import com.benjiaren.entity.Book;
import com.benjiaren.entity.Category;
public class CategoryServiceRESTClient {
//Put some static value
private static final String CATEGORY_URL = "http://localhost:8080/";
private static final String CATEGORY_ID = "005";
private static final String TYPE_XML = "application/xml";
private static final String TYPE_JSON = "application/json";
public static void main(String[] args) {
//System.out.println("Format is " + args[0]);
testAddCategory(TYPE_XML);
testUpdateCategory(TYPE_XML);
testGetCategory(TYPE_XML);
testAddBooksForCategory(TYPE_XML);
testGetBooksForCategory(TYPE_XML);
testDeleteCategory(TYPE_XML);
testAddCategory(TYPE_JSON);
testUpdateCategory(TYPE_JSON);
testGetCategory(TYPE_JSON);
testAddBooksForCategory(TYPE_JSON);
testGetBooksForCategory(TYPE_JSON);
testDeleteCategory(TYPE_JSON);
// if(args[0] !=null && args[0].equalsIgnoreCase(TYPE_XML)){
// //Content type- XML
// testAddCategory(TYPE_XML);
// testUpdateCategory(TYPE_XML);
// testGetCategory(TYPE_XML);
// testAddBooksForCategory(TYPE_XML);
// testGetBooksForCategory(TYPE_XML);
// testDeleteCategory(TYPE_XML);
// }
//
// if(args[0] !=null && args[0].equalsIgnoreCase(TYPE_JSON)){
// //ContentType- JSON
// testAddCategory(TYPE_JSON);
// testUpdateCategory(TYPE_JSON);
// testGetCategory(TYPE_JSON);
// testAddBooksForCategory(TYPE_JSON);
// testGetBooksForCategory(TYPE_JSON);
// testDeleteCategory(TYPE_JSON);
// }
}
private static void testAddCategory(final String format) {
System.out.println("testAddCategory called with format " + format);
WebClient client = WebClient.create(CATEGORY_URL);
client.path("/jsService/category").accept(
format).type(format);
Category cat = new Category();
cat.setCategoryId(CATEGORY_ID);
cat.setCategoryName("Fiction");
Category catResponse = client.post(cat, Category.class);
System.out.println("Category Id retreived for format " + format + " is " + catResponse.getCategoryId());
assertEquals(catResponse.getCategoryId(), CATEGORY_ID);
}
private static void testUpdateCategory(final String format) {
System.out.println("testUpdateCategory called with format " + format);
WebClient client = WebClient.create(CATEGORY_URL);
client.path("/jsService/category").accept(
format).type(format);
Category cat = new Category();
cat.setCategoryId(CATEGORY_ID);
cat.setCategoryName("Fiction Series");
Response response = client.put(cat);
System.out.println("Status retreived for update category for format " + format + " is " + response.getStatus());
assertEquals("200", String.valueOf(response.getStatus()));
}
private static void testGetCategory(final String format) {
System.out.println("testGetCategory called with format " + format);
WebClient client = WebClient.create(CATEGORY_URL);
Category category = client.path("/jsService/category/" + CATEGORY_ID).accept(
format).type(format).get(Category.class);
System.out.println("Category details retreived from service with format " + format);
System.out.println("Category Name " + category.getCategoryName());
System.out.println("Category Id " + category.getCategoryId());
assertEquals(CATEGORY_ID, category.getCategoryId());
}
private static void testAddBooksForCategory(final String format) {
System.out.println("testAddBooksForCategory called with format " + format);
WebClient client = WebClient.create(CATEGORY_URL);
client.path("/jsService/category/book").type(format).
accept(format);
Category cat = new Category();
cat.setCategoryId(CATEGORY_ID);
cat.setCategoryName("Fiction Series");
Book book1 = new Book();
book1.setAuthor("Naveen Balani");
book1.setBookid("NB001");
book1.setBookISBNnumber("ISBNB001");
book1.setBookName("Fiction Book1");
Collection<Book> booksList = new ArrayList<Book>();
booksList.add(book1);
cat.setBooks(booksList);
client.post(cat, Category.class);
}
private static void testGetBooksForCategory(final String format) {
System.out.println("testGetBooksForCategory called with format " + format);
WebClient clientBook = WebClient.create(CATEGORY_URL);
Category categoryBooks = clientBook.path(
"/jsService/category/" + CATEGORY_ID + "/books").type(format).accept(format).get(Category.class);
System.out.println("Book details retreived from service with format " + format);
assertEquals(String.valueOf(categoryBooks.getBooks().size()), "1");
Iterator<Book> iterator = categoryBooks.getBooks().iterator();
while (iterator.hasNext()) {
Book book = iterator.next();
System.out.println("Book Name " + book.getBookName());
System.out.println("Book ISBN " + book.getBookISBNnumber());
System.out.println("Book ID " + book.getBookid());
System.out.println("Book Author " + book.getAuthor());
}
}
private static void testDeleteCategory(final String format) {
System.out.println("testDeleteCategory called with format " + format);
WebClient client = WebClient.create(CATEGORY_URL);
client.path("/jsService/category/" + CATEGORY_ID).type(format).
accept(format);
Response response = client.delete();
System.out.println("Status retreived for delete category for format " + format + " is " + response.getStatus());
assertEquals("200", String.valueOf(response.getStatus()));
}
private static void assertEquals(String expected, String result) {
if (!expected.equalsIgnoreCase(result)) {
throw new RuntimeException("Expecte value " + expected + ", Got value" + result);
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
webService-cxf-demo
共129个文件
jar:78个
java:19个
class:19个
5星 · 超过95%的资源 需积分: 3 21 下载量 74 浏览量
2013-10-18
17:32:48
上传
评论
收藏 28.12MB RAR 举报
温馨提示
webservice-cxf里面实现了网上写的一些代码,打包,可以直接作为demo使用
资源推荐
资源详情
资源评论
收起资源包目录
webService-cxf-demo (129个子文件)
CategoryServiceRESTClient.class 6KB
CategoryService.class 4KB
ComplexUserService.class 4KB
ComplexUserServiceClient.class 3KB
CategoryDAO.class 3KB
MessageInterceptor.class 2KB
ServiceMessageInterceperClient.class 2KB
DeployInterCeptorService.class 2KB
Users.class 2KB
User.class 1KB
Category.class 1KB
DeployHelloWorldService.class 1KB
HelloWorldServiceClient.class 1KB
Book.class 1KB
DeployComplexUserService.class 1KB
HelloWorldService.class 1KB
DeployUtils.class 771B
IComplexUserService.class 736B
IHelloWorldService.class 349B
.classpath 7KB
org.eclipse.wst.jsdt.ui.superType.container 49B
cxf-2.7.7.jar 6.75MB
xmlbeans-2.6.0.jar 2.6MB
jaxb-xjc-2.2.6.jar 1.98MB
opensaml-2.5.1-1.jar 1.29MB
ehcache-core-2.5.1.jar 1.17MB
activemq-client-5.8.0.jar 1.09MB
jaxb-impl-2.2.6.jar 1.06MB
activemq-broker-5.8.0.jar 937KB
js-1.7R2.jar 851KB
msv-core-2011.1.jar 666KB
spring-context-3.0.7.RELEASE.jar 655KB
mina-core-2.0.7.jar 630KB
xmlsec-1.5.5.jar 624KB
xmltooling-1.3.2-1.jar 597KB
activemq-openwire-legacy-5.8.0.jar 574KB
commons-collections-3.2.1.jar 562KB
openws-1.4.2-1.jar 552KB
spring-beans-3.0.7.RELEASE.jar 544KB
joda-time-1.6.2.jar 530KB
woodstox-core-asl-4.2.0.jar 471KB
velocity-1.7.jar 439KB
antlr-2.7.7.jar 435KB
wss4j-1.6.12.jar 430KB
httpclient-4.2.5.jar 423KB
spring-web-3.0.7.RELEASE.jar 389KB
spring-core-3.0.7.RELEASE.jar 375KB
jetty-server-8.1.12.v20130726.jar 346KB
spring-aop-3.0.7.RELEASE.jar 314KB
FastInfoset-1.2.12.jar 287KB
httpcore-nio-4.2.4.jar 283KB
jetty-util-8.1.12.v20130726.jar 281KB
commons-lang-2.6.jar 278KB
commons-codec-1.7.jar 254KB
cxf-services-sts-core-2.7.7.jar 240KB
cxf-services-wsn-api-2.7.7.jar 228KB
spring-tx-3.0.7.RELEASE.jar 227KB
xsdlib-2010.1.jar 224KB
httpcore-4.2.4.jar 222KB
geronimo-javamail_1.4_spec-1.7.1.jar 218KB
isorelax-20030108.jar 188KB
wsdl4j-1.6.3.jar 182KB
spring-jms-3.0.7.RELEASE.jar 181KB
stax2-api-3.1.1.jar 178KB
spring-expression-3.0.7.RELEASE.jar 166KB
xmlschema-core-2.0.3.jar 159KB
javax.ws.rs-api-2.0-m10.jar 108KB
jetty-io-8.1.12.v20130726.jar 102KB
jaxb-api-2.2.6.jar 97KB
geronimo-servlet_3.0_spec-1.0.jar 94KB
jetty-http-8.1.12.v20130726.jar 94KB
jetty-security-8.1.12.v20130726.jar 88KB
xml-resolver-1.2.jar 82KB
httpasyncclient-4.0-beta3.jar 80KB
jettison-1.3.4.jar 80KB
neethi-3.0.2.jar 70KB
cxf-services-ws-discovery-api-2.7.7.jar 61KB
cxf-services-wsn-core-2.7.7.jar 60KB
commons-logging-1.1.1.jar 59KB
geronimo-jaxws_2.2_spec-1.1.jar 59KB
spring-asm-3.0.7.RELEASE.jar 52KB
hawtbuf-1.9.jar 49KB
oauth-20100527.jar 43KB
asm-3.3.1.jar 43KB
geronimo-jms_1.1_spec-1.1.1.jar 32KB
slf4j-api-1.7.5.jar 25KB
jetty-continuation-8.1.12.v20130726.jar 21KB
geronimo-j2ee-management_1.1_spec-1.0.1.jar 20KB
relaxngDatatype-20020414.jar 19KB
cxf-xjc-dv-2.6.2.jar 15KB
cxf-manifest.jar 14KB
cxf-xjc-boolean-2.6.2.jar 14KB
cxf-xjc-ts-2.6.2.jar 12KB
oauth-provider-20100527.jar 11KB
cxf-xjc-runtime-2.6.2.jar 11KB
cxf-xjc-bug671-2.6.2.jar 11KB
cxf-services-ws-discovery-service-2.7.7.jar 10KB
slf4j-jdk14-1.7.5.jar 8KB
aopalliance-1.0.jar 4KB
CategoryServiceRESTClient.java 7KB
共 129 条
- 1
- 2
资源评论
- ZhuYouming2013-10-22非常不错,至少可以跑起来,我花了那么多积分却没下到好的资源,才知道网上打酱油的人真多。
- luyantongqq2014-03-25个人跑不起来。。代码一班,能看懂
- kangaroo_tu2013-11-25正在找CXF的资料,下来看看,希望有用
- jslfl2013-11-20正在找CXF的资料,下来看看,希望有用
benjiaxiaoxu
- 粉丝: 8
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 解决未在远程桌面会话中捕获到鼠标,vmguest.iso软件分享给大家
- JSP+SQL基于WEB的开放性实验管理系统设计与实现(源代码+论文+开题报告+中英文献+答辩PPT).rar
- log4net配置文件!!!!!!!!!!!!!!!!!
- 河南统计面板数据集(2010-2022年).xlsx
- OrcaleDBHelper帮助类!!!!!!!!!!!!
- log4net帮助类,用来写日志!!!!!!!!!!!!!
- Windows10时间同步源
- 信呼OA系统2.1.7版源码
- 3122080306 邹子轩 实验报告二.docx
- 基于STM32 NUCLEO板设计彩色LED照明灯(纯cubeMX开发)(大赛作品,文档完整,可直接运行)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功