1.sample 实例之一---java_first_pojo

服务端发布服务的方法:

1         HelloWorldImpl helloworldImpl = new HelloWorldImpl();
//cxf发布服务的工厂bean
2 ServerFactoryBean svrFactory = new ServerFactoryBean();
     //设置服务类
3 svrFactory.setServiceClass(HelloWorld.class);
     //设置服务地址
4 svrFactory.setAddress("http://localhost:9000/Hello");
     //设置服务bean
5 svrFactory.setServiceBean(helloworldImpl);
6 svrFactory.create();

客户度调用的方法:

//创建服务代理工程bean
ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
//设置服务代理地址
factory.setAddress("http://localhost:9000/Hello");
//创建代理服务
HelloWorld client = factory.create(HelloWorld.class);
//调用代理服务
System.out.println(client.sayHi(System.getProperty("user.name")));

2 sample实例之二---java_first_jaxws

服务端发布服务的方法:

1         HelloWorldImpl implementor = new HelloWorldImpl();
2 String address = "http://localhost:9000/helloWorld";
3 Endpoint.publish(address, implementor);

客户端调用的方法:

 

 private static final QName SERVICE_NAME  = new QName("http://server.hw.demo/", "HelloWorld");
private static final QName PORT_NAME = new QName("http://server.hw.demo/", "HelloWorldPort");
Service service = Service.create(SERVICE_NAME);
// Endpoint Address
String endpointAddress = "http://localhost:9000/helloWorld";
// If web service deployed on Tomcat deployment, endpoint should be changed to:
// String endpointAddress = "http://localhost:8080/java_first_jaxws/services/hello_world"; // Add a port to the Service
service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress); HelloWorld hw = service.getPort(HelloWorld.class);

3 sample实例之---java_first_jaxws_factory_bean

服务端发布服务的方法:

1         HelloWorldImpl implementor = new HelloWorldImpl();
2 JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
3 svrFactory.setServiceClass(HelloWorld.class);
4 svrFactory.setAddress("http://localhost:9000/helloWorld");
5 svrFactory.setServiceBean(implementor);
6 svrFactory.getInInterceptors().add(new LoggingInInterceptor());
7 svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());
8 svrFactory.create();

 客户端调用的方法:

1         JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
2 factory.getInInterceptors().add(new LoggingInInterceptor());
3 factory.getOutInterceptors().add(new LoggingOutInterceptor());
4 factory.setAddress("http://localhost:9000/helloWorld");
5 HelloWorld client = factory.create(HelloWorld.class);
6 System.out.println(client.sayHi("World"));

  4.sample实例之一---java_first_spring_support

 服务端发布服务

1         /**
2 * Important: This code simply starts up a servlet container and adds
3 * the web application in src/webapp to it. Normally you would be using
4 * Jetty or Tomcat and have the webapp packaged as a WAR. This is simply
5 * as a convenience so you do not need to configure your servlet
6 * container to see CXF in action!
7 */
8 org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server();
9
10 SelectChannelConnector connector = new SelectChannelConnector();
11 connector.setPort(9002);
12 server.setConnectors(new Connector[] {connector});
13
14 WebAppContext webappcontext = new WebAppContext();
15 webappcontext.setContextPath("/");
16
17 webappcontext.setWar("target/JavaFirstSpringSupport.war");
18
19 HandlerCollection handlers = new HandlerCollection();
20 handlers.setHandlers(new Handler[] {webappcontext, new DefaultHandler()});
21
22 server.setHandler(handlers);
23 server.start();
24 System.out.println("Server ready...");
25 server.join();

  客户度调用服务:

