首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

CXF2.7.4 暗藏wsdl

2014-01-05 
CXF2.7.4 隐藏wsdlpackage demo.hw.filterimport java.io.IOExceptionimport java.util.Enumerationimp

CXF2.7.4 隐藏wsdl
package demo.hw.filter;import java.io.IOException;import java.util.Enumeration;import javax.servlet.Filter;import javax.servlet.FilterChain;import javax.servlet.FilterConfig;import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.http.HttpServletRequest;import org.apache.commons.lang3.StringUtils;public class WSDLFilter implements Filter {@Overridepublic void destroy() {}@Overridepublic void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException {HttpServletRequest httpRequest = (HttpServletRequest)request;Enumeration<String> enumeration = httpRequest.getParameterNames();while (enumeration.hasMoreElements()) {String param = (String) enumeration.nextElement();// 查找是否含有参数wsdl,因为使用WSDL也可以,所以这里比较时必须不区分大小写if (StringUtils.endsWithIgnoreCase("wsdl", param)) {return;}}chain.doFilter(request, response);}@Overridepublic void init(FilterConfig arg0) throws ServletException {}}

然后配置下 filter和需要过滤的url-pattern即可

<filter> <filter-name>WSDLFilter</filter-name> <filter-class>demo.hw.filter.WSDLFilter</filter-class> </filter><filter-mapping> <filter-name>WSDLFilter</filter-name> <url-pattern>/Complex</url-pattern> </filter-mapping>

?

2、使用内置Jetty容器

这里使用JaxWsServerFactoryBean来发布服务

protected Server() throws Exception {        System.out.println("Starting Server");        ComplexImpl complexImpl = new ComplexImpl();        String address = "http://localhost:9000/Complex";        JaxWsServerFactoryBean factoryBean = new JaxWsServerFactoryBean();        factoryBean.setAddress(address);        factoryBean.setServiceBean(complexImpl);                //增加拦截器,放在最前面        factoryBean.getInInterceptors().add(0, new WSDLInterceptor());        factoryBean.create();    }

?

再看看拦截器的代码

?

package demo.hw.server;import org.apache.cxf.binding.soap.interceptor.EndpointSelectionInterceptor;import org.apache.cxf.common.util.StringUtils;import org.apache.cxf.common.util.UrlUtils;import org.apache.cxf.interceptor.Fault;import org.apache.cxf.message.Message;import org.apache.cxf.phase.AbstractPhaseInterceptor;import org.apache.cxf.phase.Phase;public class WSDLInterceptor extends AbstractPhaseInterceptor<Message>{    public WSDLInterceptor() {    super(Phase.READ);                getAfter().add(EndpointSelectionInterceptor.class.getName());}    @Overridepublic void handleMessage(Message message) throws Fault {String method = (String)message.get(Message.HTTP_REQUEST_METHOD);        String query = (String)message.get(Message.QUERY_STRING);        if (!"GET".equals(method) || StringUtils.isEmpty(query)) {            return;        }                if (UrlUtils.parseQueryString(query).containsKey("wsdl")) {        message.getInterceptorChain().abort();        return;}}    }

?

?在较早的版本中,CXF使用QueryHandler来处理 wsdl查询请求。可以想办法将WSDLQueryHandler替换掉。

?

先写到这了.....

?

?

热点排行