CXF中的拦截器分为in拦截器和out拦截器,又有客户端拦截器和服务端拦截器。
拦截器使用流程:客户端(out)-> 服务端(in)->处理业务->服务端(out)->客户端(in),并不是每一步都需要拦截器。在这里我们用到的是客户端Out拦截器和服务端in拦截器。服务端in拦截器检查用户级权限,客户端out浏览器发送用户信息给服务端。
1、创建服务端验证
JaxWsServerfactorybean或Endpoint都可以通过getininterceptors方法,向WebService服务添加拦截器。
1.1 Endpoint方式
1.2 JaxWsServerfactorybean 方式
- HelloWorldServiceImpl impl = JaxWsServerfactorybean factory = new JaxWsServerfactorybean();
- factory.setAddress("http://localhost:8080/hello");
- factory.setServiceClass(HelloWorldService.class);
- factory.setServiceBean(impl);
- factory.getininterceptors().add(new AuthInterceptor());
- factory.create();