cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1233348 - in /cxf/trunk: api/src/main/java/org/apache/cxf/policy/ rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/ rt/transports/http/ rt/transports/http/src/main/java/org/apache/cxf/transport/http/ rt/transports...
Date Thu, 19 Jan 2012 13:07:52 GMT
Author: cschneider
Date: Thu Jan 19 13:07:51 2012
New Revision: 1233348

URL: http://svn.apache.org/viewvc?rev=1233348&view=rev
Log:
CXF-4032 Making http conduit and destination independent of ws policy

Added:
    cxf/trunk/api/src/main/java/org/apache/cxf/policy/
    cxf/trunk/api/src/main/java/org/apache/cxf/policy/PolicyCalculator.java
    cxf/trunk/api/src/main/java/org/apache/cxf/policy/PolicyDataEngine.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/impl/
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/impl/ClientPolicyCalculator.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/impl/ServerPolicyCalculator.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/impl/StringUtils.java
    cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/ClientPolicyCalculatorTest.java
    cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/ServerPolicyCalculatorTest.java
    cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyDataEngineImpl.java
    cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyDataEngineImplTest.java
Removed:
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/PolicyUtils.java
Modified:
    cxf/trunk/rt/transports/http/   (props changed)
    cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/HTTPClientAssertionBuilder.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/HTTPServerAssertionBuilder.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/Messages.properties
    cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/HTTPClientAssertionBuilderTest.java
    cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/HTTPServerAssertionBuilderTest.java
    cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/PolicyUtilsTest.java
    cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/bus-extensions.txt
    cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/PolicyLoggingInterceptor.java