1         ClassPathXmlApplicationContext context
2 = new ClassPathXmlApplicationContext(new String[] {"client-beans.xml"});
3
4 HelloWorld client = (HelloWorld)context.getBean("client");
5
6 String response = client.sayHi("Joe");

  客户度调用小结

  (引用http://blog.csdn.net/liaomin416100569/article/details/5503410)

 

1   UserServiceImplService serivce = new UserServiceImplService();
2 UserServiceImpl impl = serivce.getUserServiceImplPort();

  

1   JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
2 factory.setAddress("http://localhost:8088/abc");
3 QName SERVICE = new QName("http://liaomin", "UserServiceImplService");
4 factory.setServiceName(SERVICE);
5 factory.setServiceClass(UserService.class);
6 UserService us = (UserService) factory.create();

  

1      QName SERVICE = new QName("http://liaomin", "UserServiceImplService");
2 QName UserServiceImplPort = new QName("http://liaomin", "UserServiceImplPort");
3 URL url = new URL("http://localhost:8088/abc?wsdl");
4 ServiceDelegate dele=Provider.provider().createServiceDelegate(url,SERVICE,Service.class);
5 UserService us = (UserService) dele.getPort(UserServiceImplPort,UserService.class);

  

1   ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
2 factory.setServiceClass(UserService.class);
3 factory.setAddress("http://localhost:8088/abc");
4 // factory.getServiceFactory().setDataBinding(new AegisDatabinding());
5 UserService client = (UserService) factory.create();

  

  

  

cxf 实例解读的更多相关文章

  1. cxf实例异常

    基于CXF2.3.0 Caused by: java.lang.InstantiationException: org.apache.cxf.wstx_msv_validation.WoodstoxV ...

  2. 实例解读丨关于GaussDB ETCD服务异常

    摘要:本文通过对ETCD服务异常问题分析,代码展示解决方案. 本文分享自华为云社区<[实例状态]GaussDB ETCD服务异常>,作者:酷哥. 首先确认是否是虚拟机.网络故障 虚拟机故障 ...

  3. Java中Websocket使用实例解读

    介绍 现在很多网站为了实现即时通讯,所用的技术都是轮询(polling).轮询是在特定的的时间间隔(如每1秒),由浏览器对服务器发出HTTP request,然后由服务器返回最新的数据给客服端的浏览器 ...

  4. Unity3d-AngryBots实例解读

    最近粗略研究了下Unity3d自带的例子AngryBots,记录一下,部分内容摘自http://oulehui.blog.163.com/blog/static/7961469820125251051 ...

  5. Golang 并发Groutine实例解读(二)

    go提供了sync包和channel机制来解决协程间的同步与通信. 一.sync.WaitGroup sync包中的WaitGroup实现了一个类似任务队列的结构,你可以向队列中加入任务,任务完成后就 ...

  6. Golang 并发Groutine实例解读(一)

    Go语言的并发和并行 不知道你有没有注意到一个现象,还是这段代码,如果我跑在两个goroutines里面的话: var quit chan int = make(chan int) func loop ...

  7. 实例解读什么是Redis缓存穿透、缓存雪崩和缓存击穿

    from:https://baijiahao.baidu.com/s?id=1619572269435584821&wfr=spider&for=pc Redis缓存的使用,极大的提升 ...

  8. wordpress时间函数the_time() 实例解读

    wordpress the_time()时间函数想必大家多多少少都会用到,但是要自定义一些时间相对没那么熟悉了,随ytkah一起来看看吧.我们知道时间函数基础调用是<?php the_time( ...

  9. 使用CXF做简单的WebService例子

    使用Maven搭建项目测试简单的CXF实例 Server: pom.xml: <!-- begin CXF Server --> <dependency> <groupI ...

随机推荐

  1. QT笔记 -- (6) opengl

    参考 http://blog.csdn.net/myths_0/article/details/24431597 用glut绘制一个茶壶 一句话,继承QGLWidget,实现下面三个函数,用子类定义窗 ...

  2. POJ 1990 MooFest【 树状数组 】

    题意:给出n头牛,每头牛有一个听力v,坐标x,两头牛之间的能量为max(v1,v2)*dist(v1,v2),求总的能量值 先将每头牛按照v排序,排完顺序之后,会发现有坐标比当前的x小的,会有坐标比当 ...

  3. input[type="file"]的图片预览

    在项目中遇到用input标签file类型的文件上传,想实在上传之前进行图片的预览功能:之前的做的一个解决方案是文件先上传上去然后返回地址再显示在页面上,这样就不太好,因为用户基本信息可能并没有保存,但 ...

  4. 《Unix环境高级编程》读书笔记 第3章-文件I/O

    1. 引言 Unix系统的大多数文件I/O只需用到5个函数:open.read.write.lseek以及close 本章描述的函数经常被称为不带缓冲的I/O.术语不带缓冲指的是在用户的进程中对其不会 ...

  5. 路飞学城Python-Day7(practise)

    # 1.编码问题# i.请说明python2与python3中的默认编码是什么?# python2中的默认编码是ASCII码,只能识别英文等其他字符# python3中的默认编码是utf-8# ii. ...

  6. Mean, Median, Mode, Range, and Standard Deviation

    Descriptive statistics tell you about the distribution of data points in data set. The most common m ...

  7. linux操作---cd

    cd命令用于切换工作路径,格式是cd [选项][参数]: [选项] -p  如果切换的工作目录是一个符号连接,直接切换到符号连接指向的目标目录: -L  如果切换的工作目录是一个符号连接,直接切换到符 ...

  8. 今天遇到的一个诡异的core和解决 std::sort

    其实昨天开发pds,就碰到了core,我还以为是内存不够的问题,或者其他问题. 今天把所有代码挪到了as这里,没想到又出core了. 根据直觉,我就觉得可能是std::sort这边的问题. 上网一搜, ...

  9. GBK编码具体解析(附GBK码位分布图)

    1.GBK码位分布图 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA= ...

  10. UVA 11825 - Hackers&#39; Crackdown 状态压缩 dp 枚举子集

    UVA 11825 - Hackers' Crackdown 状态压缩 dp 枚举子集 ACM 题目地址:option=com_onlinejudge&Itemid=8&page=sh ...