最新webservice(3):CXF拦截器介绍及自定义拦截器实现(1),web项目二次开发

自学几个月前端,为什么感觉什么都没学到??


这种现象在很多的初学者和自学前端的同学中是比较的常见的。

因为自学走的弯路是比较的多的,会踩很多的坑,学习的过程中是比较的迷茫的。

最重要的是,在学习的过程中,不知道每个部分该学哪些知识点,学到什么程度才算好,学了能做什么。

很多自学的朋友往往都是自己去找资料学习的,资料上有的或许就学到了,资料上没有的或许就没有学到。

这就会给人一个错误的信息就是,我把资料上的学完了,估计也-就差不多的了。

但是真的是这样的吗?非也,因为很多人找的资料就是很基础的。学完了也就是掌握一点基础的东西。分享给你一份前端分析路线,你可以参考。

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

还有很多的同学在学习的过程中一味的追求学的速度,很快速的刷视频,写了后面忘了前面,最后什么都没有学到,什么都知道,但是什么都不懂,要具体说,也说不出个所以然。

所以学习编程一定要注重实践操作,练习敲代码的时间一定要多余看视频的时间。

<jaxrs:server id=“restServiceContainer” address=“/cxf”>

jaxrs:inInterceptors

</jaxrs:inInterceptors>

jaxrs:outInterceptors

</jaxrs:outInterceptors>

jaxrs:serviceBeans

</jaxrs:serviceBeans>

</jaxrs:server>

复制代码

API方式:

复制代码

JAXRSServerFactoryBean jrf = new JAXRSServerFactoryBean();

jrf.setResourceClasses(RestServiceImpl.class);

jrf.setResourceProvider(RestServiceImpl.class, new SingletonResourceProvider(new RestServiceImpl()));

jrf.setAddress(url);

jrf.getInInterceptors().add(new LoggingInInterceptor());

jrf.getOutInterceptors().add(new LoggingOutInterceptor());

jrf.create();

复制代码

客户端配置方式:

复制代码

JAXRSClientFactoryBean factory = new JAXRSClientFactoryBean();

factory.setServiceClass(RestService.class);

factory.setAddress(url);

factory.getInInterceptors().add(new LoggingInInterceptor());

factory.getOutInterceptors().add(new LoggingOutInterceptor());

RestService ser = factory.create(RestService.class);

ser.get();

复制代码

输出日志形式如下:客户端:

复制代码

[INFO ] 03-22 22:33:39 org.apache.cxf.interceptor.AbstractLoggingInterceptor.log(AbstractLoggingInterceptor.java:250) Outbound Message

---------------------------

ID: 1

Address: http://localhost:8080/webapp/ws/cxf/rest

Http-Method: GET

Content-Type: application/xml

Headers: {Content-Type=[application/xml], Accept=[text/plain]}

--------------------------------------

[INFO ] 03-22 22:33:39 org.apache.cxf.interceptor.AbstractLoggingInterceptor.log(AbstractLoggingInterceptor.java:250) Inbound Message

----------------------------

ID: 1

Response-Code: 200

Encoding: ISO-8859-1

Content-Type: text/plain

Headers: {content-type=[text/plain], Date=[Wed, 22 Mar 2017 14:33:39 GMT], transfer-encoding=[chunked]}

Payload: this is default get plain

--------------------------------------

复制代码

服务端:

复制代码

[INFO ] 03-22 22:33:39 org.apache.cxf.interceptor.AbstractLoggingInterceptor.log(AbstractLoggingInterceptor.java:250) Inbound Message

----------------------------

ID: 4

Address: http://localhost:8080/webapp/ws/cxf/rest

Encoding: UTF-8

Http-Method: GET

Content-Type: application/xml

Headers: {Accept=[text/plain], cache-control=[no-cache], connection=[keep-alive], content-type=[application/xml], host=[localhost:8080], pragma=[no-cache], user-agent=[Apache CXF 3.0.3]}

--------------------------------------

[INFO ] 03-22 22:33:39 org.apache.cxf.interceptor.AbstractLoggingInterceptor.log(AbstractLoggingInterceptor.java:250) Outbound Message

---------------------------

ID: 4

Response-Code: 200

Content-Type: text/plain

Headers: {Content-Type=[text/plain], Date=[Wed, 22 Mar 2017 14:33:39 GMT]}

Payload: this is default get plain

--------------------------------------

复制代码

自定义拦截器

CXF中也可以自定义拦截器,CXF中实现自定义拦截器需要继承AbstractPhaseInterceptor或者其子类如AbstractSoapInterceptor。

一个简单的拦截器:

复制代码

/**

* CXF 自定义拦截器

*/

public class MyInterceptor extends AbstractPhaseInterceptor{

//必需提供一个带参数的构造函数

public MyInterceptor(String phase){

super(phase);

}

//覆写拦截后的动作

@Override

public void handleMessage(Message message) throws Fault{

Q.p(“~~~~~~~~~~~~~~~~~~”);

if (message.getDestination() != null) {

Q.p(message.getDestination().getAddress());

}

if (message.getExchange() != null) {

Q.p(message.getExchange().getInMessage());

Q.p(message.getExchange().getOutMessage());

}

Q.p(message.getContent(String.class));

Q.p(“~~~~~~~~~~~~~~~~~~~”);

}

}

复制代码

分享

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

blog.csdn.net/swazer_z/article/details/72902721 “复制代码”)

分享

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值