Added: cxf/trunk/api/src/main/java/org/apache/cxf/policy/PolicyCalculator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/policy/PolicyCalculator.java?rev=1233348&view=auto
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/policy/PolicyCalculator.java (added)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/policy/PolicyCalculator.java Thu Jan 19 13:07:51 2012
@@ -0,0 +1,33 @@
+/**
+ * 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.policy;
+
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.message.Message;
+
+public interface PolicyCalculator<T> {
+    Class<T> getDataClass();
+    
+    QName getDataClassName();
+    
+    T intersect(T policy1, T policy2);
+
+    boolean isAsserted(Message message, T policy, T refPolicy);
+}

Added: cxf/trunk/api/src/main/java/org/apache/cxf/policy/PolicyDataEngine.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/policy/PolicyDataEngine.java?rev=1233348&view=auto
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/policy/PolicyDataEngine.java (added)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/policy/PolicyDataEngine.java Thu Jan 19 13:07:51 2012
@@ -0,0 +1,34 @@
+/**
+ * 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.policy;
+
+import org.apache.cxf.message.Message;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.Conduit;
+import org.apache.cxf.transport.Destination;
+
+public interface PolicyDataEngine {
+    <T> T getPolicy(Message message, T confPolicy, PolicyCalculator<T> intersector);
+
+    <T> T getClientEndpointPolicy(EndpointInfo ei, Conduit c, PolicyCalculator<T> policyCalculator);
+
+    <T> T getServerEndpointPolicy(EndpointInfo ei, Destination d, PolicyCalculator<T> policyCalculator);
+
+    <T> void assertMessage(Message message, T confPol, PolicyCalculator<T> policyCalculator);
+}

Propchange: cxf/trunk/rt/transports/http/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Thu Jan 19 13:07:51 2012
@@ -14,3 +14,5 @@ eclipse-classes
 *.ipr
 *.iml
 *.iws
+
+.externalToolBuilders

Modified: cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java?rev=1233348&r1=1233347&r2=1233348&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java (original)
+++ cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java Thu Jan 19 13:07:51 2012
@@ -51,6 +51,7 @@ import org.apache.cxf.io.AbstractWrapped
 import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.policy.PolicyDataEngine;
 import org.apache.cxf.security.transport.TLSSessionInfo;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.service.model.ServiceInfo;
@@ -570,6 +571,8 @@ public class JettyHTTPDestinationTest ex
             bus = EasyMock.createMock(Bus.class);
             bus.getExtension(EndpointResolverRegistry.class);
             EasyMock.expectLastCall().andReturn(null);
+            bus.getExtension(PolicyDataEngine.class);
+            EasyMock.expectLastCall().andReturn(null).anyTimes();
             bus.hasExtensionByName("org.apache.cxf.ws.policy.PolicyEngine");
             EasyMock.expectLastCall().andReturn(false);
             bus.getExtension(ClassLoader.class);

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java?rev=1233348&r1=1233347&r2=1233348&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java Thu Jan 19 13:07:51 2012
@@ -60,13 +60,14 @@ import org.apache.cxf.message.ExchangeIm
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.message.MessageUtils;
+import org.apache.cxf.policy.PolicyDataEngine;
 import org.apache.cxf.security.SecurityContext;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.AbstractDestination;
 import org.apache.cxf.transport.AbstractMultiplexDestination;
 import org.apache.cxf.transport.Assertor;
 import org.apache.cxf.transport.Conduit;
-import org.apache.cxf.transport.http.policy.PolicyUtils;
+import org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator;
 import org.apache.cxf.transport.https.CertConstraints;
 import org.apache.cxf.transport.https.CertConstraintsInterceptor;
 import org.apache.cxf.transport.https.SSLUtils;
@@ -419,8 +420,9 @@ public abstract class AbstractHTTPDestin
     }
 
     private void initConfig() {
-        if (bus.hasExtensionByName("org.apache.cxf.ws.policy.PolicyEngine")) {
-            server = PolicyUtils.getServer(bus, endpointInfo, this);
+        PolicyDataEngine pde = bus.getExtension(PolicyDataEngine.class);
+        if (pde != null) {
+            server = pde.getServerEndpointPolicy(endpointInfo, this, new ServerPolicyCalculator());
         }
         if (null == server && WSDLLibrary.isAvailable()) {
             server = endpointInfo.getTraversedExtensor(
@@ -768,11 +770,12 @@ public abstract class AbstractHTTPDestin
     }
     
     public void assertMessage(Message message) {
-        PolicyUtils.assertServerPolicy(message, server); 
+        PolicyDataEngine pde = bus.getExtension(PolicyDataEngine.class);
+        pde.assertMessage(message, server, new ServerPolicyCalculator());
     }
 
     public boolean canAssert(QName type) {
-        return PolicyUtils.HTTPSERVERPOLICY_ASSERTION_QNAME.equals(type); 
+        return new ServerPolicyCalculator().getDataClassName().equals(type); 
     }
     
     public void releaseRegistry() {

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java?rev=1233348&r1=1233347&r2=1233348&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java Thu Jan 19 13:07:51 2012
@@ -67,6 +67,7 @@ import org.apache.cxf.message.MessageCon
 import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.message.MessageUtils;
 import org.apache.cxf.phase.PhaseInterceptorChain;
+import org.apache.cxf.policy.PolicyDataEngine;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.AbstractConduit;
 import org.apache.cxf.transport.Assertor;
@@ -76,7 +77,7 @@ import org.apache.cxf.transport.http.aut
 import org.apache.cxf.transport.http.auth.HttpAuthHeader;
 import org.apache.cxf.transport.http.auth.HttpAuthSupplier;
 import org.apache.cxf.transport.http.auth.SpnegoAuthSupplier;
-import org.apache.cxf.transport.http.policy.PolicyUtils;
+import org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator;
 import org.apache.cxf.transport.https.CertConstraints;
 import org.apache.cxf.transport.https.CertConstraintsInterceptor;
 import org.apache.cxf.transport.https.CertConstraintsJaxBUtils;
@@ -300,18 +301,27 @@ public class HTTPConduit 
         proxyFactory = new ProxyFactory();
         connectionFactory = new HttpsURLConnectionFactory();
         cookies = new Cookies();
-        
-        // wsdl extensors are superseded by policies which in        
-        // turn are superseded by injection                          
-        if (bus.hasExtensionByName("org.apache.cxf.ws.policy.PolicyEngine")
-            && endpointInfo.getService() != null) {                         
-            clientSidePolicy =                                       
-                PolicyUtils.getClient(bus, endpointInfo, this);              
-        }
+        updateClientPolicy();
         CXFAuthenticator.addAuthenticator();
     }
 
     /**
+     * updates the HTTPClientPolicy that is compatible with the assertions
+     * included in the service, endpoint, operation and message policy subjects
+     * if a PolicyDataEngine is installed
+     * 
+     * wsdl extensors are superseded by policies which in 
+     * turn are superseded by injection
+     */
+    private void updateClientPolicy() {
+        PolicyDataEngine policyEngine = bus.getExtension(PolicyDataEngine.class);
+        if (policyEngine != null && endpointInfo.getService() != null) {
+            clientSidePolicy = policyEngine.getClientEndpointPolicy(endpointInfo, 
+                                                                    this, new ClientPolicyCalculator());
+        }
+    }
+
+    /**
      * This method returns the registered Logger for this conduit.
      */
     protected Logger getLogger() {
@@ -838,7 +848,17 @@ public class HTTPConduit 
     }
     
     public HTTPClientPolicy getClient(Message message) {
-        return PolicyUtils.getClient(message, clientSidePolicy);
+        ClientPolicyCalculator cpc = new ClientPolicyCalculator();
+        HTTPClientPolicy messagePol = message.get(HTTPClientPolicy.class);
+        if (messagePol != null) {
+            return cpc.intersect(messagePol, clientSidePolicy);
+        }
+
+        PolicyDataEngine policyDataEngine = bus.getExtension(PolicyDataEngine.class);
+        if (policyDataEngine == null) {
+            return clientSidePolicy;
+        }
+        return policyDataEngine.getPolicy(message, clientSidePolicy, cpc);
     }
 
     /**
@@ -1688,11 +1708,12 @@ public class HTTPConduit 
     }
     
     public void assertMessage(Message message) {
-        PolicyUtils.assertClientPolicy(message, clientSidePolicy);
+        PolicyDataEngine policyDataEngine = bus.getExtension(PolicyDataEngine.class);
+        policyDataEngine.assertMessage(message, getClient(), new ClientPolicyCalculator());
     }
     
     public boolean canAssert(QName type) {
-        return PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME.equals(type);  
+        return new ClientPolicyCalculator().equals(type);  
     }
 
     public void propertyChange(PropertyChangeEvent evt) {

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/HTTPClientAssertionBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/HTTPClientAssertionBuilder.java?rev=1233348&r1=1233347&r2=1233348&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/HTTPClientAssertionBuilder.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/HTTPClientAssertionBuilder.java Thu Jan 19 13:07:51 2012
@@ -26,6 +26,7 @@ import javax.xml.bind.JAXBException;
 import javax.xml.namespace.QName;
 
 import org.apache.cxf.common.injection.NoJSR250Annotations;
+import org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator;
 import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
 import org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion;
 import org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertionBuilder;
@@ -39,10 +40,10 @@ import org.apache.neethi.PolicyComponent
 @NoJSR250Annotations
 public class HTTPClientAssertionBuilder extends JaxbAssertionBuilder<HTTPClientPolicy> {
     public static final List<QName> KNOWN_ELEMENTS 
-        = Collections.singletonList(PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME);
+        = Collections.singletonList(new ClientPolicyCalculator().getDataClassName());
 
     public HTTPClientAssertionBuilder() throws JAXBException {
-        super(HTTPClientPolicy.class, PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME);     
+        super(HTTPClientPolicy.class, new ClientPolicyCalculator().getDataClassName());     
     }
 
     @Override
@@ -52,7 +53,7 @@ public class HTTPClientAssertionBuilder 
     
     class HTTPClientPolicyAssertion extends JaxbAssertion<HTTPClientPolicy> {
         HTTPClientPolicyAssertion() {
-            super(PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME, false);
+            super(new ClientPolicyCalculator().getDataClassName(), false);
         }
 
         @Override
@@ -65,7 +66,7 @@ public class HTTPClientAssertionBuilder 
                 return false;
             }
             JaxbAssertion<HTTPClientPolicy> other = JaxbAssertion.cast((Assertion)policyComponent);
-            return PolicyUtils.equals(this.getData(), other.getData());  
+            return new ClientPolicyCalculator().equals(this.getData(), other.getData());  
         }
         
         @Override

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/HTTPServerAssertionBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/HTTPServerAssertionBuilder.java?rev=1233348&r1=1233347&r2=1233348&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/HTTPServerAssertionBuilder.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/HTTPServerAssertionBuilder.java Thu Jan 19 13:07:51 2012
@@ -26,6 +26,7 @@ import javax.xml.bind.JAXBException;
 import javax.xml.namespace.QName;
 
 import org.apache.cxf.common.injection.NoJSR250Annotations;
+import org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator;
 import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
 import org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion;
 import org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertionBuilder;
@@ -39,10 +40,10 @@ import org.apache.neethi.PolicyComponent
 @NoJSR250Annotations
 public class HTTPServerAssertionBuilder extends JaxbAssertionBuilder<HTTPServerPolicy> {
     public static final List<QName> KNOWN_ELEMENTS 
-        = Collections.singletonList(PolicyUtils.HTTPSERVERPOLICY_ASSERTION_QNAME);
+        = Collections.singletonList(new ServerPolicyCalculator().getDataClassName());
 
     public HTTPServerAssertionBuilder() throws JAXBException {
-        super(HTTPServerPolicy.class, PolicyUtils.HTTPSERVERPOLICY_ASSERTION_QNAME);        
+        super(HTTPServerPolicy.class, new ServerPolicyCalculator().getDataClassName());        
     }
     
     @Override
@@ -52,7 +53,7 @@ public class HTTPServerAssertionBuilder 
     
     class HTTPServerPolicyAssertion extends JaxbAssertion<HTTPServerPolicy> {
         HTTPServerPolicyAssertion() {
-            super(PolicyUtils.HTTPSERVERPOLICY_ASSERTION_QNAME, false);            
+            super(new ServerPolicyCalculator().getDataClassName(), false);            
         }
 
         @Override
@@ -65,7 +66,7 @@ public class HTTPServerAssertionBuilder 
                 return false;
             }
             JaxbAssertion<HTTPServerPolicy> other = JaxbAssertion.cast((Assertion)policyComponent);
-            return PolicyUtils.equals(this.getData(), other.getData());  
+            return new ServerPolicyCalculator().equals(this.getData(), other.getData());  
         }
         
         @Override

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/Messages.properties
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/Messages.properties?rev=1233348&r1=1233347&r2=1233348&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/Messages.properties (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/Messages.properties Thu Jan 19 13:07:51 2012
@@ -18,5 +18,4 @@
 #    under the License.
 #
 #
-INCOMPATIBLE_HTTPCLIENTPOLICY_ASSERTIONS = Incompatible HTTPClientPolicy assertions.
-INCOMPATIBLE_HTTPSERVERPOLICY_ASSERTIONS = Incompatible HTTPServerPolicy assertions.
+INCOMPATIBLE_POLICY_ASSERTIONS = Incompatible Policy assertions of type %s.

Added: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/impl/ClientPolicyCalculator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/impl/ClientPolicyCalculator.java?rev=1233348&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/impl/ClientPolicyCalculator.java (added)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/impl/ClientPolicyCalculator.java Thu Jan 19 13:07:51 2012
@@ -0,0 +1,262 @@
+/**
+ * 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.transport.http.policy.impl;
+
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageUtils;
+import org.apache.cxf.policy.PolicyCalculator;
+import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
+import org.apache.cxf.transports.http.configuration.ObjectFactory;
+
+public class ClientPolicyCalculator implements PolicyCalculator<HTTPClientPolicy> {
+
+
+    /**
+     * Determines if two HTTPClientPolicy objects are equal. REVISIT: Check if
+     * this can be replaced by a generated equals method.
+     * 
+     * @param p1 one client policy
+     * @param p2 another client policy
+     * @return true iff the two policies are equal
+     */
+    public boolean equals(HTTPClientPolicy p1, HTTPClientPolicy p2) {
+        if (p1 == p2) {
+            return true;
+        }
+        boolean result = true;
+        result &= (p1.isAllowChunking() == p2.isAllowChunking())
+                  && (p1.isAutoRedirect() == p2.isAutoRedirect())
+                  && StringUtils.equals(p1.getAccept(), p2.getAccept())
+                  && StringUtils.equals(p1.getAcceptEncoding(), p2.getAcceptEncoding())
+                  && StringUtils.equals(p1.getAcceptLanguage(), p2.getAcceptLanguage())
+                  && StringUtils.equals(p1.getBrowserType(), p2.getBrowserType());
+        if (!result) {
+            return false;
+        }
+
+        result &= (p1.getCacheControl() == null ? p2.getCacheControl() == null : p1.getCacheControl()
+            .equals(p2.getCacheControl()) && p1.getConnection().value().equals(p2.getConnection().value()))
+                  && (p1.getConnectionTimeout() == p2.getConnectionTimeout())
+                  && StringUtils.equals(p1.getContentType(), p2.getContentType())
+                  && StringUtils.equals(p1.getCookie(), p2.getCookie())
+                  && StringUtils.equals(p1.getDecoupledEndpoint(), p2.getDecoupledEndpoint())
+                  && StringUtils.equals(p1.getHost(), p2.getHost());
+        if (!result) {
+            return false;
+        }
+
+        result &= StringUtils.equals(p1.getProxyServer(), p2.getProxyServer())
+                  && (p1.isSetProxyServerPort() ? p1.getProxyServerPort() == p2.getProxyServerPort() : !p2
+                      .isSetProxyServerPort())
+                  && p1.getProxyServerType().value().equals(p2.getProxyServerType().value())
+                  && (p1.getReceiveTimeout() == p2.getReceiveTimeout())
+                  && StringUtils.equals(p1.getReferer(), p2.getReferer());
+
+        return result;
+    }
+
+    /**
+     * Returns a new HTTPClientPolicy that is compatible with the two specified
+     * policies or null if no compatible policy can be determined.
+     * 
+     * @param p1 one policy
+     * @param p2 another policy
+     * @return the compatible policy
+     */
+    public HTTPClientPolicy intersect(HTTPClientPolicy p1, HTTPClientPolicy p2) {
+
+        // incompatibilities
+
+        if (!compatible(p1, p2)) {
+            return null;
+        }
+
+        // ok - compute compatible policy
+
+        HTTPClientPolicy p = new HTTPClientPolicy();
+        p.setAccept(StringUtils.combine(p1.getAccept(), p2.getAccept()));
+        p.setAcceptEncoding(StringUtils.combine(p1.getAcceptEncoding(), p2.getAcceptEncoding()));
+        p.setAcceptLanguage(StringUtils.combine(p1.getAcceptLanguage(), p2.getAcceptLanguage()));
+        if (p1.isSetAllowChunking()) {
+            p.setAllowChunking(p1.isAllowChunking());
+        } else if (p2.isSetAllowChunking()) {
+            p.setAllowChunking(p2.isAllowChunking());
+        }
+        if (p1.isSetAutoRedirect()) {
+            p.setAutoRedirect(p1.isAutoRedirect());
+        } else if (p2.isSetAutoRedirect()) {
+            p.setAutoRedirect(p2.isAutoRedirect());
+        }
+        p.setBrowserType(StringUtils.combine(p1.getBrowserType(), p2.getBrowserType()));
+        if (p1.isSetCacheControl()) {
+            p.setCacheControl(p1.getCacheControl());
+        } else if (p2.isSetCacheControl()) {
+            p.setCacheControl(p2.getCacheControl());
+        }
+        if (p1.isSetConnection()) {
+            p.setConnection(p1.getConnection());
+        } else if (p2.isSetConnection()) {
+            p.setConnection(p2.getConnection());
+        }
+        if (p1.isSetContentType()) {
+            p.setContentType(p1.getContentType());
+        } else if (p2.isSetContentType()) {
+            p.setContentType(p2.getContentType());
+        }
+        p.setCookie(StringUtils.combine(p1.getCookie(), p2.getCookie()));
+        p.setDecoupledEndpoint(StringUtils.combine(p1.getDecoupledEndpoint(), p2.getDecoupledEndpoint()));
+        p.setHost(StringUtils.combine(p1.getHost(), p2.getHost()));
+        p.setProxyServer(StringUtils.combine(p1.getProxyServer(), p2.getProxyServer()));
+        if (p1.isSetProxyServerPort()) {
+            p.setProxyServerPort(p1.getProxyServerPort());
+        } else if (p2.isSetProxyServerPort()) {
+            p.setProxyServerPort(p2.getProxyServerPort());
+        }
+        if (p1.isSetProxyServerType()) {
+            p.setProxyServerType(p1.getProxyServerType());
+        } else if (p2.isSetProxyServerType()) {
+            p.setProxyServerType(p2.getProxyServerType());
+        }
+        p.setReferer(StringUtils.combine(p1.getReferer(), p2.getReferer()));
+        if (p1.isSetConnectionTimeout() || p2.isSetConnectionTimeout()) {
+            p.setConnectionTimeout(Math.min(p1.getConnectionTimeout(), p2.getConnectionTimeout()));
+        }
+        if (p1.isSetReceiveTimeout() || p2.isSetReceiveTimeout()) {
+            p.setReceiveTimeout(Math.min(p1.getReceiveTimeout(), p2.getReceiveTimeout()));
+        }
+
+        return p;
+    }
+
+    /**
+     * Checks if two HTTPClientPolicy objects are compatible.
+     * 
+     * @param p1 one client policy
+     * @param p2 another client policy
+     * @return true iff policies are compatible
+     */
+    public boolean compatible(HTTPClientPolicy p1, HTTPClientPolicy p2) {
+
+        if (p1 == p2 || p1.equals(p2)) {
+            return true;
+        }
+
+        boolean compatible = true;
+
+        if (compatible) {
+            compatible &= StringUtils.compatible(p1.getAccept(), p2.getAccept());
+        }
+
+        if (compatible) {
+            compatible &= StringUtils.compatible(p1.getAcceptEncoding(), p2.getAcceptEncoding());
+        }
+
+        if (compatible) {
+            compatible &= StringUtils.compatible(p1.getAcceptLanguage(), p2.getAcceptLanguage());
+        }
+
+        if (compatible) {
+            compatible &= StringUtils.compatible(p1.getBrowserType(), p2.getBrowserType());
+        }
+
+        if (compatible) {
+            compatible &= !p1.isSetCacheControl() || !p2.isSetCacheControl()
+                          || p1.getCacheControl().equals(p2.getCacheControl());
+        }
+
+        if (compatible) {
+            compatible = !p1.isSetConnection() || !p2.isSetConnection()
+                         || p1.getConnection().value().equals(p2.getConnection().value());
+        }
+
+        if (compatible) {
+            compatible = !p1.isSetContentType() || !p2.isSetContentType()
+                         || p1.getContentType().equals(p2.getContentType());
+        }
+
+        if (compatible) {
+            compatible &= StringUtils.compatible(p1.getCookie(), p2.getCookie());
+        }
+
+        // REVISIT: Should compatibility require strict equality?
+
+        if (compatible) {
+            compatible &= StringUtils.compatible(p1.getDecoupledEndpoint(), p2.getDecoupledEndpoint());
+        }
+
+        if (compatible) {
+            compatible &= StringUtils.compatible(p1.getHost(), p2.getHost());
+        }
+
+        if (compatible) {
+            compatible &= StringUtils.compatible(p1.getProxyServer(), p2.getProxyServer());
+        }
+
+        if (compatible) {
+            compatible &= !p1.isSetProxyServerPort() || !p2.isSetProxyServerPort()
+                          || p1.getProxyServerPort() == p2.getProxyServerPort();
+        }
+
+        if (compatible) {
+            compatible &= !p1.isSetProxyServerType() || !p2.isSetProxyServerType()
+                          || p1.getProxyServerType().equals(p2.getProxyServerType());
+        }
+
+        if (compatible) {
+            compatible &= StringUtils.compatible(p1.getReferer(), p2.getReferer());
+        }
+
+        if (compatible) {
+            compatible &= p1.isAllowChunking() == p2.isAllowChunking();
+        }
+
+        if (compatible) {
+            compatible &= p1.isAutoRedirect() == p2.isAutoRedirect();
+        }
+
+        return compatible;
+    }
+    
+    public boolean isAsserted(Message message, HTTPClientPolicy policy, HTTPClientPolicy refPolicy) {
+        boolean outbound = MessageUtils.isOutbound(message);
+        boolean compatible = compatible(policy, refPolicy);
+        return !outbound || compatible;
+    }
+
+    public Class<HTTPClientPolicy> getDataClass() {
+        return HTTPClientPolicy.class;
+    }
+
+    public QName getDataClassName() {
+        return new ObjectFactory().createClient(null).getName();
+    }
+    
+    public static String toString(HTTPClientPolicy p) {
+        StringBuilder buf = new StringBuilder();
+        buf.append(p);
+        buf.append("[DecoupledEndpoint=\"");
+        buf.append(p.getDecoupledEndpoint());
+        buf.append("\", ReceiveTimeout=");
+        buf.append(p.getReceiveTimeout());
+        buf.append("])");
+        return buf.toString();
+    }
+}

