六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 51|回复: 0

CXF三

[复制链接]

升级  86%

11

主题

11

主题

11

主题

童生

Rank: 1

积分
43
 楼主| 发表于 2013-1-15 02:24:55 | 显示全部楼层 |阅读模式
校验类AuthorizationInterceptor写在服务器端的,代码如下:
package com.huawei.support.security;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.apache.cxf.binding.soap.interceptor.SoapHeaderInterceptor;
import org.apache.cxf.configuration.security.AuthorizationPolicy;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.Message;
import org.apache.cxf.transport.Conduit;
import org.apache.cxf.ws.addressing.EndpointReferenceType;
import org.springframework.core.io.Resource;
import com.huawei.support.utils.StreamUtil;
import com.huawei.support.utils.StringUtil;

public class AuthorizationInterceptor extends SoapHeaderInterceptor
{
    private static Properties props;
    /**
     * 配置路径
     */
    private Resource configLocation;

    public void setConfigLocation(Resource aConfigLocation)
    {
        this.configLocation = aConfigLocation;
    }
    private Properties getProps()
    {
        if (null == props)
        {
            props = new Properties();
            InputStream is = null;
            try
            {
                is = configLocation.getInputStream();
                props.load(is);
            }
            catch (IOException e)
            {
                props = null;
            }
            finally
            {
                StreamUtil.close(is);
            }
        }
        return props;
    }
private Conduit getConduit(Message inMessage) throws IOException
    {
        Exchange exchange = inMessage.getExchange();
        EndpointReferenceType target = exchange.get(EndpointReferenceType.class);
        Conduit conduit = exchange.getDestination().getBackChannel(inMessage,
                null,
                target);
        exchange.setConduit(conduit);
        return conduit;
    }  
    private void close(Message outMessage) throws IOException
    {
        OutputStream os = outMessage.getContent(OutputStream.class);
        os.flush();
        os.close();
    }
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表