WebService学习笔记-CXF添加拦截器
发布时间:2020-12-16 23:19:13 所属栏目:安全 来源:网络整理
导读:Webservice拦截器:在webservice请求过程中,动态操作请求和响应的数据 分类 按照所处的位置分:服务器端拦截器 ?客户端拦截器 按照消息的方向分:入拦截器 ?出拦截器 按照定义者分:系统拦截器 自定义拦截器? 在服务器端添加拦截器 package?com.demo;//注意
Webservice拦截器:在webservice请求过程中,动态操作请求和响应的数据 分类 按照所处的位置分:服务器端拦截器 ?客户端拦截器 按照消息的方向分:入拦截器 ?出拦截器 按照定义者分:系统拦截器 自定义拦截器? 在服务器端添加拦截器 package?com.demo; //注意引入的类一定要正确 import?javax.xml.ws.Endpoint; import?org.apache.cxf.interceptor.LoggingInInterceptor; import?org.apache.cxf.jaxws.EndpointImpl; public?class?webServiceApp?{ public?static?void?main(String[]?args)?{ System.out.println("Starting?web?service...?"); HelloWorldImpl?implementor?=?new?HelloWorldImpl(); String?address?=?"http://localhost:8080/helloWorld"; Endpoint?endpoint?=?Endpoint.publish(address,?implementor); //?jaxws?API?转到?cxf?API?添加日志拦截器 EndpointImpl?jaxwsEndpointImpl?=?(EndpointImpl)?endpoint; org.apache.cxf.endpoint.Server?server?=?jaxwsEndpointImpl.getServer(); org.apache.cxf.endpoint.Endpoint?cxfEndpoint?=?server.getEndpoint(); LoggingInInterceptor?logging?=?new?LoggingInInterceptor(); cxfEndpoint.getInInterceptors().add(logging); System.out.println("Web?service?started"); } } 客户端 package?com.demo.client; import?org.apache.cxf.interceptor.LoggingOutInterceptor; import?org.apache.cxf.jaxws.JaxWsProxyFactoryBean; import?com.demo.HelloWorld; import?com.demo.User; //参考http://blog.csdn.net/fhd001/article/details/5778915 public?class?HelloWorldClient?{ public?static?void?main(String[]?args)?{ JaxWsProxyFactoryBean?svr?=?new?JaxWsProxyFactoryBean(); svr.setServiceClass(HelloWorld.class); svr.setAddress("http://localhost:8080/helloWorld"); HelloWorld?hw?=?(HelloWorld)?svr.create(); //?jaxws?API?转到?cxf?API?添加日志拦截器 org.apache.cxf.endpoint.Client?client?=?org.apache.cxf.frontend.ClientProxy .getClient(hw); org.apache.cxf.endpoint.Endpoint?cxfEndpoint?=?client.getEndpoint(); LoggingOutInterceptor?logging?=?new?LoggingOutInterceptor(); cxfEndpoint.getOutInterceptors().add(logging); User?user?=?new?User(); user.setUsername("Umgsai"); user.setDescription("test"); System.out.println(hw.sayHiToUser(user)); String?sayHi?=?hw.sayHi("test~~~"); System.out.println(sayHi); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- angularjs – 提供范围的$destroy事件的示例?
- Scala:找到类型不匹配,需要单位:布尔值
- Ngrx angular 2我应该如何设置初始状态?
- 如何在shell中运行python程序而不键入“python”
- Shell命令行执行SQL语句
- Yum安装LAMP(Centos7.2+Apache2.4+Mariadb5.5.56+PHP7.0.24
- Angular cookies cookieStore
- angularjs – heroku错误:ENOENT,stat’/app/build/index.
- angular开发中问题记录--启动过程初探
- AngularJS 学习笔记(2)-MVC,$scope,$watch