Added: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/impl/ServerPolicyCalculator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/impl/ServerPolicyCalculator.java?rev=1233348&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/impl/ServerPolicyCalculator.java (added)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/impl/ServerPolicyCalculator.java Thu Jan 19 13:07:51 2012
@@ -0,0 +1,201 @@
+/**
+ * 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.transport.http.policy.impl;
+
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageUtils;
+import org.apache.cxf.policy.PolicyCalculator;
+import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
+import org.apache.cxf.transports.http.configuration.ObjectFactory;
+
+public class ServerPolicyCalculator implements PolicyCalculator<HTTPServerPolicy> {
+    /**
+     * Returns a new HTTPServerPolicy that is compatible with the two specified
+     * policies or null if no compatible policy can be determined.
+     * 
+     * @param p1 one policy
+     * @param p2 another policy
+     * @return the compatible policy
+     */
+    public HTTPServerPolicy intersect(HTTPServerPolicy p1, HTTPServerPolicy p2) {
+
+        if (!compatible(p1, p2)) {
+            return null;
+        }
+
+        HTTPServerPolicy p = new HTTPServerPolicy();
+        if (p1.isSetCacheControl()) {
+            p.setCacheControl(p1.getCacheControl());
+        } else if (p2.isSetCacheControl()) {
+            p.setCacheControl(p2.getCacheControl());
+        }
+        p.setContentEncoding(StringUtils.combine(p1.getContentEncoding(), p2.getContentEncoding()));
+        p.setContentLocation(StringUtils.combine(p1.getContentLocation(), p2.getContentLocation()));
+        if (p1.isSetContentType()) {
+            p.setContentType(p1.getContentType());
+        } else if (p2.isSetContentType()) {
+            p.setContentType(p2.getContentType());
+        }
+        if (p1.isSetHonorKeepAlive()) {
+            p.setHonorKeepAlive(p1.isHonorKeepAlive());
+        } else if (p2.isSetHonorKeepAlive()) {
+            p.setHonorKeepAlive(p2.isHonorKeepAlive());
+        }
+        if (p1.isSetKeepAliveParameters()) {
+            p.setKeepAliveParameters(p1.getKeepAliveParameters());
+        } else if (p2.isSetKeepAliveParameters()) {
+            p.setKeepAliveParameters(p2.getKeepAliveParameters());
+        }
+
+        if (p1.isSetReceiveTimeout() || p2.isSetReceiveTimeout()) {
+            p.setReceiveTimeout(Math.min(p1.getReceiveTimeout(), p2.getReceiveTimeout()));
+        }
+        p.setRedirectURL(StringUtils.combine(p1.getRedirectURL(), p2.getRedirectURL()));
+        p.setServerType(StringUtils.combine(p1.getServerType(), p2.getServerType()));
+        if (p1.isSetSuppressClientReceiveErrors()) {
+            p.setSuppressClientReceiveErrors(p1.isSuppressClientReceiveErrors());
+        } else if (p2.isSetSuppressClientReceiveErrors()) {
+            p.setSuppressClientReceiveErrors(p2.isSuppressClientReceiveErrors());
+        }
+        if (p1.isSetSuppressClientSendErrors()) {
+            p.setSuppressClientSendErrors(p1.isSuppressClientSendErrors());
+        } else if (p2.isSetSuppressClientSendErrors()) {
+            p.setSuppressClientSendErrors(p2.isSuppressClientSendErrors());
+        }
+
+        return p;
+    }
+
+    /**
+     * Checks if two HTTPServerPolicy objects are compatible.
+     * 
+     * @param p1 one server policy
+     * @param p2 another server policy
+     * @return true iff policies are compatible
+     */
+    public boolean compatible(HTTPServerPolicy p1, HTTPServerPolicy p2) {
+
+        if (p1 == p2 || p1.equals(p2)) {
+            return true;
+        }
+
+        boolean compatible = true;
+
+        if (compatible) {
+            compatible &= !p1.isSetCacheControl() || !p2.isSetCacheControl()
+                          || p1.getCacheControl().equals(p2.getCacheControl());
+        }
+
+        if (compatible) {
+            compatible &= StringUtils.compatible(p1.getContentEncoding(), p2.getContentEncoding());
+        }
+
+        if (compatible) {
+            compatible &= StringUtils.compatible(p1.getContentLocation(), p2.getContentLocation());
+        }
+
+        if (compatible) {
+            compatible &= StringUtils.compatible(p1.getContentType(), p2.getContentType());
+        }
+
+        if (compatible) {
+            compatible &= StringUtils.compatible(p1.getRedirectURL(), p2.getRedirectURL());
+        }
+
+        if (compatible) {
+            compatible &= StringUtils.compatible(p1.getServerType(), p2.getServerType());
+        }
+
+        if (compatible) {
+            compatible &= p1.isHonorKeepAlive() == p2.isHonorKeepAlive();
+        }
+
+        if (compatible) {
+            compatible &= p1.isSuppressClientReceiveErrors() == p2.isSuppressClientReceiveErrors();
+        }
+
+        if (compatible) {
+            compatible &= p1.isSuppressClientSendErrors() == p2.isSuppressClientSendErrors();
+        }
+        if (compatible) {
+            compatible &= StringUtils.compatible(p1.getKeepAliveParameters(), p2.getKeepAliveParameters());
+        }
+
+        return compatible;
+    }
+
+    /**
+     * Determines if two HTTPServerPolicy objects are equal. REVISIT: Check if
+     * this can be replaced by a generated equals method.
+     * 
+     * @param p1 one server policy
+     * @param p2 another server policy
+     * @return true iff the two policies are equal
+     */
+    public boolean equals(HTTPServerPolicy p1, HTTPServerPolicy p2) {
+        if (p1 == p2) {
+            return true;
+        }
+        boolean result = true;
+
+        result &= (p1.isHonorKeepAlive() == p2.isHonorKeepAlive())
+                  && (p1.getCacheControl() == null ? p2.getCacheControl() == null : p1.getCacheControl()
+                      .equals(p2.getCacheControl()))
+                  && StringUtils.equals(p1.getContentEncoding(), p2.getContentEncoding())
+                  && StringUtils.equals(p1.getContentLocation(), p2.getContentLocation())
+                  && StringUtils.equals(p1.getContentType(), p2.getContentType())
+                  && StringUtils.equals(p1.getKeepAliveParameters(), p2.getKeepAliveParameters());
+        if (!result) {
+            return false;
+        }
+        result &= (p1.getReceiveTimeout() == p2.getReceiveTimeout())
+                  && StringUtils.equals(p1.getRedirectURL(), p2.getRedirectURL())
+                  && StringUtils.equals(p1.getServerType(), p2.getServerType())
+                  && (p1.isSuppressClientReceiveErrors() == p2.isSuppressClientReceiveErrors())
+                  && (p1.isSuppressClientSendErrors() == p2.isSuppressClientSendErrors());
+
+        return result;
+    }
+
+    public boolean isAsserted(Message message, HTTPServerPolicy policy, HTTPServerPolicy refPolicy) {
+        return MessageUtils.isOutbound(message) || equals(policy, refPolicy);
+    }
+
+    public Class<HTTPServerPolicy> getDataClass() {
+        return HTTPServerPolicy.class;
+    }
+
+    public QName getDataClassName() {
+        return new ObjectFactory().createServer(null).getName();
+    }
+    
+    public static String toString(HTTPServerPolicy p) {
+        StringBuilder buf = new StringBuilder();
+        buf.append(p);
+        buf.append("[ContentType=\"");
+        buf.append(p.getContentType());
+        buf.append("\", ReceiveTimeout=");
+        buf.append(p.getReceiveTimeout());
+        buf.append("])");
+        return buf.toString();
+        
+    }
+}

