cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andreasm...@apache.org
Subject svn commit: r510614 [1/2] - in /incubator/cxf/trunk: api/src/main/java/org/apache/cxf/ws/policy/ rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/ rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ rt/ws/policy/src/main/java/org/apache/cxf/ws/po...
Date Thu, 22 Feb 2007 18:28:44 GMT
Author: andreasmyth
Date: Thu Feb 22 10:28:42 2007
New Revision: 510614

URL: http://svn.apache.org/viewvc?view=rev&rev=510614
Log:
* Outbound client side policy interceptor to store the assertions of the chosen alternative in the message so that they are available to subsequent interceptors.
* Logical addressing interceptor to determine if addressing should be used by checking a) property in context, b) presence of Addressing assertion or c) presence of UsingAddressing attribute.
The latter check is performed only once per endpoint, results are cached.
* Logical addressing interceptor to run after OutgoingChainSetupInterceptor to that property propagation works correctly.
* Added system test that uses a plain wsdl model (no usingAddressing attribute, no Policy attachments) and external attachments as well as minimal configuration (PolicyEngine.registerInterceptors = true) to automatically engage the addressing interceptors.

Added:
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java   (with props)
    incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java   (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/GreeterImpl.java   (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/PolicyClientServerTest.java   (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/addr-only-external.xml   (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/addr-only.xml   (with props)
Modified:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyConstants.java
    incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInFaultInterceptor.java
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInInterceptor.java
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyOutInterceptor.java
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyInInterceptor.java
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyOutFaultInterceptor.java
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyOutInterceptor.java
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerResponsePolicyInfo.java
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/AbstractPolicyProvider.java
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/DomainExpressionBuilder.java
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/EndpointReferenceDomainExpressionBuilder.java
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProvider.java
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/Messages.properties
    incubator/cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/cxf-extension-policy.xml
    incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyExtensionsTest.java
    incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorsTest.java
    incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyTest.java
    incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProviderTest.java
    incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/policy-bus.xml
    incubator/cxf/trunk/systests/pom.xml
    incubator/cxf/trunk/testutils/src/main/resources/wsdl/greeter_control.wsdl

Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyConstants.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyConstants.java?view=diff&rev=510614&r1=510613&r2=510614
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyConstants.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyConstants.java Thu Feb 22 10:28:42 2007
@@ -46,6 +46,19 @@
     public static final String SERVER_POLICY_OUT_FAULT_INTERCEPTOR_ID
         = "org.apache.cxf.ws.policy.ServerPolicyOutFaultInterceptor";
     
+    public static final String CLIENT_OUT_ASSERTIONS
+        = "org.apache.cxf.ws.policy.client.out.assertions";
+    public static final String CLIENT_IN_ASSERTIONS
+        = "org.apache.cxf.ws.policy.client.in.assertions";
+    public static final String CLIENT_INFAULT_ASSERTIONS
+        = "org.apache.cxf.ws.policy.client.infault.assertions";
+    
+    public static final String SERVER_IN_ASSERTIONS
+        = "org.apache.cxf.ws.policy.server.in.assertions";
+    public static final String SERVER_OUT_ASSERTIONS
+        = "org.apache.cxf.ws.policy.server.out.assertions";
+    public static final String SERVER_OUTFAULT_ASSERTIONS
+        = "org.apache.cxf.ws.policy.server.outfault.assertions";
     
     private static String namespaceURI; 
     

Modified: incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java?view=diff&rev=510614&r1=510613&r2=510614
==============================================================================
--- incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java (original)
+++ incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java Thu Feb 22 10:28:42 2007
@@ -21,12 +21,13 @@
 
 
 import java.text.MessageFormat;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.ResourceBundle;
-import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -34,6 +35,8 @@
 
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.interceptor.OutgoingChainSetupInterceptor;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
@@ -41,6 +44,9 @@
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.Conduit;
 import org.apache.cxf.transport.Destination;
+import org.apache.cxf.ws.addressing.policy.MetadataConstants;
+import org.apache.cxf.ws.policy.PolicyConstants;
+import org.apache.neethi.Assertion;
 
 
 /**
@@ -64,8 +70,8 @@
     /**
      * Whether the endpoint supports WS-Addressing.
      */
-    private final AtomicBoolean usingAddressingDetermined = new AtomicBoolean(false);
-    private final AtomicBoolean usingAddressing = new AtomicBoolean(false);
+
+    private Map<Endpoint, Boolean> usingAddressing = new ConcurrentHashMap<Endpoint, Boolean>();
     
     /**
      * REVISIT allow this policy to be configured.
@@ -78,6 +84,8 @@
     public MAPAggregator() {
         super();
         setPhase(Phase.PRE_LOGICAL);
+        // this is necessary so that MAPs can be propagated 
+        addAfter(OutgoingChainSetupInterceptor.class.getName());
     }
 
     /**
@@ -106,39 +114,70 @@
     private boolean usingAddressing(Message message) {
         boolean ret = false;
         if (ContextUtils.isRequestor(message)) {
-            if (!usingAddressingDetermined.get()) {
-                Endpoint endpoint = message.getExchange().get(Endpoint.class);
-                if (endpoint != null) {
-                    EndpointInfo endpointInfo = endpoint.getEndpointInfo();
-                    List<ExtensibilityElement> endpointExts =
-                        endpointInfo != null
-                        ? endpointInfo.getExtensors(ExtensibilityElement.class)
-                        : null;
-                    List<ExtensibilityElement> bindingExts =
-                        endpointInfo != null
-                            && endpointInfo.getBinding() != null
-                        ? endpointInfo.getBinding().getExtensors(ExtensibilityElement.class)
-                        : null;
-                    List<ExtensibilityElement> serviceExts =
-                        endpointInfo != null
-                            && endpointInfo.getService() != null
-                        ? endpointInfo.getService().getExtensors(ExtensibilityElement.class)
-                        : null;
-                    ret = hasUsingAddressing(endpointExts)
-                          || hasUsingAddressing(bindingExts)
-                          || hasUsingAddressing(serviceExts);
-                } else {
-                    ret = WSAContextUtils.retrieveUsingAddressing(message);
-                }
-                setUsingAddressing(ret);
-            } else {
-                ret = usingAddressing.get();
-            }
+            ret =  WSAContextUtils.retrieveUsingAddressing(message)
+                || hasUsingAddressing(message) 
+                || hasAddressingAssertion(message);
         } else {
             ret = getMAPs(message, false, false) != null;
         }
         return ret;
     }
+      
+   /**
+    * Determine if the use of addressing is indicated by the presence of a
+    * the usingAddressing attribute.
+    *
+    * @param message the current message
+    * @pre message is outbound
+    * @pre requestor role
+    */
+    private boolean hasUsingAddressing(Message message) {
+        boolean ret = false;
+        Endpoint endpoint = message.getExchange().get(Endpoint.class);
+        if (null != endpoint) {
+            Boolean b = usingAddressing.get(endpoint);
+            if (null == b) {
+                EndpointInfo endpointInfo = endpoint.getEndpointInfo();
+                List<ExtensibilityElement> endpointExts = endpointInfo != null ? endpointInfo
+                    .getExtensors(ExtensibilityElement.class) : null;
+                List<ExtensibilityElement> bindingExts = endpointInfo != null
+                    && endpointInfo.getBinding() != null ? endpointInfo
+                    .getBinding().getExtensors(ExtensibilityElement.class) : null;
+                List<ExtensibilityElement> serviceExts = endpointInfo != null
+                    && endpointInfo.getService() != null ? endpointInfo
+                    .getService().getExtensors(ExtensibilityElement.class) : null;
+                ret = hasUsingAddressing(endpointExts) || hasUsingAddressing(bindingExts)
+                             || hasUsingAddressing(serviceExts);
+                b = ret ? Boolean.TRUE : Boolean.FALSE;
+                usingAddressing.put(endpoint, b);
+            } else {
+                ret = b.booleanValue();
+            }
+        }    
+        return ret;
+    }
+    
+    /**
+     * Determine if the use of addressing is indicated by an assertion in the
+     * alternative chosen for the current message.
+     * 
+     * @param message the current message
+     * @pre message is outbound
+     * @pre requestor role
+     */
+    private boolean hasAddressingAssertion(Message message) {
+        Collection<Assertion> assertions = 
+            CastUtils.cast((Collection)message.get(PolicyConstants.CLIENT_OUT_ASSERTIONS), Assertion.class);
+        if (null == assertions) {
+            return false;
+        }
+        for (Assertion a : assertions) {
+            if (MetadataConstants.ADDRESSING_ASSERTION_QNAME.equals(a.getName())) {
+                return true;
+            }
+        }
+        return false;
+    }
 
     /**
      * @param exts list of extension elements
@@ -174,7 +213,6 @@
         } else if (!ContextUtils.isRequestor(message)) {
             // responder validates incoming MAPs
             AddressingPropertiesImpl maps = getMAPs(message, false, false);
-            setUsingAddressing(true);
             boolean isOneway = message.getExchange().isOneWay();
             continueProcessing = validateIncomingMAPs(maps, message);
             if (continueProcessing) {
@@ -378,16 +416,6 @@
             }
         }
         return valid;
-    }
-    
-    /**
-     * Set using addressing flag.
-     * 
-     * @param using true if addressing in use.
-     */
-    private void setUsingAddressing(boolean using) {
-        usingAddressing.set(using);
-        usingAddressingDetermined.set(true);
     }
 }
 

Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInFaultInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInFaultInterceptor.java?view=diff&rev=510614&r1=510613&r2=510614
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInFaultInterceptor.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInFaultInterceptor.java Thu Feb 22 10:28:42 2007
@@ -20,13 +20,17 @@
 package org.apache.cxf.ws.policy;
 
 import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 import org.apache.cxf.phase.Phase;
-import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.Conduit;
 
 /**
@@ -34,6 +38,7 @@
  */
 public class ClientPolicyInFaultInterceptor extends AbstractPhaseInterceptor<Message> {
 
+    private static final Logger LOG = LogUtils.getL7dLogger(ClientPolicyInFaultInterceptor.class);
     private Bus bus;
     
     public ClientPolicyInFaultInterceptor() {
@@ -51,11 +56,16 @@
     
     public void handleMessage(Message msg) {        
         if (!PolicyUtils.isRequestor(msg)) {
+            LOG.fine("Not a requestor.");
             return;
         }
         
-        EndpointInfo ei = msg.get(EndpointInfo.class);
-        if (null == ei) {
+        Exchange exchange = msg.getExchange();
+        assert null != exchange;
+        
+        Endpoint e = exchange.get(Endpoint.class);
+        if (null == e) {
+            LOG.fine("No endpoint.");
             return;
         }
         
@@ -69,9 +79,12 @@
         // We do not know the underlying message type yet - so we pre-emptively add interceptors 
         // that can deal with the response and all of the operation's possible fault messages.
         
-        List<Interceptor> policyInFaultInterceptors = pe.getClientInFaultInterceptors(ei, conduit);
+        List<Interceptor> policyInFaultInterceptors = pe.getClientInFaultInterceptors(e, conduit);
         for (Interceptor poi : policyInFaultInterceptors) {
             msg.getInterceptorChain().add(poi);
+            if (LOG.isLoggable(Level.FINE)) {
+                LOG.fine("Added interceptor of type " + poi.getClass().getSimpleName());
+            }
         }
     }
 }

Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInInterceptor.java?view=diff&rev=510614&r1=510613&r2=510614
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInInterceptor.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInInterceptor.java Thu Feb 22 10:28:42 2007
@@ -20,13 +20,17 @@
 package org.apache.cxf.ws.policy;
 
 import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 import org.apache.cxf.phase.Phase;
-import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.Conduit;
 
 /**
@@ -34,6 +38,7 @@
  */
 public class ClientPolicyInInterceptor extends AbstractPhaseInterceptor<Message> {
 
+    private static final Logger LOG = LogUtils.getL7dLogger(ClientPolicyInInterceptor.class);
     private Bus bus;
     
     public ClientPolicyInInterceptor() {
@@ -51,11 +56,16 @@
     
     public void handleMessage(Message msg) {        
         if (!PolicyUtils.isRequestor(msg)) {
+            LOG.fine("Not a requestor.");
             return;
         }
         
-        EndpointInfo ei = msg.get(EndpointInfo.class);
-        if (null == ei) {
+        Exchange exchange = msg.getExchange();
+        assert null != exchange;
+        
+        Endpoint e = exchange.get(Endpoint.class);
+        if (null == e) {
+            LOG.fine("No endpoint.");
             return;
         }
         
@@ -69,9 +79,12 @@
         // We do not know the underlying message type yet - so we pre-emptively add interceptors 
         // that can deal with the response and all of the operation's possible fault messages.
         
-        List<Interceptor> policyInInterceptors = pe.getClientInInterceptors(ei, conduit);
+        List<Interceptor> policyInInterceptors = pe.getClientInInterceptors(e, conduit);
         for (Interceptor poi : policyInInterceptors) {
             msg.getInterceptorChain().add(poi);
+            if (LOG.isLoggable(Level.FINE)) {
+                LOG.fine("Added interceptor of type " + poi.getClass().getSimpleName());
+            }
         }
         
     }

Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyOutInterceptor.java?view=diff&rev=510614&r1=510613&r2=510614
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyOutInterceptor.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyOutInterceptor.java Thu Feb 22 10:28:42 2007
@@ -20,14 +20,18 @@
 package org.apache.cxf.ws.policy;
 
 import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.service.model.BindingOperationInfo;
-import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.Conduit;
 
 /**
@@ -35,6 +39,7 @@
  */
 public class ClientPolicyOutInterceptor extends AbstractPhaseInterceptor<Message> {
 
+    private static final Logger LOG = LogUtils.getL7dLogger(ClientPolicyOutInterceptor.class);
     private Bus bus;
     
     public ClientPolicyOutInterceptor() {
@@ -52,16 +57,22 @@
     
     public void handleMessage(Message msg) {
         if (!PolicyUtils.isRequestor(msg)) {
+            LOG.fine("Not a requestor.");
             return;
         }
         
-        BindingOperationInfo boi = msg.get(BindingOperationInfo.class);
+        Exchange exchange = msg.getExchange();
+        assert null != exchange;
+        
+        BindingOperationInfo boi = exchange.get(BindingOperationInfo.class);
         if (null == boi) {
+            LOG.fine("No binding operation info.");
             return;
         }
         
-        EndpointInfo ei = msg.get(EndpointInfo.class);
-        if (null == ei) {
+        Endpoint e = exchange.get(Endpoint.class);
+        if (null == e) {
+            LOG.fine("No endpoint.");
             return;
         }        
         
@@ -72,9 +83,18 @@
         
         Conduit conduit = msg.getConduit();
         
-        List<Interceptor> policyOutInterceptors = pe.getClientOutInterceptors(boi, ei, conduit);
-        for (Interceptor poi : policyOutInterceptors) {
+        // add the required interceptors
+        
+        List<Interceptor> policyOutInterceptors = pe.getClientOutInterceptors(e, boi, conduit);
+        for (Interceptor poi : policyOutInterceptors) {            
             msg.getInterceptorChain().add(poi);
+            if (LOG.isLoggable(Level.FINE)) {
+                LOG.fine("Added interceptor of type " + poi.getClass().getSimpleName());
+            }
         }
+        
+        // insert assertions of the chosen alternative into the message
+        
+        msg.put(PolicyConstants.CLIENT_OUT_ASSERTIONS, pe.getClientOutAssertions(e, boi, conduit));
     }
 }

Added: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java?view=auto&rev=510614
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java Thu Feb 22 10:28:42 2007
@@ -0,0 +1,399 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.ws.policy;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.annotation.PostConstruct;
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.extension.BusExtension;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.service.model.BindingFaultInfo;
+import org.apache.cxf.service.model.BindingMessageInfo;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.transport.Conduit;
+import org.apache.cxf.transport.Destination;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.Constants;
+import org.apache.neethi.Policy;
+import org.apache.neethi.PolicyComponent;
+import org.apache.neethi.PolicyOperator;
+import org.apache.neethi.PolicyReference;
+import org.apache.neethi.PolicyRegistry;
+
+/**
+ * 
+ */
+public class PolicyEngine implements BusExtension {
+    
+    private Bus bus;
+    private PolicyRegistry registry;
+    private Collection<PolicyProvider> policyProviders;
+    private boolean registerInterceptors;
+
+    private Map<BindingOperation, ClientRequestPolicyInfo> clientRequestInfo 
+        = new ConcurrentHashMap<BindingOperation, ClientRequestPolicyInfo>();
+    
+    private Map<Endpoint, EndpointPolicyInfo> endpointInfo 
+        = new ConcurrentHashMap<Endpoint, EndpointPolicyInfo>();
+    
+    private Map<BindingOperation, ServerResponsePolicyInfo> serverResponseInfo 
+        = new ConcurrentHashMap<BindingOperation, ServerResponsePolicyInfo>();
+
+    public PolicyEngine() {
+        registry = new PolicyRegistryImpl();
+    }
+    
+    public Class getRegistrationType() {
+        return PolicyEngine.class;
+    }
+    
+    public void setBus(Bus b) {
+        bus = b;
+    }
+    
+    public Bus getBus() {
+        return bus;
+    }
+    
+    public void setPolicyProviders(Collection<PolicyProvider> p) {
+        policyProviders = p;
+    }
+   
+    public Collection<PolicyProvider> getPolicyProviders() {
+        return policyProviders;
+    }
+    
+    public void setRegistry(PolicyRegistry r) {
+        registry = r;
+    }
+    
+    public PolicyRegistry getRegistry() {
+        return registry;
+    }
+      
+    public boolean getRegisterInterceptors() {
+        return registerInterceptors;
+    }
+
+    public void setRegisterInterceptors(boolean ri) {
+        registerInterceptors = ri;
+    }
+    
+    @PostConstruct
+    public void addBusInterceptors() {
+        if (null == bus || !registerInterceptors) {
+            return;
+        }
+
+        ClientPolicyOutInterceptor clientOut = new ClientPolicyOutInterceptor();
+        clientOut.setBus(bus);
+        bus.getOutInterceptors().add(clientOut);
+        ClientPolicyInInterceptor clientIn = new ClientPolicyInInterceptor();
+        clientIn.setBus(bus);
+        bus.getInInterceptors().add(clientIn);
+        ClientPolicyInFaultInterceptor clientInFault = new ClientPolicyInFaultInterceptor();
+        clientInFault.setBus(bus);
+        bus.getInFaultInterceptors().add(clientInFault);
+        
+        ServerPolicyInInterceptor serverIn = new ServerPolicyInInterceptor();
+        serverIn.setBus(bus);
+        bus.getInInterceptors().add(serverIn);
+        ServerPolicyOutInterceptor serverOut = new ServerPolicyOutInterceptor();
+        serverOut.setBus(bus);
+        bus.getOutInterceptors().add(serverOut);
+        ServerPolicyOutFaultInterceptor serverOutFault = new ServerPolicyOutFaultInterceptor();
+        serverOutFault.setBus(bus);
+        bus.getOutFaultInterceptors().add(serverOutFault);
+        
+        // TODO: policy verification interceptors
+    }  
+    
+    public Collection<Assertion> getClientOutAssertions(Endpoint e, BindingOperationInfo boi, Conduit c) {
+        return getClientRequestPolicyInfo(e, boi, c).getChosenAlternative();
+    }
+
+    public List<Interceptor> getClientOutInterceptors(Endpoint e, BindingOperationInfo boi, Conduit c) {
+        return getClientRequestPolicyInfo(e, boi, c).getOutInterceptors();
+    }
+    
+    public List<Interceptor> getClientInInterceptors(Endpoint e, Conduit c) {        
+        return getEndpointPolicyInfo(e, c).getInInterceptors();
+    }
+    
+    public List<Interceptor> getClientInFaultInterceptors(Endpoint e, Conduit c) {
+        return getEndpointPolicyInfo(e, c).getInFaultInterceptors();
+    }
+    
+    public List<Interceptor> getServerInInterceptors(Endpoint e, Destination d) {
+        return getEndpointPolicyInfo(e, d).getInInterceptors();
+    }
+    
+    public Collection<Assertion> getServerOutAssertions(Endpoint e, BindingOperationInfo boi,
+                                                       Destination d) {
+        return getServerResponsePolicyInfo(e, boi, d).getChosenAlternative(); 
+    }
+                                                       
+    public List<Interceptor> getServerOutInterceptors(Endpoint e, BindingOperationInfo boi, 
+                                                      Destination d) {
+        return getServerResponsePolicyInfo(e, boi, d).getOutInterceptors();
+    }
+    
+    public List<Interceptor> getServerOutFaultInterceptors(Endpoint e, BindingOperationInfo boi, 
+                                                      Destination d) {
+        return getServerResponsePolicyInfo(e, boi, d).getOutFaultInterceptors();
+    }
+
+    public Policy getAggregatedServicePolicy(ServiceInfo si) {
+        Policy aggregated = null;
+        for (PolicyProvider pp : getPolicyProviders()) {
+            Policy p = pp.getEffectivePolicy(si);
+            if (null == aggregated) {
+                aggregated = p;
+            } else {
+                aggregated = aggregated.merge(p);
+            }
+        }
+        return aggregated == null ? new Policy() : aggregated;
+    }
+
+    public Policy getAggregatedEndpointPolicy(EndpointInfo ei) {
+        Policy aggregated = null;
+        for (PolicyProvider pp : getPolicyProviders()) {
+            Policy p = pp.getEffectivePolicy(ei);
+            if (null == aggregated) {
+                aggregated = p;
+            } else {
+                aggregated = aggregated.merge(p);
+            }
+        }
+        return aggregated == null ? new Policy() : aggregated;
+    }
+    
+    public Policy getAggregatedOperationPolicy(BindingOperationInfo boi) {
+        Policy aggregated = null;
+        for (PolicyProvider pp : getPolicyProviders()) {
+            Policy p = pp.getEffectivePolicy(boi);
+            if (null == aggregated) {
+                aggregated = p;
+            } else {
+                aggregated = aggregated.merge(p);
+            }
+        }
+        return aggregated == null ? new Policy() : aggregated;
+    }
+    
+    public Policy getAggregatedMessagePolicy(BindingMessageInfo bmi) {
+        Policy aggregated = null;
+        for (PolicyProvider pp : getPolicyProviders()) {
+            Policy p = pp.getEffectivePolicy(bmi);
+            if (null == aggregated) {
+                aggregated = p;
+            } else {
+                aggregated = aggregated.merge(p);
+            }
+        }
+        return aggregated == null ? new Policy() : aggregated;
+    }
+    
+    public Policy getAggregatedFaultPolicy(BindingFaultInfo bfi) {
+        Policy aggregated = null;
+        for (PolicyProvider pp : getPolicyProviders()) {
+            Policy p = pp.getEffectivePolicy(bfi);
+            if (null == aggregated) {
+                aggregated = p;
+            } else {
+                aggregated = aggregated.merge(p);
+            }
+        }
+        return aggregated == null ? new Policy() : aggregated;
+    }
+    
+    /**
+     * Return a collection of all assertions used in the given policy component,
+     * optionally including optional assertions.
+     * The policy need not be normalised, so any policy references will have to be resolved.
+     * @param pc the policy component
+     * @param includeOptional flag indicating if optional assertions should be included
+     * @return the assertions
+     */
+    public Collection<Assertion> getAssertions(PolicyComponent pc, boolean includeOptional) {
+        
+        if (Constants.TYPE_ASSERTION == pc.getType()) {
+            return Collections.singletonList((Assertion)pc);
+        } 
+        
+        Collection<Assertion> assertions = new ArrayList<Assertion>();
+        addAssertions(pc, includeOptional, assertions);
+        return assertions;
+    }
+    
+    private void addAssertions(PolicyComponent pc, boolean includeOptional, 
+                               Collection<Assertion> assertions) {
+
+        if (Constants.TYPE_ASSERTION == pc.getType()) {
+            Assertion a = (Assertion)pc;
+            if (includeOptional || !a.isOptional()) {
+                assertions.add((Assertion)pc);
+                return;
+            }
+        } 
+        
+        if (Constants.TYPE_POLICY_REF == pc.getType()) {
+            PolicyReference pr = (PolicyReference)pc;
+            pc = pr.normalize(registry, false);
+        }
+
+        assert Constants.TYPE_POLICY == pc.getType() 
+                || Constants.TYPE_POLICY == pc.getType() 
+                || Constants.TYPE_EXACTLYONE == pc.getType();
+
+        PolicyOperator po = (PolicyOperator)pc;
+
+        List<PolicyComponent> pcs = CastUtils.cast(po.getPolicyComponents(), PolicyComponent.class);
+        for (PolicyComponent child : pcs) {
+            addAssertions(child, includeOptional, assertions);
+        }
+    }
+    
+    /**
+     * Return the vocabulary of a policy component, i.e. the set of QNames of
+     * the assertions used in the componente, duplicates removed.
+     * @param pc the policy component
+     * @param includeOptional flag indicating if optional assertions should be included
+     * @return the vocabulary
+     */
+    public Set<QName> getVocabulary(PolicyComponent pc, boolean includeOptional) {
+        Collection<Assertion> assertions = getAssertions(pc, includeOptional);
+        Set<QName> vocabulary = new HashSet<QName>();
+        for (Assertion a : assertions) {
+            vocabulary.add(a.getName());
+        }
+        return vocabulary;
+    }
+
+
+    /**
+     * Check if a given list of assertions can potentially be supported by
+     * interceptors or by an already installed assertor (a conduit or transport
+     * that implements the Assertor interface).
+     * 
+     * @param alternative the policy alternative
+     * @param Assertor the assertor
+     * @return true iff the alternative can be supported
+     */
+    boolean supportsAlternative(List<Assertion> alternative, Assertor assertor) {
+        PolicyInterceptorProviderRegistry pipr = bus.getExtension(PolicyInterceptorProviderRegistry.class);
+        for (Assertion a : alternative) {
+            if (!(a.isOptional() 
+                || (null != pipr.get(a.getName())) 
+                || (null != assertor && assertor.asserts(a)))) {
+                return false;
+            }
+        }
+        return true;
+    }
+    
+    ClientRequestPolicyInfo getClientRequestPolicyInfo(Endpoint e, BindingOperationInfo boi, Conduit c) {
+        BindingOperation bo = new BindingOperation(e, boi);
+        ClientRequestPolicyInfo crpi = clientRequestInfo.get(bo);
+        if (null == crpi) {
+            crpi = new ClientRequestPolicyInfo();
+            Assertor assertor = null;
+            if (c instanceof Assertor) {
+                assertor = (Assertor)c;
+            }
+            crpi.initialise(boi, e.getEndpointInfo(), this, assertor);
+            clientRequestInfo.put(bo, crpi);
+        }
+        return crpi;
+    }
+    
+    EndpointPolicyInfo getEndpointPolicyInfo(Endpoint e, Conduit conduit) {
+        EndpointPolicyInfo epi = endpointInfo.get(e);
+        if (null != epi) {
+            return epi;
+        }
+        Assertor assertor = conduit instanceof Assertor ? (Assertor)conduit : null;
+        return createEndpointPolicyInfo(e, false, assertor);
+    }
+    
+    EndpointPolicyInfo getEndpointPolicyInfo(Endpoint e, Destination destination) {
+        EndpointPolicyInfo epi = endpointInfo.get(e);
+        if (null != epi) {
+            return epi;
+        }
+        Assertor assertor = destination instanceof Assertor ? (Assertor)destination : null;
+        return createEndpointPolicyInfo(e, true, assertor);
+    }
+    
+    EndpointPolicyInfo createEndpointPolicyInfo(Endpoint e, boolean isServer, Assertor assertor) {
+        EndpointPolicyInfo epi = new EndpointPolicyInfo();
+        epi.initialise(e.getEndpointInfo(), isServer, this, assertor);
+        endpointInfo.put(e, epi);
+
+        return epi;
+    }
+    
+    ServerResponsePolicyInfo getServerResponsePolicyInfo(Endpoint e, BindingOperationInfo boi, 
+                                                         Destination d) {
+        BindingOperation bo = new BindingOperation(e, boi);
+        ServerResponsePolicyInfo srpi = serverResponseInfo.get(bo);
+        if (null == srpi) {
+            srpi = new ServerResponsePolicyInfo();
+            Assertor assertor = null;
+            if (d instanceof Assertor) {
+                assertor = (Assertor)d;
+            }
+            srpi.initialise(e, boi, this, assertor);
+            serverResponseInfo.put(bo, srpi);
+        }
+        return srpi;
+    }
+    
+    
+    /**
+     * Class used as key in the client request policy map.
+     */
+    class BindingOperation {
+        Endpoint endpoint;
+        BindingOperationInfo boi;
+        
+        BindingOperation(Endpoint e, BindingOperationInfo b) {
+            endpoint = e;
+            boi = b;
+        }
+    }
+
+
+}

Propchange: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java?view=diff&rev=510614&r1=510613&r2=510614
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java Thu Feb 22 10:28:42 2007
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.ws.policy;
 
+import java.util.Collection;
 import java.util.List;
 
 import org.apache.cxf.helpers.CastUtils;
@@ -48,6 +49,44 @@
     public static boolean isRequestor(Message message) {
         Boolean requestor = (Boolean)message.get(Message.REQUESTOR_ROLE);
         return requestor != null && requestor.booleanValue();
+    }
+    
+    /**
+     * Determine if a collection of assertions contains a given assertion, using
+     * the equal method from the Assertion interface.
+     * 
+     * @param assertions a collection of assertions
+     * @param candidate the assertion to test
+     * @return true iff candidate is equal to one of the assertions in the collection
+     */
+    public static boolean contains(Collection<Assertion> assertions, Assertion candidate) {
+        for (Assertion a : assertions) {
+            if (a.equal(candidate)) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    /**
+     * Determine if one collection of assertions contains another collection of assertion, using
+     * the equal method from the Assertion interface.
+     * 
+     * @param assertions a collection of assertions
+     * @param candidates the collections of assertion to test
+     * @return true iff each candidate is equal to one of the assertions in the collection
+     */
+    public static boolean contains(Collection<Assertion> assertions, 
+                                   Collection<Assertion> candidates) {
+        if (null == candidates || candidates.isEmpty()) {
+            return true;
+        }
+        for (Assertion c : candidates) {
+            if (!contains(assertions, c)) {
+                return false;
+            }
+        }
+        return true;
     }
     
     public static void printPolicyComponent(PolicyComponent pc) {

Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyInInterceptor.java?view=diff&rev=510614&r1=510613&r2=510614
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyInInterceptor.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyInInterceptor.java Thu Feb 22 10:28:42 2007
@@ -20,13 +20,17 @@
 package org.apache.cxf.ws.policy;
 
 import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 import org.apache.cxf.phase.Phase;
-import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.Destination;
 
 /**
@@ -34,6 +38,7 @@
  */
 public class ServerPolicyInInterceptor extends AbstractPhaseInterceptor<Message> {
 
+    private static final Logger LOG = LogUtils.getL7dLogger(ServerPolicyInInterceptor.class);
     private Bus bus;
     
     public ServerPolicyInInterceptor() {
@@ -51,13 +56,18 @@
     
     public void handleMessage(Message msg) {        
         if (PolicyUtils.isRequestor(msg)) {
+            LOG.fine("Is a requestor.");
             return;
         }
         
-        EndpointInfo ei = msg.get(EndpointInfo.class);
-        if (null == ei) {
+        Exchange exchange = msg.getExchange();
+        assert null != exchange;
+        
+        Endpoint e = exchange.get(Endpoint.class);
+        if (null == e) {
+            LOG.fine("No endpoint.");
             return;
-        }
+        }        
         
         PolicyEngine pe = bus.getExtension(PolicyEngine.class);
         if (null == pe) {
@@ -69,9 +79,12 @@
         // We do not know the underlying message type yet - so we pre-emptively add interceptors 
         // that can deal with any requests on the underlying endpoint
         
-        List<Interceptor> policyInInterceptors = pe.getServerInInterceptors(ei, destination);
+        List<Interceptor> policyInInterceptors = pe.getServerInInterceptors(e, destination);
         for (Interceptor poi : policyInInterceptors) {
             msg.getInterceptorChain().add(poi);
+            if (LOG.isLoggable(Level.FINE)) {
+                LOG.fine("Added interceptor of type " + poi.getClass().getSimpleName());
+            }
         }
     }
 }

Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyOutFaultInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyOutFaultInterceptor.java?view=diff&rev=510614&r1=510613&r2=510614
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyOutFaultInterceptor.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyOutFaultInterceptor.java Thu Feb 22 10:28:42 2007
@@ -20,14 +20,18 @@
 package org.apache.cxf.ws.policy;
 
 import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.service.model.BindingOperationInfo;
-import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.Destination;
 
 /**
@@ -35,6 +39,7 @@
  */
 public class ServerPolicyOutFaultInterceptor extends AbstractPhaseInterceptor<Message> {
 
+    private static final Logger LOG = LogUtils.getL7dLogger(ServerPolicyOutFaultInterceptor.class);
     private Bus bus;
     
     public ServerPolicyOutFaultInterceptor() {
@@ -52,16 +57,22 @@
     
     public void handleMessage(Message msg) {        
         if (PolicyUtils.isRequestor(msg)) {
+            LOG.fine("Is a requestor.");
             return;
         }
         
-        BindingOperationInfo boi = msg.get(BindingOperationInfo.class);
+        Exchange exchange = msg.getExchange();
+        assert null != exchange;
+        
+        BindingOperationInfo boi = exchange.get(BindingOperationInfo.class);
         if (null == boi) {
+            LOG.fine("No binding operation info.");
             return;
         }
         
-        EndpointInfo ei = msg.get(EndpointInfo.class);
-        if (null == ei) {
+        Endpoint e = exchange.get(Endpoint.class);
+        if (null == e) {
+            LOG.fine("No endpoint.");
             return;
         }
         
@@ -72,9 +83,12 @@
         
         Destination destination = msg.getDestination();
         
-        List<Interceptor> outInterceptors = pe.getServerOutFaultInterceptors(boi, ei, destination);
+        List<Interceptor> outInterceptors = pe.getServerOutFaultInterceptors(e, boi, destination);
         for (Interceptor oi : outInterceptors) {
             msg.getInterceptorChain().add(oi);
+            if (LOG.isLoggable(Level.FINE)) {
+                LOG.fine("Added interceptor of type " + oi.getClass().getSimpleName());
+            }
         }
     }
 }

Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyOutInterceptor.java?view=diff&rev=510614&r1=510613&r2=510614
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyOutInterceptor.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyOutInterceptor.java Thu Feb 22 10:28:42 2007
@@ -20,14 +20,18 @@
 package org.apache.cxf.ws.policy;
 
 import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.service.model.BindingOperationInfo;
-import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.Destination;
 
 /**
@@ -35,6 +39,7 @@
  */
 public class ServerPolicyOutInterceptor extends AbstractPhaseInterceptor<Message> {
 
+    private static final Logger LOG = LogUtils.getL7dLogger(ServerPolicyOutInterceptor.class);
     private Bus bus;
     
     public ServerPolicyOutInterceptor() {
@@ -52,16 +57,22 @@
     
     public void handleMessage(Message msg) {        
         if (PolicyUtils.isRequestor(msg)) {
+            LOG.fine("Is a requestor.");
             return;
         }
         
-        BindingOperationInfo boi = msg.get(BindingOperationInfo.class);
+        Exchange exchange = msg.getExchange();
+        assert null != exchange;
+        
+        BindingOperationInfo boi = exchange.get(BindingOperationInfo.class);
         if (null == boi) {
+            LOG.fine("No binding operation info.");
             return;
         }
         
-        EndpointInfo ei = msg.get(EndpointInfo.class);
-        if (null == ei) {
+        Endpoint e = exchange.get(Endpoint.class);
+        if (null == e) {
+            LOG.fine("No endpoint.");
             return;
         }
         
@@ -72,9 +83,17 @@
         
         Destination destination = msg.getDestination();
         
-        List<Interceptor> outInterceptors = pe.getServerOutInterceptors(boi, ei, destination);
+        List<Interceptor> outInterceptors = pe.getServerOutInterceptors(e, boi, destination);
+        LOG.fine("Required out interceptors: " + outInterceptors);
         for (Interceptor oi : outInterceptors) {
             msg.getInterceptorChain().add(oi);
+            if (LOG.isLoggable(Level.FINE)) {
+                LOG.fine("Added interceptor of type " + oi.getClass().getSimpleName());
+            }
         }
+        
+        // insert assertions of the chosen alternative into the message
+        
+        msg.put(PolicyConstants.SERVER_OUT_ASSERTIONS, pe.getServerOutAssertions(e, boi, destination));
     }
 }

Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerResponsePolicyInfo.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerResponsePolicyInfo.java?view=diff&rev=510614&r1=510613&r2=510614
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerResponsePolicyInfo.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerResponsePolicyInfo.java Thu Feb 22 10:28:42 2007
@@ -29,11 +29,11 @@
 
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.service.model.BindingFaultInfo;
 import org.apache.cxf.service.model.BindingOperationInfo;
-import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.Destination;
 import org.apache.neethi.Assertion;
 import org.apache.neethi.Policy;
@@ -67,16 +67,16 @@
         return outFaultInterceptors;
     }   
     
-    public void initialise(BindingOperationInfo boi, EndpointInfo ei, 
+    public void initialise(Endpoint e, BindingOperationInfo boi,
                            PolicyEngine engine, Assertor assertor) {
-        initialiseResponsePolicy(boi, ei, engine);
-        chooseAlternative(engine, ei, assertor);
+        initialiseResponsePolicy(e, boi, engine);
+        chooseAlternative(e, engine, assertor);
         initialiseOutInterceptors(boi, engine);
-        initialiseOutFaultInterceptors(boi, ei, engine);
+        initialiseOutFaultInterceptors(boi, engine);
     }
     
-    void initialiseResponsePolicy(BindingOperationInfo boi, EndpointInfo ei, PolicyEngine engine) {
-        responsePolicy = engine.getEndpointPolicyInfo(ei, (Destination)null).getPolicy(); 
+    void initialiseResponsePolicy(Endpoint e, BindingOperationInfo boi, PolicyEngine engine) {
+        responsePolicy = engine.getEndpointPolicyInfo(e, (Destination)null).getPolicy(); 
         responsePolicy = responsePolicy.merge(engine.getAggregatedOperationPolicy(boi));
         if (null != boi.getOutput()) {
             responsePolicy = responsePolicy.merge(engine.getAggregatedMessagePolicy(boi.getOutput()));
@@ -84,13 +84,13 @@
         responsePolicy = (Policy)responsePolicy.normalize(true);
     }
 
-    void chooseAlternative(PolicyEngine engine, EndpointInfo ei, Assertor assertor) {
-        EndpointPolicyInfo epi = engine.getEndpointPolicyInfo(ei, (Destination)null);
+    void chooseAlternative(Endpoint e, PolicyEngine engine, Assertor assertor) {
+        EndpointPolicyInfo epi = engine.getEndpointPolicyInfo(e, (Destination)null);
         Iterator alternatives = responsePolicy.getAlternatives();
         while (alternatives.hasNext()) {
             List<Assertion> alternative = CastUtils.cast((List)alternatives.next(), Assertion.class);
             if (engine.supportsAlternative(alternative, assertor)
-                && alternative.contains(epi.getChosenAlternative())) {
+                && PolicyUtils.contains(alternative, epi.getChosenAlternative())) {
                 setChosenAlternative(alternative);
                 return;
             }
@@ -102,7 +102,8 @@
         outInterceptors = new ArrayList<Interceptor>();
         
         if (null == boi.getOutput()) {
-            return;
+            // need out interceptors for partial responses
+            // return;
         }     
         
         PolicyInterceptorProviderRegistry reg = engine.getBus()
@@ -120,7 +121,7 @@
         }
     }
     
-    void initialiseOutFaultInterceptors(BindingOperationInfo boi, EndpointInfo ei, PolicyEngine engine) {
+    void initialiseOutFaultInterceptors(BindingOperationInfo boi, PolicyEngine engine) {
         outFaultInterceptors = new ArrayList<Interceptor>();
         
         if (null == boi.getOutput()) {

Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/AbstractPolicyProvider.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/AbstractPolicyProvider.java?view=diff&rev=510614&r1=510613&r2=510614
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/AbstractPolicyProvider.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/AbstractPolicyProvider.java Thu Feb 22 10:28:42 2007
@@ -63,10 +63,10 @@
     }  
     
     @PostConstruct
-    void init() {
+    public void init() {
         if (null != bus) {
             setBuilder(bus.getExtension(PolicyBuilder.class));
-            PolicyEngine pe = bus.getExtension(PolicyEngine.class);
+            PolicyEngine pe = (PolicyEngine)bus.getExtension(PolicyEngine.class);
             setRegistry(pe.getRegistry());
         }
     }

Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/DomainExpressionBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/DomainExpressionBuilder.java?view=diff&rev=510614&r1=510613&r2=510614
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/DomainExpressionBuilder.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/DomainExpressionBuilder.java Thu Feb 22 10:28:42 2007
@@ -19,6 +19,10 @@
 
 package org.apache.cxf.ws.policy.attachment.external;
 
+import java.util.Collection;
+
+import javax.xml.namespace.QName;
+
 import org.w3c.dom.Element;
 
 /**
@@ -26,6 +30,20 @@
  */
 public interface DomainExpressionBuilder {
     
+    /**
+     * Builds a domain expression from the given element.
+     * 
+     * @param e the element
+     * @return the domin expression
+     */
     DomainExpression build(Element e);
+    
+    /**
+     * Returns a collection of QNames describing the xml schema types for which this
+     * builder can build domain expressions.
+     * 
+     * @return collection of supported types
+     */
+    Collection<QName> getDomainExpressionTypes();
    
 }

Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/EndpointReferenceDomainExpressionBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/EndpointReferenceDomainExpressionBuilder.java?view=diff&rev=510614&r1=510613&r2=510614
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/EndpointReferenceDomainExpressionBuilder.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/EndpointReferenceDomainExpressionBuilder.java Thu Feb 22 10:28:42 2007
@@ -19,12 +19,15 @@
 
 package org.apache.cxf.ws.policy.attachment.external;
 
+import java.util.Collection;
+import java.util.Collections;
 import java.util.ResourceBundle;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Unmarshaller;
+import javax.xml.namespace.QName;
 
 import org.w3c.dom.Element;
 
@@ -41,6 +44,9 @@
     private static final ResourceBundle BUNDLE 
         = BundleUtils.getBundle(EndpointReferenceDomainExpressionBuilder.class);
     
+    private static final Collection<QName> SUPPORTED_TYPES = Collections.singletonList(
+        new QName("http://www.w3.org/2005/08/addressing", "EndpointReference"));
+    
     private Unmarshaller unmarshaller;
     
     EndpointReferenceDomainExpressionBuilder() {
@@ -51,8 +57,12 @@
             throw new PolicyException(new Message("EPR_DOMAIN_EXPRESSION_BUILDER_INIT_EXC", BUNDLE, 
                                                   (Object[])null), ex);
         }
-    }
+    }  
     
+    public Collection<QName> getDomainExpressionTypes() {
+        return SUPPORTED_TYPES;
+    }
+
     public DomainExpression build(Element e) {
         Object obj = null;
         try {

Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProvider.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProvider.java?view=diff&rev=510614&r1=510613&r2=510614
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProvider.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProvider.java Thu Feb 22 10:28:42 2007
@@ -22,6 +22,7 @@
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.ResourceBundle;
 
 import javax.xml.namespace.QName;
 
@@ -31,8 +32,9 @@
 import org.w3c.dom.NodeList;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.common.i18n.BundleUtils;
+import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.helpers.DOMUtils;
-import org.apache.cxf.resource.URIResolver;
 import org.apache.cxf.service.model.BindingFaultInfo;
 import org.apache.cxf.service.model.BindingMessageInfo;
 import org.apache.cxf.service.model.BindingOperationInfo;
@@ -40,18 +42,26 @@
 import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.ws.policy.PolicyConstants;
 import org.apache.cxf.ws.policy.PolicyException;
+import org.apache.cxf.ws.policy.PolicyProvider;
 import org.apache.cxf.ws.policy.attachment.AbstractPolicyProvider;
 import org.apache.cxf.ws.policy.attachment.reference.LocalDocumentReferenceResolver;
 import org.apache.cxf.ws.policy.attachment.reference.ReferenceResolver;
 import org.apache.neethi.Policy;
 import org.apache.neethi.PolicyReference;
+import org.springframework.core.io.Resource;
 
 /**
  * 
  */
-public class ExternalAttachmentProvider extends AbstractPolicyProvider {
+public class ExternalAttachmentProvider extends AbstractPolicyProvider
+    implements PolicyProvider {
     
-    private String uri;
+    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(ExternalAttachmentProvider.class);
+    
+    // Use a Resource object here instead of a String so that the resource can be resolved when
+    // this bean is created
+  
+    private Resource location;
     private Collection<PolicyAttachment> attachments;
     
     ExternalAttachmentProvider() {        
@@ -61,12 +71,12 @@
         super(b);
     }
     
-    public void setURI(String u) {
-        uri = u;
+    public void setLocation(Resource u) {
+        location = u;
     }
     
-    public String getURI() {
-        return uri;
+    public Resource getLocation() {
+        return location;
     }
 
     public Policy getEffectivePolicy(BindingFaultInfo bfi) {
@@ -138,12 +148,11 @@
         attachments = new ArrayList<PolicyAttachment>();
         Document doc = null;
         try {
-            InputStream is = new URIResolver(uri).getInputStream();
-            try {
-                doc = DOMUtils.readXml(is);
-            } catch (Exception ex) {
-                throw new PolicyException(ex);
+            InputStream is = location.getInputStream();
+            if (null == is) {
+                throw new PolicyException(new Message("COULD_NOT_OPEN_ATTACHMENT_DOC_EXC", BUNDLE, location));
             }
+            doc = DOMUtils.readXml(is);
         } catch (Exception ex) {
             throw new PolicyException(ex);
         }

Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/Messages.properties?view=diff&rev=510614&r1=510613&r2=510614
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/Messages.properties (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/Messages.properties Thu Feb 22 10:28:42 2007
@@ -20,4 +20,5 @@
 #
 NO_DOMAINEXPRESSIONBUILDER_EXC = No domain expresssion builder for type {0} registered.
 EPR_DOMAIN_EXPRESSION_BUILD_EXC = Failed to build endpoint reference type domain expression.  
-EPR_DOMAIN_EXPRESSION_BUILDER_INIT_EXC = Failed to initialise endpoint reference type domain expression builder.
\ No newline at end of file
+EPR_DOMAIN_EXPRESSION_BUILDER_INIT_EXC = Failed to initialise endpoint reference type domain expression builder.
+COULD_NOT_OPEN_ATTACHMENT_DOC_EXC = Could not open policy attachment document {0}.
\ No newline at end of file

Modified: incubator/cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/cxf-extension-policy.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/cxf-extension-policy.xml?view=diff&rev=510614&r1=510613&r2=510614
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/cxf-extension-policy.xml (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/cxf-extension-policy.xml Thu Feb 22 10:28:42 2007
@@ -38,13 +38,25 @@
               <property name="idsProperty" value="assertionTypes"/>
             </bean>
         </constructor-arg>
-    </bean>
-
+    </bean>   
+    
+    <bean id="org.apache.cxf.ws.policy.attachment.external.DomainExpressionBuilderRegistry" 
+          class="org.apache.cxf.ws.policy.attachment.external.DomainExpressionBuilderRegistry">
+        <constructor-arg>
+            <bean class="org.apache.cxf.configuration.spring.SpringBeanQNameMap">
+              <property name="type" value="org.apache.cxf.ws.policy.attachment.external.DomainExpressionBuilder"/>
+              <property name="idsProperty" value="domainExpressionTypes"/>
+            </bean>
+        </constructor-arg>
+    </bean>   
+    
+    <bean class="org.apache.cxf.ws.policy.attachment.external.EndpointReferenceDomainExpressionBuilder"/> 
+    
     <bean id="org.apache.cxf.ws.policy.PolicyBuilder" class="org.apache.cxf.ws.policy.PolicyBuilderImpl">
         <property name="assertionBuilderRegistry" ref="org.apache.cxf.ws.policy.AssertionBuilderRegistry"/>
     </bean>
   
-    <bean class="org.apache.cxf.ws.policy.spring.InitializingPolicyEngine">
+    <bean id="org.apache.cxf.ws.policy.PolicyEngine" class="org.apache.cxf.ws.policy.spring.InitializingPolicyEngine">
        <property name="bus" ref="cxf"/>
     </bean>
     

Added: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java?view=auto&rev=510614
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java Thu Feb 22 10:28:42 2007
@@ -0,0 +1,420 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.ws.policy;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.phase.PhaseInterceptor;
+import org.apache.cxf.service.model.BindingFaultInfo;
+import org.apache.cxf.service.model.BindingMessageInfo;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.transport.Conduit;
+import org.apache.cxf.transport.Destination;
+import org.apache.neethi.Policy;
+import org.apache.neethi.PolicyRegistry;
+import org.easymock.classextension.EasyMock;
+import org.easymock.classextension.IMocksControl;
+
+/**
+ * 
+ */
+public class PolicyEngineTest extends TestCase {
+
+    private IMocksControl control;
+    private PolicyEngine engine;
+    
+    public void setUp() {
+        control = EasyMock.createNiceControl(); 
+    } 
+    
+    public void testAccessors() {
+        engine = new PolicyEngine();
+        assertNotNull(engine.getRegistry());
+        assertNull(engine.getBus());
+        assertNull(engine.getPolicyProviders()); 
+        assertTrue(!engine.getRegisterInterceptors());
+        Bus bus = control.createMock(Bus.class);
+        engine.setBus(bus);
+        List<PolicyProvider> providers = CastUtils.cast(Collections.EMPTY_LIST, PolicyProvider.class);
+        engine.setPolicyProviders(providers);
+        PolicyRegistry reg = control.createMock(PolicyRegistry.class);
+        engine.setRegistry(reg);
+        engine.setRegisterInterceptors(true);
+        assertSame(bus, engine.getBus());
+        assertSame(providers, engine.getPolicyProviders());
+        assertSame(reg, engine.getRegistry());
+        assertTrue(engine.getRegisterInterceptors());
+    }
+    
+    public void testDontAddBusInterceptors() {        
+        doTestAddBusInterceptors(false);
+    }
+    
+    public void testAddBusInterceptors() {        
+        doTestAddBusInterceptors(true);
+    }
+    
+    private void doTestAddBusInterceptors(boolean add) {        
+        engine = new PolicyEngine();
+        engine.setRegisterInterceptors(add);
+    
+        Bus bus = control.createMock(Bus.class);
+        engine.setBus(bus);
+        List<Interceptor> out = new ArrayList<Interceptor>();
+        List<Interceptor> in = new ArrayList<Interceptor>();
+        List<Interceptor> inFault = new ArrayList<Interceptor>();
+        List<Interceptor> outFault = new ArrayList<Interceptor>();
+        if (add) {
+            EasyMock.expect(bus.getOutInterceptors()).andReturn(out).times(2);
+            EasyMock.expect(bus.getInInterceptors()).andReturn(in).times(2);
+            EasyMock.expect(bus.getInFaultInterceptors()).andReturn(inFault);
+            EasyMock.expect(bus.getOutFaultInterceptors()).andReturn(outFault);
+            control.replay();
+        }
+        
+        engine.addBusInterceptors();
+        
+        if (add) {
+            Set<String> idsOut = getInterceptorIds(out);
+            Set<String> idsIn = getInterceptorIds(in);
+            Set<String> idsInFault = getInterceptorIds(inFault);
+            Set<String> idsOutFault = getInterceptorIds(outFault);
+            assertEquals(2, out.size());
+            assertTrue(idsOut.contains(PolicyConstants.CLIENT_POLICY_OUT_INTERCEPTOR_ID));
+            assertTrue(idsOut.contains(PolicyConstants.SERVER_POLICY_OUT_INTERCEPTOR_ID));
+            assertEquals(2, in.size());
+            assertTrue(idsIn.contains(PolicyConstants.CLIENT_POLICY_IN_INTERCEPTOR_ID));
+            assertTrue(idsIn.contains(PolicyConstants.SERVER_POLICY_IN_INTERCEPTOR_ID));
+            assertEquals(1, inFault.size());
+            assertTrue(idsInFault.contains(PolicyConstants.CLIENT_POLICY_IN_FAULT_INTERCEPTOR_ID));
+            assertEquals(1, outFault.size());
+            assertTrue(idsOutFault.contains(PolicyConstants.SERVER_POLICY_OUT_FAULT_INTERCEPTOR_ID));
+        } else {
+            assertEquals(0, out.size());
+            assertEquals(0, in.size());
+            assertEquals(0, inFault.size());
+            assertEquals(0, outFault.size());
+        }
+        if (add) {
+            control.verify();
+        }
+    }
+    
+    public void testGetAggregatedServicePolicy() {
+        engine = new PolicyEngine();
+        List<PolicyProvider> providers = new ArrayList<PolicyProvider>();
+        engine.setPolicyProviders(providers);
+        ServiceInfo si = control.createMock(ServiceInfo.class);
+        
+        control.replay();
+        Policy p = engine.getAggregatedServicePolicy(si);
+        assertTrue(p.isEmpty());
+        control.verify();
+        control.reset();
+        
+        PolicyProvider provider1 = control.createMock(PolicyProvider.class);
+        providers.add(provider1);
+        Policy p1 = control.createMock(Policy.class);
+        EasyMock.expect(provider1.getEffectivePolicy(si)).andReturn(p1);
+        
+        control.replay();
+        assertSame(p1, engine.getAggregatedServicePolicy(si));
+        control.verify();
+        control.reset();
+        
+        PolicyProvider provider2 = control.createMock(PolicyProvider.class);
+        providers.add(provider2);
+        Policy p2 = control.createMock(Policy.class);
+        Policy p3 = control.createMock(Policy.class);
+        EasyMock.expect(provider1.getEffectivePolicy(si)).andReturn(p1);
+        EasyMock.expect(provider2.getEffectivePolicy(si)).andReturn(p2);
+        EasyMock.expect(p1.merge(p2)).andReturn(p3);
+        
+        control.replay();
+        assertSame(p3, engine.getAggregatedServicePolicy(si));
+        control.verify();      
+    }
+    
+    public void testGetAggregatedEndpointPolicy() {
+        engine = new PolicyEngine();
+        List<PolicyProvider> providers = new ArrayList<PolicyProvider>();
+        engine.setPolicyProviders(providers);
+        EndpointInfo ei = control.createMock(EndpointInfo.class);
+        
+        control.replay();
+        Policy p = engine.getAggregatedEndpointPolicy(ei);
+        assertTrue(p.isEmpty());
+        control.verify();
+        control.reset();
+        
+        PolicyProvider provider1 = control.createMock(PolicyProvider.class);
+        providers.add(provider1);
+        Policy p1 = control.createMock(Policy.class);
+        EasyMock.expect(provider1.getEffectivePolicy(ei)).andReturn(p1);
+        
+        control.replay();
+        assertSame(p1, engine.getAggregatedEndpointPolicy(ei));
+        control.verify();
+        control.reset();
+        
+        PolicyProvider provider2 = control.createMock(PolicyProvider.class);
+        providers.add(provider2);
+        Policy p2 = control.createMock(Policy.class);
+        Policy p3 = control.createMock(Policy.class);
+        EasyMock.expect(provider1.getEffectivePolicy(ei)).andReturn(p1);
+        EasyMock.expect(provider2.getEffectivePolicy(ei)).andReturn(p2);
+        EasyMock.expect(p1.merge(p2)).andReturn(p3);
+        
+        control.replay();
+        assertSame(p3, engine.getAggregatedEndpointPolicy(ei));
+        control.verify();      
+    }
+    
+    public void testGetAggregatedOperationPolicy() {
+        engine = new PolicyEngine();
+        List<PolicyProvider> providers = new ArrayList<PolicyProvider>();
+        engine.setPolicyProviders(providers);
+        BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
+        
+        control.replay();
+        Policy p = engine.getAggregatedOperationPolicy(boi);
+        assertTrue(p.isEmpty());
+        control.verify();
+        control.reset();
+        
+        PolicyProvider provider1 = control.createMock(PolicyProvider.class);
+        providers.add(provider1);
+        Policy p1 = control.createMock(Policy.class);
+        EasyMock.expect(provider1.getEffectivePolicy(boi)).andReturn(p1);
+        
+        control.replay();
+        assertSame(p1, engine.getAggregatedOperationPolicy(boi));
+        control.verify();
+        control.reset();
+        
+        PolicyProvider provider2 = control.createMock(PolicyProvider.class);
+        providers.add(provider2);
+        Policy p2 = control.createMock(Policy.class);
+        Policy p3 = control.createMock(Policy.class);
+        EasyMock.expect(provider1.getEffectivePolicy(boi)).andReturn(p1);
+        EasyMock.expect(provider2.getEffectivePolicy(boi)).andReturn(p2);
+        EasyMock.expect(p1.merge(p2)).andReturn(p3);
+        
+        control.replay();
+        assertSame(p3, engine.getAggregatedOperationPolicy(boi));
+        control.verify();      
+    }
+    
+    public void testGetAggregatedMessagePolicy() {
+        engine = new PolicyEngine();
+        List<PolicyProvider> providers = new ArrayList<PolicyProvider>();
+        engine.setPolicyProviders(providers);
+        BindingMessageInfo bmi = control.createMock(BindingMessageInfo.class);
+        
+        control.replay();
+        Policy p = engine.getAggregatedMessagePolicy(bmi);
+        assertTrue(p.isEmpty());
+        control.verify();
+        control.reset();
+        
+        PolicyProvider provider1 = control.createMock(PolicyProvider.class);
+        providers.add(provider1);
+        Policy p1 = control.createMock(Policy.class);
+        EasyMock.expect(provider1.getEffectivePolicy(bmi)).andReturn(p1);
+        
+        control.replay();
+        assertSame(p1, engine.getAggregatedMessagePolicy(bmi));
+        control.verify();
+        control.reset();
+        
+        PolicyProvider provider2 = control.createMock(PolicyProvider.class);
+        providers.add(provider2);
+        Policy p2 = control.createMock(Policy.class);
+        Policy p3 = control.createMock(Policy.class);
+        EasyMock.expect(provider1.getEffectivePolicy(bmi)).andReturn(p1);
+        EasyMock.expect(provider2.getEffectivePolicy(bmi)).andReturn(p2);
+        EasyMock.expect(p1.merge(p2)).andReturn(p3);
+        
+        control.replay();
+        assertSame(p3, engine.getAggregatedMessagePolicy(bmi));
+        control.verify();      
+    }
+    
+    public void testGetAggregatedFaultPolicy() {
+        engine = new PolicyEngine();
+        List<PolicyProvider> providers = new ArrayList<PolicyProvider>();
+        engine.setPolicyProviders(providers);
+        BindingFaultInfo bfi = control.createMock(BindingFaultInfo.class);
+        
+        control.replay();
+        Policy p = engine.getAggregatedFaultPolicy(bfi);
+        assertTrue(p.isEmpty());
+        control.verify();
+        control.reset();
+        
+        PolicyProvider provider1 = control.createMock(PolicyProvider.class);
+        providers.add(provider1);
+        Policy p1 = control.createMock(Policy.class);
+        EasyMock.expect(provider1.getEffectivePolicy(bfi)).andReturn(p1);
+        
+        control.replay();
+        assertSame(p1, engine.getAggregatedFaultPolicy(bfi));
+        control.verify();
+        control.reset();
+        
+        PolicyProvider provider2 = control.createMock(PolicyProvider.class);
+        providers.add(provider2);
+        Policy p2 = control.createMock(Policy.class);
+        Policy p3 = control.createMock(Policy.class);
+        EasyMock.expect(provider1.getEffectivePolicy(bfi)).andReturn(p1);
+        EasyMock.expect(provider2.getEffectivePolicy(bfi)).andReturn(p2);
+        EasyMock.expect(p1.merge(p2)).andReturn(p3);
+        
+        control.replay();
+        assertSame(p3, engine.getAggregatedFaultPolicy(bfi));
+        control.verify();      
+    }
+    
+    public void testGetClientOutInterceptors() throws NoSuchMethodException {
+        Method m = PolicyEngine.class.getDeclaredMethod("getClientRequestPolicyInfo",
+                                                        new Class[] {Endpoint.class,
+                                                                     BindingOperationInfo.class,
+                                                                     Conduit.class});
+        engine = control.createMock(PolicyEngine.class, new Method[] {m});
+        BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
+        Endpoint e = control.createMock(Endpoint.class);
+        Conduit conduit = control.createMock(Conduit.class);
+        ClientRequestPolicyInfo cpi = control.createMock(ClientRequestPolicyInfo.class);
+        EasyMock.expect(engine.getClientRequestPolicyInfo(e, boi, conduit)).andReturn(cpi);
+        Interceptor i = control.createMock(Interceptor.class);
+        List<Interceptor> li = Collections.singletonList(i);
+        EasyMock.expect(cpi.getOutInterceptors()).andReturn(li);        
+
+        control.replay();
+        List<Interceptor> clientInterceptors = engine.getClientOutInterceptors(e, boi, conduit); 
+        assertSame(li, clientInterceptors);
+        control.verify();
+    }
+    
+    public void testGetClientInInterceptors() throws NoSuchMethodException { 
+        doTestGetInterceptors(false, false);
+    }
+    
+    public void testGetClientInFaultInterceptors() throws NoSuchMethodException { 
+        doTestGetInterceptors(false, true);
+    }
+    
+    public void testGetServerInFaultInterceptors() throws NoSuchMethodException { 
+        doTestGetInterceptors(true, false);
+    }
+    
+    public void testServerOutInterceptors() throws NoSuchMethodException {
+        doTestGetServerOutInterceptors(false);
+    }
+    
+    public void testServerOutFaultInterceptors() throws NoSuchMethodException {
+        doTestGetServerOutInterceptors(true);
+    }
+     
+    private void doTestGetInterceptors(boolean isServer, boolean fault) throws NoSuchMethodException {
+        Method m = PolicyEngine.class.getDeclaredMethod("getEndpointPolicyInfo",
+            new Class[] {Endpoint.class, isServer ? Destination.class : Conduit.class});
+        engine = control.createMock(PolicyEngine.class, new Method[] {m});
+        Endpoint e = control.createMock(Endpoint.class);
+        Conduit conduit = null;
+        Destination destination = null;
+        EndpointPolicyInfo epi = control.createMock(EndpointPolicyInfo.class);
+        
+        if (isServer) {
+            destination = control.createMock(Destination.class);
+            EasyMock.expect(engine.getEndpointPolicyInfo(e, destination)).andReturn(epi);
+        } else {
+            conduit = control.createMock(Conduit.class);
+            EasyMock.expect(engine.getEndpointPolicyInfo(e, conduit)).andReturn(epi);
+        }
+        
+        Interceptor i = control.createMock(Interceptor.class);
+        List<Interceptor> li = Collections.singletonList(i);
+        if (fault) {
+            EasyMock.expect(epi.getInFaultInterceptors()).andReturn(li); 
+        } else {
+            EasyMock.expect(epi.getInInterceptors()).andReturn(li);  
+        }
+
+        control.replay();
+        List<Interceptor> interceptors = fault 
+            ? engine.getClientInFaultInterceptors(e, conduit) 
+            : (isServer 
+                ? engine.getServerInInterceptors(e, destination)
+                : engine.getClientInInterceptors(e, conduit));
+        assertSame(li, interceptors);
+        control.verify(); 
+    }
+    
+    private void doTestGetServerOutInterceptors(boolean fault) throws NoSuchMethodException {
+
+        Method m = PolicyEngine.class.getDeclaredMethod("getServerResponsePolicyInfo",
+                                                        new Class[] {Endpoint.class,
+                                                                     BindingOperationInfo.class,
+                                                                     Destination.class});
+        engine = control.createMock(PolicyEngine.class, new Method[] {m});
+        BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
+        Endpoint e = control.createMock(Endpoint.class);
+        Destination destination = control.createMock(Destination.class);
+        ServerResponsePolicyInfo srpi = control.createMock(ServerResponsePolicyInfo.class);
+        EasyMock.expect(engine.getServerResponsePolicyInfo(e, boi, destination)).andReturn(srpi);
+        Interceptor i = control.createMock(Interceptor.class);
+        List<Interceptor> li = Collections.singletonList(i);
+        if (fault) {
+            EasyMock.expect(srpi.getOutFaultInterceptors()).andReturn(li);
+        } else {
+            EasyMock.expect(srpi.getOutInterceptors()).andReturn(li);
+        }
+
+        control.replay();
+        List<Interceptor> interceptors = fault ? engine.getServerOutFaultInterceptors(e, boi, destination)
+            : engine.getServerOutInterceptors(e, boi, destination);
+        assertSame(li, interceptors);
+        control.verify();
+    }
+    
+    private Set<String> getInterceptorIds(List<Interceptor> interceptors) {
+        Set<String> ids = new HashSet<String>();
+        for (Interceptor i : interceptors) {
+            ids.add(((PhaseInterceptor)i).getId());
+        }
+        return ids;
+    }
+    
+    
+}

Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyExtensionsTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyExtensionsTest.java?view=diff&rev=510614&r1=510613&r2=510614
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyExtensionsTest.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyExtensionsTest.java Thu Feb 22 10:28:42 2007
@@ -32,6 +32,9 @@
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.bus.spring.SpringBusFactory;
 import org.apache.cxf.interceptor.AbstractAttributedInterceptorProvider;
+import org.apache.cxf.ws.policy.attachment.external.DomainExpressionBuilder;
+import org.apache.cxf.ws.policy.attachment.external.DomainExpressionBuilderRegistry;
+import org.apache.cxf.ws.policy.attachment.external.ExternalAttachmentProvider;
 import org.apache.cxf.ws.policy.attachment.wsdl11.Wsdl11AttachmentPolicyProvider;
 import org.apache.neethi.Assertion;
 
@@ -41,6 +44,9 @@
 public class PolicyExtensionsTest extends TestCase {
 
     private static final QName KNOWN = new QName("http://cxf.apache.org/test/policy", "known");
+    private static final QName KNOWN_DOMAIN_EXPR_TYPE
+        = new QName("http://www.w3.org/2005/08/addressing", "EndpointReference");
+    
     private static final QName UNKNOWN = new QName("http://cxf.apache.org/test/policy", "unknown");
     
     public void testExtensions() {
@@ -63,16 +69,32 @@
             pip = pipr.get(UNKNOWN);
             assertNull(pip);
             
+            DomainExpressionBuilderRegistry debr = bus.getExtension(DomainExpressionBuilderRegistry.class);
+            assertNotNull(debr);
+            DomainExpressionBuilder deb = debr.get(KNOWN_DOMAIN_EXPR_TYPE);
+            assertNotNull(deb);
+            deb = debr.get(UNKNOWN);
+            assertNull(deb);
+            
             PolicyEngine engine = bus.getExtension(PolicyEngine.class);
             assertNotNull(engine);            
             assertNotNull(engine.getPolicyProviders());
             assertNotNull(engine.getRegistry());
             
             Collection<PolicyProvider> pps = engine.getPolicyProviders();
-            assertEquals(1, pps.size());
+            assertEquals(2, pps.size());
+            boolean wsdlProvider = false;
+            boolean externalProvider = false;
             for (PolicyProvider pp : pps) {
-                assertTrue(pp instanceof Wsdl11AttachmentPolicyProvider);
+                if (pp instanceof Wsdl11AttachmentPolicyProvider) {
+                    wsdlProvider = true;
+                } else if (pp instanceof ExternalAttachmentProvider) {
+                    externalProvider = true;
+                }
             }
+            assertTrue(wsdlProvider);
+            assertTrue(externalProvider);
+            
             
             PolicyBuilder builder = bus.getExtension(PolicyBuilder.class);
             assertNotNull(builder);



Mime
View raw message