设为首页 收藏本站
查看: 715|回复: 0

[经验分享] cxf 实例解读

[复制链接]

尚未签到

发表于 2017-2-28 08:47:01 | 显示全部楼层 |阅读模式
  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();

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-348178-1-1.html 上篇帖子: 常用的web服务器 下篇帖子: Running Solr with Maven
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表