大文件
特殊验证
日志记录
Soap消息处理
消息的压缩处理
好的,要实现的功能已经列出来了,一步步的添加.首先看基础代码,一个最简单的webservices代码如下:
接口
package com.gwtjs.web.services; import javax.jws.WebService; @WebService public interface HandlerServices { public String sendHello(String par); }
实现类:
package com.gwtjs.web.services.impl; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; import org.apache.cxf.interceptor.InInterceptors; import org.springframework.stereotype.Service; @Service("HandlerServices") @WebService( endpointInterface = "com.gwtjs.web.services.HandlerServices", name="HandlerServices", targetNamespace="http://services.gwtjs.com:8181/batis/services/", portName="HandlerServicesPort", serviceName = "HandlerServices" ) public class HandlerServicesImpl { @WebMethod public String sendHello(@WebParam String par) { return par + "-" + System.currentTimeMillis(); } }
查询下cxf的监听器,想通过监听器的方式解决切入拦截,注入一个验证类,通过ide代码提示查到可以使用InInterceptors和OutInterceptors实现输入输出监听.扩展了cxf的监听器,代码如下:
package com.gwtjs.web.service.interception; import java.util.List; import org.apache.cxf.binding.soap.SoapMessage; import org.apache.cxf.headers.Header; import org.apache.cxf.interceptor.Fault; import org.apache.cxf.phase.AbstractPhaseInterceptor; import org.apache.cxf.phase.Phase; import org.w3c.dom.Element; import org.w3c.dom.NodeList; /** * <h2><pre name="code" class="java">自定义拦截器在入口阶段实施拦截</h2><p>
@InInterceptors(interceptors={"org.apache.cxf.interceptor.LoggingInInterceptor","com.gwtjs.web.service.interception.AuthInterceptor"})
日志记录和特殊验证完成.
输出日志可以加上@OutInterceptors注解,自己扩展也行,使用LoggingOutInterceptor也行;
我的接口实现类完整的注解代码:
@Service("HandlerServices") @InInterceptors(interceptors={"org.apache.cxf.interceptor.LoggingInInterceptor","com.gwtjs.web.service.interception.AuthInterceptor"}) @OutInterceptors(classes={org.apache.cxf.interceptor.LoggingOutInterceptor.class}) @WebService( endpointInterface = "com.gwtjs.web.services.HandlerServices", name="HandlerServices", targetNamespace="http://services.gwtjs.com:8181/batis/services/", portName="HandlerServicesPort", serviceName = "HandlerServices" )