首页 > 其他分享 >CXF学习笔记(2)-HelloWorld!-客户端调用

CXF学习笔记(2)-HelloWorld!-客户端调用

时间:2023-11-09 12:07:01浏览次数:41  
标签:webservice CXF HelloWorld HelloWorldService cxf import apache org 客户端


上一节中已经成功的发布了一个服务端webservice,这一部分将默认客户端调用webservice

这里我们重新建立了一个新的工程CXF-Client,把上一节中列举的jar包都搞过来即可,调用方式采用了和RMI类似的机制,即客户端直接服务器端提供的服务接口(interface),CXF通过运行时代理生成远程服务的代理对象,在客户端完成对webservice的访问

几个必填的字段:setAddress-这个就是我们发布webservice时候的地址,保持一致

HelloWorldService:需要服务器端提供单独的Jar文件过来




1. package com.crazycoder2010.webservice.cxf.client;  
2.   
3. import org.apache.cxf.interceptor.LoggingInInterceptor;  
4. import org.apache.cxf.interceptor.LoggingOutInterceptor;  
5. import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;  
6.   
7. import com.crazycoder2010.webservice.cxf.server.HelloWorldService;  
8.   
9. public class Client {  
10. public static void main(String[] args) {  
11. new JaxWsProxyFactoryBean();  
12. new LoggingInInterceptor());  
13. new LoggingOutInterceptor());  
14. class);  
15. "http://localhost:9090/helloWorldService");  
16.         HelloWorldService helloWorldService = (HelloWorldService)bean.create();  
17. "Kevin");  
18.         System.out.println(result);  
19.     }  
20. }



运行输出:



1. 2011-8-9 21:32:20 org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass  
2. 信息: Creating Service {http://server.cxf.webservice.crazycoder2010.com/}HelloWorldServiceService from class com.crazycoder2010.webservice.cxf.server.HelloWorldService  
3. 2011-8-9 21:32:41 org.apache.cxf.interceptor.AbstractLoggingInterceptor log  
4. 信息: Inbound Message  
5. ----------------------------  
6. ID: 1  
7. Response-Code: 200  
8. Encoding: UTF-8  
9. Content-Type: text/xml;charset="utf-8"  
10. Headers: {Content-type=[text/xml;charset="utf-8"], Transfer-encoding=[chunked]}  
11. Payload: <?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:sayHelloResponse xmlns:ns2="http://server.cxf.webservice.crazycoder2010.com/"><return>Hello Kevin</return></ns2:sayHelloResponse></S:Body></S:Envelope>  
12. --------------------------------------  
13. Hello Kevin





查看了官方的文档后,发现其实是可以实现不依赖服务器端接口来完成调用的,如下


使用JaxWsDynamicClientFactory类,只要指定服务器端wsdl文件的位置,然后指定要调用的方法和方法的参数即可,so simple!!

1. package com.crazycoder2010.webservice.cxf.client;  
2.   
3. import org.apache.cxf.endpoint.Client;  
4. import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;  
5.   
6. public class Client3 {  
7. public static void main(String[] args) throws Exception {  
8.         JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();  
9. "http://localhost:9090/helloWorldService?wsdl");  
10. "sayHello", "KEVIN");  
11. 0]);  
12.     }  
13. }

标签:webservice,CXF,HelloWorld,HelloWorldService,cxf,import,apache,org,客户端
From: https://blog.51cto.com/u_809530/8274900

相关文章

  • CXF学习笔记(1)-HelloWorld!-发布webservice
    1.apache网站下载CXF http://cxf.apache.org/download.html 最新版本2.4.12.创建一个java工程,将以下jar包复制到工程的classpath下 所有的jar包都可以在${CXF_HOME}\lib目录中找到3.定义服务接口HelloWorldService因为这个接口将会被我们暴露为webservice,所以给该......
  • HttpServletRequest对象中获取客户端IP地址
    什么是HttpServletRequest对象HttpServletRequest对象是JavaServlet规范中定义的一种接口,它封装了客户端请求的所有信息,例如请求头、请求参数、请求方法、请求URL等。在JavaWeb开发中,HttpServletRequest对象非常常用,可以用来处理各种HTTP请求。获取客户端IP地址的需求在一些场景......
  • Spring整合使用RMI-HelloWorld例子
    Spring整合RMI的原理客户端的核心是RmiProxyFactoryBean,包含serviceURL属性和serviceInterface属性。通过JRMP访问服务。JRMPJRMP:javaremotemethodprotocol,Java特有的,基于流的协议。 服务端暴露远程服务RmiServiceExporter把任何Spring管理的Bean输出成一个RMI服务。通......
  • 快速定位连接oracle的客户端IP
    使用场景某些情况下,一些客户端上执行的程序性能有问题,或者程序中用户密码不对,重复登录造成用户被锁,这个时候都需要我们去定位有问题的客户端IP,然后进行处理。方案介绍一般情况下,快速定位客户端IP通畅有3种方法:创建触发器。该方法对生产系统还是有负担的,生产环境下一般不推荐,如果有......
  • js实现webSocket客户端
    var ws= new WebSocket("ws://localhost:8080/msg");//readyState属性返回实例对象的当前状态,共有四种。//CONNECTING:值为0,表示正在连接。//OPEN:值为1,表示连接成功,可以通信了。//CLOSING:值为2,表示连接正在关闭。//CLOSED:值为3,表示连接已经关闭,或者打开连接失败//例如:if......
  • 1. 客户端代码执行流程
    目录1.GIT拉取客户端代码2.tf配置文件结构2.1backend.tf配置terraform状态文件存储在哪(localAWSS3...)2.2main.tfterraform入口文件2.3provider.tf配置terraform供应商2.4terraform.tfvars以及variables.tf配置变量2.5总结1.GIT拉取客户端代码https://wwwin-......
  • TCP的通信流程和socket套接字完成服务端和客户端通信
    一、TCP是一个面向连接的、安全的、流式传输协议,这个协议是传输层协议。面向连接:是一个双向连接,通过三次握手建立连接,通过四次挥手断开连接。安全:tcp通信的过程中,会对发送的每一数据包都会进行校验,如果发现数据丢失,会自动重传。流式传输:发送端和接受端处理数据的速......
  • Redis的Java客户端
     Redis的Java客户端很多,常用的几种:JedisLettuceSpringDataRedisSpring对Redis客户端进行了整合,提供了SpringDataRedis,在SpringBoot项目中还提供了对应的Starter,即spring-boot-starter-data-redis。......
  • 客户端如何查找FTP服务器的用户名和密码
    在互联网的早期阶段,FTP(文件传输协议)是一种非常常用的技术,它允许用户在计算机之间传输文件。然而,由于网络安全和隐私的考虑,许多FTP服务器现在都使用认证系统来限制用户的访问。因此,为了连接到FTP服务器,您通常需要知道用户名和密码。这篇文章将指导您如何在客户端查找FTP服务器的用......
  • [MacOS]Ansible-HelloWorld
    安装pipinstallansible手动创建ansible.cfgsudomkdir/etc/ansible/ansible.cfg查看ansible配置信息ansible--version创建hosts文件cd/etc/ansible/sudotouchhostssudovihosts添加主机IP127.0.0.1ansible是基于ssh协议实现的,所以其配置公私......