Added: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/impl/StringUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/impl/StringUtils.java?rev=1233348&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/impl/StringUtils.java (added)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/impl/StringUtils.java Thu Jan 19 13:07:51 2012
@@ -0,0 +1,38 @@
+/**
+ * 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.transport.http.policy.impl;
+
+public final class StringUtils {
+
+    private StringUtils() {
+    }
+
+    static String combine(String s1, String s2) {
+        return s1 == null ? s2 : s1;
+    }
+
+    static boolean equals(String s1, String s2) {
+        return s1 == null ? s2 == null : s1.equals(s2);
+    }
+
+    static boolean compatible(String s1, String s2) {
+        return s1 == null || s2 == null || s1.equals(s2);
+    }
+
+}

Added: cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/ClientPolicyCalculatorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/ClientPolicyCalculatorTest.java?rev=1233348&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/ClientPolicyCalculatorTest.java (added)
+++ cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/ClientPolicyCalculatorTest.java Thu Jan 19 13:07:51 2012
@@ -0,0 +1,80 @@
+/**
+ * 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.transport.http.policy;
+
+import org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator;
+import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ClientPolicyCalculatorTest extends Assert {
+    @Test
+    public void testCompatibleClientPolicies() {
+        ClientPolicyCalculator calc = new ClientPolicyCalculator();
+        HTTPClientPolicy p1 = new HTTPClientPolicy();
+        assertTrue("Policy is not compatible with itself.", calc.compatible(p1, p1));
+        HTTPClientPolicy p2 = new HTTPClientPolicy();
+        assertTrue("Policies are not compatible.", calc.compatible(p1, p2));
+        p1.setBrowserType("browser");
+        assertTrue("Policies are not compatible.", calc.compatible(p1, p2));
+        p1.setBrowserType(null);
+        p1.setConnectionTimeout(10000);
+        assertTrue("Policies are not compatible.", calc.compatible(p1, p2));
+        p1.setAllowChunking(false);
+        assertTrue("Policies are compatible.", !calc.compatible(p1, p2));
+        p2.setAllowChunking(false);
+        assertTrue("Policies are compatible.", calc.compatible(p1, p2));
+    }
+
+    @Test
+    public void testIntersectClientPolicies() {
+        ClientPolicyCalculator calc = new ClientPolicyCalculator();
+        HTTPClientPolicy p1 = new HTTPClientPolicy();
+        HTTPClientPolicy p2 = new HTTPClientPolicy();
+        HTTPClientPolicy p = null;
+
+        p1.setBrowserType("browser");
+        p = calc.intersect(p1, p2);
+        assertEquals("browser", p.getBrowserType());
+        p1.setBrowserType(null);
+        p1.setConnectionTimeout(10000L);
+        p = calc.intersect(p1, p2);
+        assertEquals(10000L, p.getConnectionTimeout());
+        p1.setAllowChunking(false);
+        p2.setAllowChunking(false);
+        p = calc.intersect(p1, p2);
+        assertTrue(!p.isAllowChunking());
+    }
+    
+    @Test
+    public void testEqualClientPolicies() {
+        ClientPolicyCalculator calc = new ClientPolicyCalculator();
+        HTTPClientPolicy p1 = new HTTPClientPolicy();
+        assertTrue(calc.equals(p1, p1));
+        HTTPClientPolicy p2 = new HTTPClientPolicy();        
+        assertTrue(calc.equals(p1, p2));
+        p1.setDecoupledEndpoint("http://localhost:8080/decoupled");
+        assertTrue(!calc.equals(p1, p2));
+        p2.setDecoupledEndpoint("http://localhost:8080/decoupled");
+        assertTrue(calc.equals(p1, p2));
+        p1.setReceiveTimeout(10000L);
+        assertTrue(!calc.equals(p1, p2));
+    }
+
+}

Modified: cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/HTTPClientAssertionBuilderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/HTTPClientAssertionBuilderTest.java?rev=1233348&r1=1233347&r2=1233348&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/HTTPClientAssertionBuilderTest.java (original)
+++ cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/HTTPClientAssertionBuilderTest.java Thu Jan 19 13:07:51 2012
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.transport.http.policy;
 
+import org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator;
 import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
 import org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion;
 import org.apache.neethi.Assertion;
@@ -37,7 +38,7 @@ public class HTTPClientAssertionBuilderT
         Assertion a = ab.buildAssertion();
         assertTrue(a instanceof JaxbAssertion);
         assertTrue(a instanceof HTTPClientAssertionBuilder.HTTPClientPolicyAssertion);
-        assertEquals(PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME, a.getName());
+        assertEquals(new ClientPolicyCalculator().getDataClassName(), a.getName());
         assertTrue(!a.isOptional());
     }
     

Modified: cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/HTTPServerAssertionBuilderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/HTTPServerAssertionBuilderTest.java?rev=1233348&r1=1233347&r2=1233348&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/HTTPServerAssertionBuilderTest.java (original)
+++ cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/HTTPServerAssertionBuilderTest.java Thu Jan 19 13:07:51 2012
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.transport.http.policy;
 
+import org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator;
 import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
 import org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion;
 import org.apache.neethi.Assertion;
@@ -37,7 +38,7 @@ public class HTTPServerAssertionBuilderT
         Assertion a = ab.buildAssertion();
         assertTrue(a instanceof JaxbAssertion);
         assertTrue(a instanceof HTTPServerAssertionBuilder.HTTPServerPolicyAssertion);
-        assertEquals(PolicyUtils.HTTPSERVERPOLICY_ASSERTION_QNAME, a.getName());
+        assertEquals(new ServerPolicyCalculator().getDataClassName(), a.getName());
         assertTrue(!a.isOptional());
     }
     

Modified: cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/PolicyUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/PolicyUtilsTest.java?rev=1233348&r1=1233347&r2=1233348&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/PolicyUtilsTest.java (original)
+++ cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/PolicyUtilsTest.java Thu Jan 19 13:07:51 2012
@@ -26,11 +26,15 @@ import java.util.Collections;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.policy.PolicyDataEngine;
+import org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator;
+import org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator;
 import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
 import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
 import org.apache.cxf.ws.policy.AssertionInfo;
 import org.apache.cxf.ws.policy.AssertionInfoMap;
 import org.apache.cxf.ws.policy.PolicyAssertion;
+import org.apache.cxf.ws.policy.PolicyDataEngineImpl;
 import org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion;
 import org.easymock.EasyMock;
 import org.easymock.IMocksControl;
@@ -50,108 +54,6 @@ public class PolicyUtilsTest extends Ass
         control = EasyMock.createNiceControl();
     }
 
-    @Test
-    public void testCompatibleClientPolicies() {
-        HTTPClientPolicy p1 = new HTTPClientPolicy();
-        assertTrue("Policy is not compatible with itself.", PolicyUtils.compatible(p1, p1));
-        HTTPClientPolicy p2 = new HTTPClientPolicy();
-        assertTrue("Policies are not compatible.", PolicyUtils.compatible(p1, p2));
-        p1.setBrowserType("browser");
-        assertTrue("Policies are not compatible.", PolicyUtils.compatible(p1, p2));
-        p1.setBrowserType(null);
-        p1.setConnectionTimeout(10000);
-        assertTrue("Policies are not compatible.", PolicyUtils.compatible(p1, p2));
-        p1.setAllowChunking(false);
-        assertTrue("Policies are compatible.", !PolicyUtils.compatible(p1, p2));
-        p2.setAllowChunking(false);
-        assertTrue("Policies are compatible.", PolicyUtils.compatible(p1, p2));
-    }
-
-    @Test
-    public void testIntersectClientPolicies() {
-        HTTPClientPolicy p1 = new HTTPClientPolicy();
-        HTTPClientPolicy p2 = new HTTPClientPolicy();
-        HTTPClientPolicy p = null;
-
-        p1.setBrowserType("browser");
-        p = PolicyUtils.intersect(p1, p2);
-        assertEquals("browser", p.getBrowserType());
-        p1.setBrowserType(null);
-        p1.setConnectionTimeout(10000L);
-        p = PolicyUtils.intersect(p1, p2);
-        assertEquals(10000L, p.getConnectionTimeout());
-        p1.setAllowChunking(false);
-        p2.setAllowChunking(false);
-        p = PolicyUtils.intersect(p1, p2);
-        assertTrue(!p.isAllowChunking());
-    }
-    
-    @Test
-    public void testEqualClientPolicies() {
-        HTTPClientPolicy p1 = new HTTPClientPolicy();
-        assertTrue(PolicyUtils.equals(p1, p1));
-        HTTPClientPolicy p2 = new HTTPClientPolicy();        
-        assertTrue(PolicyUtils.equals(p1, p2));
-        p1.setDecoupledEndpoint("http://localhost:8080/decoupled");
-        assertTrue(!PolicyUtils.equals(p1, p2));
-        p2.setDecoupledEndpoint("http://localhost:8080/decoupled");
-        assertTrue(PolicyUtils.equals(p1, p2));
-        p1.setReceiveTimeout(10000L);
-        assertTrue(!PolicyUtils.equals(p1, p2));
-    }
-
-    @Test
-    public void testCompatibleServerPolicies() {
-        HTTPServerPolicy p1 = new HTTPServerPolicy();
-        assertTrue("Policy is not compatible with itself.", PolicyUtils.compatible(p1, p1));
-        HTTPServerPolicy p2 = new HTTPServerPolicy();
-        assertTrue("Policies are not compatible.", PolicyUtils.compatible(p1, p2));
-        p1.setServerType("server");
-        assertTrue("Policies are not compatible.", PolicyUtils.compatible(p1, p2));
-        p1.setServerType(null);
-        p1.setReceiveTimeout(10000);
-        assertTrue("Policies are not compatible.", PolicyUtils.compatible(p1, p2));
-        p1.setSuppressClientSendErrors(false);
-        assertTrue("Policies are compatible.", PolicyUtils.compatible(p1, p2));
-        p1.setSuppressClientSendErrors(true);
-        assertTrue("Policies are compatible.", !PolicyUtils.compatible(p1, p2));
-        p2.setSuppressClientSendErrors(true);
-        assertTrue("Policies are compatible.", PolicyUtils.compatible(p1, p2));
-    }
-        
-    @Test
-    public void testIntersectServerPolicies() {
-        HTTPServerPolicy p1 = new HTTPServerPolicy();
-        HTTPServerPolicy p2 = new HTTPServerPolicy();
-        HTTPServerPolicy p = null;
-
-        p1.setServerType("server");
-        p = PolicyUtils.intersect(p1, p2);
-        assertEquals("server", p.getServerType());
-        p1.setServerType(null);
-        p1.setReceiveTimeout(10000L);
-        p = PolicyUtils.intersect(p1, p2);
-        assertEquals(10000L, p.getReceiveTimeout());
-        p1.setSuppressClientSendErrors(true);
-        p2.setSuppressClientSendErrors(true);
-        p = PolicyUtils.intersect(p1, p2);
-        assertTrue(p.isSuppressClientSendErrors());
-    }
-
-    
-    @Test
-    public void testEqualServerPolicies() {
-        HTTPServerPolicy p1 = new HTTPServerPolicy();
-        assertTrue(PolicyUtils.equals(p1, p1));
-        HTTPServerPolicy p2 = new HTTPServerPolicy();        
-        assertTrue(PolicyUtils.equals(p1, p2));
-        p1.setContentEncoding("encoding");
-        assertTrue(!PolicyUtils.equals(p1, p2));
-        p2.setContentEncoding("encoding");
-        assertTrue(PolicyUtils.equals(p1, p2));
-        p1.setSuppressClientSendErrors(true);
-        assertTrue(!PolicyUtils.equals(p1, p2));
-    }
     
     @Test
     public void testAssertClientPolicyNoop() {
@@ -164,10 +66,12 @@ public class PolicyUtilsTest extends Ass
     }
     
     void testAssertPolicyNoop(boolean isRequestor) {
+        PolicyDataEngine pde = new PolicyDataEngineImpl(null);
         Message message = control.createMock(Message.class);
         EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(null);
         control.replay();
-        PolicyUtils.assertClientPolicy(message, null);
+        
+        pde.assertMessage(message, null, new ClientPolicyCalculator());
         control.verify();
 
         control.reset();
@@ -176,13 +80,14 @@ public class PolicyUtilsTest extends Ass
         EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
         control.replay();
         if (isRequestor) {
-            PolicyUtils.assertClientPolicy(message, null);
+            pde.assertMessage(message, null, new ClientPolicyCalculator());
         } else {
-            PolicyUtils.assertServerPolicy(message, null);
+            pde.assertMessage(message, null, new ServerPolicyCalculator());
         }
         control.verify();
     }
 
+
     @Test
     public void testAssertClientPolicyOutbound() {
         testAssertClientPolicy(true);
@@ -192,6 +97,13 @@ public class PolicyUtilsTest extends Ass
     public void testAssertClientPolicyInbound() {
         testAssertClientPolicy(false);
     }
+    
+    public AssertionInfo getClientPolicyAssertionInfo(HTTPClientPolicy policy) {
+        JaxbAssertion<HTTPClientPolicy> assertion = 
+            new JaxbAssertion<HTTPClientPolicy>(new ClientPolicyCalculator().getDataClassName(), false);
+        assertion.setData(policy);
+        return new AssertionInfo(assertion);
+    }
 
     void testAssertClientPolicy(boolean outbound) {
         Message message = control.createMock(Message.class);
@@ -202,19 +114,9 @@ public class PolicyUtilsTest extends Ass
         HTTPClientPolicy icmp = new HTTPClientPolicy();
         icmp.setAllowChunking(false);
 
-        JaxbAssertion<HTTPClientPolicy> ea = 
-            new JaxbAssertion<HTTPClientPolicy>(PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME, false);
-        ea.setData(ep);
-        JaxbAssertion<HTTPClientPolicy> cma = 
-            new JaxbAssertion<HTTPClientPolicy>(PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME, false);
-        cma.setData(cmp);
-        JaxbAssertion<HTTPClientPolicy> icma = 
-            new JaxbAssertion<HTTPClientPolicy>(PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME, false);
-        icma.setData(icmp);
-
-        AssertionInfo eai = new AssertionInfo(ea);
-        AssertionInfo cmai = new AssertionInfo(cma);
-        AssertionInfo icmai = new AssertionInfo(icma);
+        AssertionInfo eai = getClientPolicyAssertionInfo(ep);
+        AssertionInfo cmai = getClientPolicyAssertionInfo(cmp);
+        AssertionInfo icmai = getClientPolicyAssertionInfo(icmp);
 
         AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(Collections.EMPTY_LIST,
                                                                    PolicyAssertion.class));
@@ -222,17 +124,18 @@ public class PolicyUtilsTest extends Ass
         ais.add(eai);
         ais.add(cmai);
         ais.add(icmai);
-        aim.put(PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME, ais);
+        aim.put(new ClientPolicyCalculator().getDataClassName(), ais);
         EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
         Exchange ex = control.createMock(Exchange.class);
-        EasyMock.expect(message.getExchange()).andReturn(ex);
-        EasyMock.expect(ex.getOutMessage()).andReturn(outbound ? message : null);
+        EasyMock.expect(message.getExchange()).andReturn(ex).atLeastOnce();
+        EasyMock.expect(ex.getOutMessage()).andReturn(outbound ? message : null).atLeastOnce();
         if (!outbound) {
-            EasyMock.expect(ex.getOutFaultMessage()).andReturn(null);
+            EasyMock.expect(ex.getOutFaultMessage()).andReturn(null).atLeastOnce();
         }
 
         control.replay();
-        PolicyUtils.assertClientPolicy(message, ep);
+        PolicyDataEngine pde = new PolicyDataEngineImpl(null);
+        pde.assertMessage(message, ep, new ClientPolicyCalculator());
         assertTrue(eai.isAsserted());
         assertTrue(cmai.isAsserted());
         assertTrue(outbound ? !icmai.isAsserted() : icmai.isAsserted());
@@ -248,6 +151,13 @@ public class PolicyUtilsTest extends Ass
     public void testAssertServerPolicyInbound() {
         testAssertServerPolicy(false);
     }
+    
+    public AssertionInfo getServerPolicyAssertionInfo(HTTPServerPolicy policy) {
+        JaxbAssertion<HTTPServerPolicy> assertion = 
+            new JaxbAssertion<HTTPServerPolicy>(new ServerPolicyCalculator().getDataClassName(), false);
+        assertion.setData(policy);
+        return new AssertionInfo(assertion);
+    }
 
     void testAssertServerPolicy(boolean outbound) {
         Message message = control.createMock(Message.class);
@@ -258,42 +168,30 @@ public class PolicyUtilsTest extends Ass
         HTTPServerPolicy icmp = new HTTPServerPolicy();
         icmp.setSuppressClientSendErrors(true);
 
-        JaxbAssertion<HTTPServerPolicy> ea = 
-            new JaxbAssertion<HTTPServerPolicy>(PolicyUtils.HTTPSERVERPOLICY_ASSERTION_QNAME, false);
-        ea.setData(ep);
-        JaxbAssertion<HTTPServerPolicy> ma = 
-            new JaxbAssertion<HTTPServerPolicy>(PolicyUtils.HTTPSERVERPOLICY_ASSERTION_QNAME, false);
-        ma.setData(mp);
-        JaxbAssertion<HTTPServerPolicy> cma = 
-            new JaxbAssertion<HTTPServerPolicy>(PolicyUtils.HTTPSERVERPOLICY_ASSERTION_QNAME, false);
-        cma.setData(cmp);
-        JaxbAssertion<HTTPServerPolicy> icma = 
-            new JaxbAssertion<HTTPServerPolicy>(PolicyUtils.HTTPSERVERPOLICY_ASSERTION_QNAME, false);
-        icma.setData(icmp);
-
-        AssertionInfo eai = new AssertionInfo(ea);
-        AssertionInfo mai = new AssertionInfo(ma);
-        AssertionInfo cmai = new AssertionInfo(cma);
-        AssertionInfo icmai = new AssertionInfo(icma);
+        AssertionInfo eai = getServerPolicyAssertionInfo(ep);
+        AssertionInfo mai = getServerPolicyAssertionInfo(mp); 
+        AssertionInfo cmai = getServerPolicyAssertionInfo(cmp); 
+        AssertionInfo icmai = getServerPolicyAssertionInfo(icmp);
 
-        AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(Collections.EMPTY_LIST, 
-                                                                   PolicyAssertion.class));
         Collection<AssertionInfo> ais = new ArrayList<AssertionInfo>();
         ais.add(eai);
         ais.add(mai);
         ais.add(cmai);
         ais.add(icmai);
-        aim.put(PolicyUtils.HTTPSERVERPOLICY_ASSERTION_QNAME, ais);
-        EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
+        AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(Collections.EMPTY_LIST, 
+                                                                   PolicyAssertion.class));
+        aim.put(new ServerPolicyCalculator().getDataClassName(), ais);
+        EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim).atLeastOnce();
         Exchange ex = control.createMock(Exchange.class);
-        EasyMock.expect(message.getExchange()).andReturn(ex);
-        EasyMock.expect(ex.getOutMessage()).andReturn(outbound ? message : null);
+        EasyMock.expect(message.getExchange()).andReturn(ex).atLeastOnce();
+        EasyMock.expect(ex.getOutMessage()).andReturn(outbound ? message : null).atLeastOnce();
         if (!outbound) {
-            EasyMock.expect(ex.getOutFaultMessage()).andReturn(null);
+            EasyMock.expect(ex.getOutFaultMessage()).andReturn(null).atLeastOnce();
         }
 
         control.replay();
-        PolicyUtils.assertServerPolicy(message, ep);
+        new PolicyDataEngineImpl(null).assertMessage(message, ep, 
+                                                     new ServerPolicyCalculator());
         assertTrue(eai.isAsserted());
         assertTrue(mai.isAsserted());
         assertTrue(outbound ? cmai.isAsserted() : !cmai.isAsserted());

Added: cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/ServerPolicyCalculatorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/ServerPolicyCalculatorTest.java?rev=1233348&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/ServerPolicyCalculatorTest.java (added)
+++ cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/ServerPolicyCalculatorTest.java Thu Jan 19 13:07:51 2012
@@ -0,0 +1,82 @@
+/**
+ * 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.transport.http.policy;
+
+import org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator;
+import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ServerPolicyCalculatorTest extends Assert {
+    @Test
+    public void testCompatibleServerPolicies() {
+        ServerPolicyCalculator spc = new ServerPolicyCalculator();
+        HTTPServerPolicy p1 = new HTTPServerPolicy();
+        assertTrue("Policy is not compatible with itself.", spc.compatible(p1, p1));
+        HTTPServerPolicy p2 = new HTTPServerPolicy();
+        assertTrue("Policies are not compatible.", spc.compatible(p1, p2));
+        p1.setServerType("server");
+        assertTrue("Policies are not compatible.", spc.compatible(p1, p2));
+        p1.setServerType(null);
+        p1.setReceiveTimeout(10000);
+        assertTrue("Policies are not compatible.", spc.compatible(p1, p2));
+        p1.setSuppressClientSendErrors(false);
+        assertTrue("Policies are compatible.", spc.compatible(p1, p2));
+        p1.setSuppressClientSendErrors(true);
+        assertTrue("Policies are compatible.", !spc.compatible(p1, p2));
+        p2.setSuppressClientSendErrors(true);
+        assertTrue("Policies are compatible.", spc.compatible(p1, p2));
+    }
+        
+    @Test
+    public void testIntersectServerPolicies() {
+        ServerPolicyCalculator spc = new ServerPolicyCalculator();
+        HTTPServerPolicy p1 = new HTTPServerPolicy();
+        HTTPServerPolicy p2 = new HTTPServerPolicy();
+        HTTPServerPolicy p = null;
+
+        p1.setServerType("server");
+        p = spc.intersect(p1, p2);
+        assertEquals("server", p.getServerType());
+        p1.setServerType(null);
+        p1.setReceiveTimeout(10000L);
+        p = spc.intersect(p1, p2);
+        assertEquals(10000L, p.getReceiveTimeout());
+        p1.setSuppressClientSendErrors(true);
+        p2.setSuppressClientSendErrors(true);
+        p = spc.intersect(p1, p2);
+        assertTrue(p.isSuppressClientSendErrors());
+    }
+
+    
+    @Test
+    public void testEqualServerPolicies() {
+        ServerPolicyCalculator spc = new ServerPolicyCalculator();
+        HTTPServerPolicy p1 = new HTTPServerPolicy();
+        assertTrue(spc.equals(p1, p1));
+        HTTPServerPolicy p2 = new HTTPServerPolicy();        
+        assertTrue(spc.equals(p1, p2));
+        p1.setContentEncoding("encoding");
+        assertTrue(!spc.equals(p1, p2));
+        p2.setContentEncoding("encoding");
+        assertTrue(spc.equals(p1, p2));
+        p1.setSuppressClientSendErrors(true);
+        assertTrue(!spc.equals(p1, p2));
+    }
+}

Added: cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyDataEngineImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyDataEngineImpl.java?rev=1233348&view=auto
==============================================================================
--- cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyDataEngineImpl.java (added)
+++ cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyDataEngineImpl.java Thu Jan 19 13:07:51 2012
@@ -0,0 +1,151 @@
+/**
+ * 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.List;
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.policy.PolicyCalculator;
+import org.apache.cxf.policy.PolicyDataEngine;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.Conduit;
+import org.apache.cxf.transport.Destination;
+import org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion;
+import org.apache.neethi.Assertion;
+
+public class PolicyDataEngineImpl implements PolicyDataEngine {
+    private static final Logger LOG = LogUtils.getL7dLogger(PolicyDataEngineImpl.class);
+    private Bus bus;
+    private PolicyEngine policyEngine;
+    
+    public PolicyDataEngineImpl(Bus bus) {
+        this.bus = bus;
+    }
+    
+    void setPolicyEngine(PolicyEngine policyEngine) {
+        this.policyEngine = policyEngine;
+    }
+    
+    private PolicyEngine getPolicyEngine() {
+        if (this.policyEngine == null) {
+            this.policyEngine = bus.getExtension(PolicyEngine.class); 
+        }
+        return this.policyEngine;
+    }
+
+    public <T> T getClientEndpointPolicy(EndpointInfo ei, Conduit c,
+                                         PolicyCalculator<T> policyCalculator) {
+        Collection<Assertion> alternative = getPolicyEngine().getClientEndpointPolicy(ei, c).getChosenAlternative();
+        List<T> filteredPolicies = new ArrayList<T>();
+        for (Assertion a : alternative) {
+            if (policyCalculator.getDataClassName().equals(a.getName())) {
+                T p = JaxbAssertion.cast(a, policyCalculator.getDataClass()).getData();
+                filteredPolicies.add(p);
+            }
+        }
+        return getPolicy(filteredPolicies, policyCalculator);
+    }
+
+    public <T> T getPolicy(Message message, T confPolicy, PolicyCalculator<T> intersector) {
+        List<T> policies = getPoliciesFromMessage(intersector.getDataClassName(), 
+                                                  message, intersector.getDataClass());
+        policies.add(confPolicy);
+        return getPolicy(policies, intersector);
+    }
+
+    public <T> T getServerEndpointPolicy(EndpointInfo ei, Destination d, 
+                                         PolicyCalculator<T> policyCalculator) {
+        Collection<Assertion> alternative = getPolicyEngine().getServerEndpointPolicy(ei, d).getChosenAlternative();
+        List<T> filteredPolicies = new ArrayList<T>();
+        for (Assertion a : alternative) {
+            if (policyCalculator.getDataClassName().equals(a.getName())) {
+                T p = JaxbAssertion.cast(a, policyCalculator.getDataClass()).getData();
+                filteredPolicies.add(p);
+            }
+        }
+        return getPolicy(filteredPolicies, policyCalculator);
+    }
+
+    private <T> List<T> getPoliciesFromMessage(QName name, Message message, Class<T> dataClass) {
+        List<T> policies = new ArrayList<T>();
+        AssertionInfoMap amap = message.get(AssertionInfoMap.class);
+        if (null == amap || amap.isEmpty()) {
+            return policies;
+        }
+        Collection<AssertionInfo> ais = amap.get(name);
+        if (null == ais) {
+            return policies;
+        }
+        for (AssertionInfo ai : ais) {
+            T policy = JaxbAssertion.cast(ai.getAssertion(), dataClass).getData();
+            policies.add(policy);
+        }
+        return policies;
+    }
+
+    public <T> void assertMessage(Message message, T confPol,
+                                  PolicyCalculator<T> policyCalculator) {
+        T messagePol = message.get(policyCalculator.getDataClass());
+        final T refPolicy = (messagePol != null) ? policyCalculator.intersect(messagePol, confPol) : confPol;
+
+        AssertionInfoMap amap = message.get(AssertionInfoMap.class);
+        if (null == amap || amap.isEmpty()) {
+            return;
+        }
+        Collection<AssertionInfo> ais = amap.get(policyCalculator.getDataClassName());
+        if (ais == null) {
+            return;
+        }
+        for (AssertionInfo ai : ais) {
+            T policy = JaxbAssertion.cast(ai.getAssertion(), policyCalculator.getDataClass()).getData();
+            ai.setAsserted(policyCalculator.isAsserted(message, policy, refPolicy));
+        }
+    }
+
+    private <T> T getPolicy(List<T> policies, PolicyCalculator<T> intersector) {
+        T compatible = null;
+        for (T p : policies) {
+            if (null == compatible) {
+                compatible = p;
+            } else {
+                compatible = intersector.intersect(compatible, p);
+                if (null == compatible) {
+                    logAndThrowPolicyException(p);
+                }
+            }
+        }
+        return compatible;
+    }
+
+    private <T> void logAndThrowPolicyException(T dataClass) {
+        org.apache.cxf.common.i18n.Message msg = 
+            new org.apache.cxf.common.i18n.Message("INCOMPATIBLE_HTTPCLIENTPOLICY_ASSERTIONS", 
+                                                   LOG, dataClass.getClass());
+        LOG.severe(msg.toString());
+        throw new PolicyException(msg);
+    }
+
+}

Modified: cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/bus-extensions.txt
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/bus-extensions.txt?rev=1233348&r1=1233347&r2=1233348&view=diff
==============================================================================
--- cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/bus-extensions.txt (original)
+++ cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/bus-extensions.txt Thu Jan 19 13:07:51 2012
@@ -1,4 +1,5 @@
 org.apache.cxf.ws.policy.PolicyEngineImpl:org.apache.cxf.ws.policy.PolicyEngine:false
+org.apache.cxf.ws.policy.PolicyDataEngineImpl:org.apache.cxf.policy.PolicyDataEngine:false
 org.apache.cxf.ws.policy.AssertionBuilderRegistryImpl:org.apache.cxf.ws.policy.AssertionBuilderRegistry:true 
 org.apache.cxf.ws.policy.PolicyInterceptorProviderRegistryImpl:org.apache.cxf.ws.policy.PolicyInterceptorProviderRegistry:true
 org.apache.cxf.ws.policy.PolicyBuilderImpl:org.apache.cxf.ws.policy.PolicyBuilder:true

Added: cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyDataEngineImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyDataEngineImplTest.java?rev=1233348&view=auto
==============================================================================
--- cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyDataEngineImplTest.java (added)
+++ cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyDataEngineImplTest.java Thu Jan 19 13:07:51 2012
@@ -0,0 +1,93 @@
+package org.apache.cxf.ws.policy;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.policy.PolicyCalculator;
+import org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion;
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PolicyDataEngineImplTest extends Assert {
+    private final static QName TEST_POLICY_NAME = new QName("http://test","TestPolicy");
+    
+    class TestPolicy {
+    }
+    
+    class TestPolicyCalculator implements PolicyCalculator<TestPolicy> {
+
+        public Class<TestPolicy> getDataClass() {
+            return TestPolicy.class;
+        }
+
+        public QName getDataClassName() {
+            return TEST_POLICY_NAME;
+        }
+
+        public TestPolicy intersect(TestPolicy policy1, TestPolicy policy2) {
+            return policy1;
+        }
+
+        public boolean isAsserted(Message message, TestPolicy policy, TestPolicy refPolicy) {
+            return true;
+        }
+        
+    }
+    
+    public AssertionInfo getTestPolicyAssertionInfo(TestPolicy policy) {
+        JaxbAssertion<TestPolicy> assertion = 
+            new JaxbAssertion<TestPolicy>(TEST_POLICY_NAME, false);
+        assertion.setData(policy);
+        return new AssertionInfo(assertion);
+    }
+    
+    @Test
+    public void testAssertMessageNullAim() {
+        checkAssertWithMap(null);
+    }
+    
+    @Test
+    public void testAssertMessageEmptyAim() {
+        checkAssertWithMap(new AssertionInfoMap(CastUtils.cast(Collections.EMPTY_LIST,
+                                                               PolicyAssertion.class)));
+    }
+
+    @Test
+    public void testAssertMessage() {
+        TestPolicy policy = new TestPolicy();
+        AssertionInfo ai = getTestPolicyAssertionInfo(policy);
+        AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(Collections.EMPTY_LIST,
+                                                                   PolicyAssertion.class));
+        Collection<AssertionInfo> ais = new ArrayList<AssertionInfo>();
+        ais.add(ai);
+        aim.put(TEST_POLICY_NAME, ais);
+        checkAssertWithMap(aim);
+        assertTrue(ai.isAsserted());
+    }
+
+    /**
+     * Simply check that it runs without any exceptions
+     * 
+     * @param assertionInfoMap
+     */
+    private void checkAssertWithMap(AssertionInfoMap assertionInfoMap) {
+        PolicyDataEngineImpl pde = new PolicyDataEngineImpl(null);
+        pde.setPolicyEngine(new PolicyEngineImpl());
+        TestPolicy confPol = new TestPolicy();
+        IMocksControl control = EasyMock.createControl();
+        PolicyCalculator<TestPolicy> policyCalculator = new TestPolicyCalculator();
+        Message message = control.createMock(Message.class);
+        EasyMock.expect(message.get(TestPolicy.class)).andReturn(confPol);
+        EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(assertionInfoMap);
+        control.replay();
+        pde.assertMessage(message , confPol , policyCalculator);
+        control.verify();
+    }
+}

Modified: cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/PolicyLoggingInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/PolicyLoggingInterceptor.java?rev=1233348&r1=1233347&r2=1233348&view=diff
==============================================================================
--- cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/PolicyLoggingInterceptor.java (original)
+++ cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/PolicyLoggingInterceptor.java Thu Jan 19 13:07:51 2012
@@ -33,7 +33,7 @@ import org.apache.cxf.phase.AbstractPhas
 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.http.policy.PolicyUtils;
+import org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator;
 import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
 import org.apache.cxf.ws.policy.EffectivePolicy;
 import org.apache.cxf.ws.policy.PolicyEngine;
@@ -67,7 +67,7 @@ public class PolicyLoggingInterceptor ex
             for (Assertion a : as) {
                 LOG.fine("Assertion: " + a.getClass().getName());
                 HTTPServerPolicy p = (JaxbAssertion.cast(a, HTTPServerPolicy.class)).getData(); 
-                LOG.fine("server policy: " + PolicyUtils.toString(p));
+                LOG.fine("server policy: " + new ServerPolicyCalculator().toString(p));
             }
         }
 



Mime
View raw message