conquer0 发表于 2013-1-15 02:24:55

CXF三

校验类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();
    }
页: [1]
查看完整版本: CXF三