日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

cxf 实例解读

發布時間:2025/4/5 编程问答 13 豆豆
生活随笔 收集整理的這篇文章主要介紹了 cxf 实例解读 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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 AddressString 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();

?

?

轉載于:https://www.cnblogs.com/davidwang456/archive/2013/03/17/2964084.html

總結

以上是生活随笔為你收集整理的cxf 实例解读的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。