Author: andreasmyth
Date: Tue Jul 17 05:32:21 2007
New Revision: 556903
URL: http://svn.apache.org/viewvc?view=rev&rev=556903
Log:
[JIRA CXF-799] Support for UsingAddressing assertion type.
{JIRA CXF-796] Configurable error handling for unknown assertion types.
Added:
incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/AssertionBuilderRegistryImplTest.java
(with props)
Modified:
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AssertionBuilderRegistry.java
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java
incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java
incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/policy/AddressingPolicyInterceptorProvider.java
incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/policy/MetadataConstants.java
incubator/cxf/trunk/rt/ws/addr/src/main/resources/META-INF/cxf/cxf-extension-addr.xml
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/AssertionBuilderRegistryImpl.java
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyBuilderImpl.java
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java
Modified:
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AssertionBuilderRegistry.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AssertionBuilderRegistry.java?view=diff&rev=556903&r1=556902&r2=556903
==============================================================================
---
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AssertionBuilderRegistry.java
(original)
+++
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AssertionBuilderRegistry.java
Tue Jul 17 05:32:21 2007
@@ -40,4 +40,22 @@
* @return an Assertion that is built using the specified element.
*/
Assertion build(Element element);
+
+ /**
+ * Indicates if unknown assertions should simply be ignored.
+ * If set to false, the policy engine will throw an exception upon
+ * encountering an assertion type for which no AssertionBuilder
+ * has been registered.
+ * @return
+ */
+ boolean isIgnoreUnknownAssertions();
+
+ /**
+ * Indicates if unknown assertions should simply be ignored.
+ * If set to false, the policy engine will throw an exception upon
+ * encountering an assertion type for which no AssertionBuilder
+ * has been registered.
+ * @param ignoreUnknownAssertions iff unknown assertions should be ignored
+ */
+ void setIgnoreUnknownAssertions(boolean ignoreUnknownAssertions);
}
Modified:
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java?view=diff&rev=556903&r1=556902&r2=556903
==============================================================================
---
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java
(original)
+++
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java
Tue Jul 17 05:32:21 2007
@@ -33,6 +33,8 @@
*
*/
public interface PolicyEngine {
+
+ // configuration
boolean isEnabled();
@@ -41,6 +43,12 @@
AlternativeSelector getAlternativeSelector();
void setAlternativeSelector(AlternativeSelector selector);
+
+ boolean isIgnoreUnknownAssertions();
+
+ void setIgnoreUnknownAssertions(boolean ignoreUnknownAssertions);
+
+ //
boolean supportsAlternative(Collection<Assertion> alterative, Assertor
assertor);
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=556903&r1=556902&r2=556903
==============================================================================
---
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
Tue Jul 17 05:32:21 2007
@@ -32,6 +32,7 @@
import java.util.logging.Logger;
import javax.wsdl.extensions.ExtensibilityElement;
+import javax.xml.namespace.QName;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.endpoint.Endpoint;
@@ -151,7 +152,8 @@
ret = usingAddressingAdvisory
|| WSAContextUtils.retrieveUsingAddressing(message)
|| hasUsingAddressing(message)
- || hasAddressingAssertion(message);
+ || hasAddressingAssertion(message)
+ || hasUsingAddressingAssertion(message);
} else {
ret = getMAPs(message, false, false) != null;
}
@@ -193,7 +195,7 @@
}
/**
- * Determine if the use of addressing is indicated by an assertion in the
+ * Determine if the use of addressing is indicated by an Addressing
assertion in the
* alternative chosen for the current message.
*
* @param message the current message
@@ -216,6 +218,35 @@
}
/**
+ * Determine if the use of addressing is indicated by a UsingAddressing in
the
+ * alternative chosen for the current message.
+ *
+ * @param message the current message
+ * @pre message is outbound
+ * @pre requestor role
+ */
+ private boolean hasUsingAddressingAssertion(Message message) {
+ AssertionInfoMap aim = message.get(AssertionInfoMap.class);
+ if (null == aim) {
+ return false;
+
+ }
+ Collection<AssertionInfo> ais =
aim.get(MetadataConstants.USING_ADDRESSING_2004_QNAME);
+ if (null != ais || ais.size() > 0) {
+ return true;
+ }
+ ais = aim.get(MetadataConstants.USING_ADDRESSING_2005_QNAME);
+ if (null != ais || ais.size() > 0) {
+ return true;
+ }
+ ais = aim.get(MetadataConstants.USING_ADDRESSING_2006_QNAME);
+ if (null != ais || ais.size() > 0) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
* Asserts all Addressing assertions for the current message, regardless
their nested
* Policies.
* @param message the current message
@@ -226,13 +257,20 @@
return;
}
- Collection<AssertionInfo> ais =
aim.get(MetadataConstants.ADDRESSING_ASSERTION_QNAME);
- if (null == ais || ais.size() == 0) {
- return;
- }
+ QName[] types = new QName[] {
+ MetadataConstants.ADDRESSING_ASSERTION_QNAME,
+ MetadataConstants.USING_ADDRESSING_2004_QNAME,
+ MetadataConstants.USING_ADDRESSING_2005_QNAME,
+ MetadataConstants.USING_ADDRESSING_2006_QNAME
+ };
- for (AssertionInfo ai : ais) {
- ai.setAsserted(true);
+ for (QName type : types) {
+ Collection<AssertionInfo> ais = aim.get(type);
+ if (null != ais) {
+ for (AssertionInfo ai : ais) {
+ ai.setAsserted(true);
+ }
+ }
}
}
Modified:
incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/policy/AddressingPolicyInterceptorProvider.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/policy/AddressingPolicyInterceptorProvider.java?view=diff&rev=556903&r1=556902&r2=556903
==============================================================================
---
incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/policy/AddressingPolicyInterceptorProvider.java
(original)
+++
incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/policy/AddressingPolicyInterceptorProvider.java
Tue Jul 17 05:32:21 2007
@@ -46,6 +46,9 @@
types.add(MetadataConstants.ADDRESSING_ASSERTION_QNAME);
types.add(MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME);
types.add(MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME);
+ types.add(MetadataConstants.USING_ADDRESSING_2004_QNAME);
+ types.add(MetadataConstants.USING_ADDRESSING_2005_QNAME);
+ types.add(MetadataConstants.USING_ADDRESSING_2006_QNAME);
ASSERTION_TYPES = types;
}
Modified:
incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/policy/MetadataConstants.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/policy/MetadataConstants.java?view=diff&rev=556903&r1=556902&r2=556903
==============================================================================
---
incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/policy/MetadataConstants.java
(original)
+++
incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/policy/MetadataConstants.java
Tue Jul 17 05:32:21 2007
@@ -31,6 +31,14 @@
public static final String ADDRESSING_ELEM_NAME = "Addressing";
public static final String ANON_RESPONSES_ELEM_NAME = "AnonymousResponses";
public static final String NON_ANON_RESPONSES_ELEM_NAME =
"NonAnonymousResponses";
+ public static final String USING_ADDRESSING_ELEM_NAME = "UsingAddressing";
+
+ public static final String ADDR_POLICY_2004_NAMESPACE_URI =
+ "http://schemas.xmlsoap.org/ws/2004/08/addressing/policy";
+ public static final String ADDR_WSDL_2005_NAMESPACE_URI =
+ "http://www.w3.org/2005/02/addressing/wsdl";
+ public static final String ADDR_WSDL_2006_NAMESPACE_URI =
+ "http://www.w3.org/2006/05/addressing/wsdl";
public static final QName ADDRESSING_ASSERTION_QNAME
= new QName(NAMESPACE_URI, ADDRESSING_ELEM_NAME);
@@ -38,6 +46,13 @@
= new QName(NAMESPACE_URI, ANON_RESPONSES_ELEM_NAME);
public static final QName NON_ANON_RESPONSES_ASSERTION_QNAME
= new QName(NAMESPACE_URI, NON_ANON_RESPONSES_ELEM_NAME);
+
+ public static final QName USING_ADDRESSING_2004_QNAME
+ = new QName(ADDR_POLICY_2004_NAMESPACE_URI,
USING_ADDRESSING_ELEM_NAME);
+ public static final QName USING_ADDRESSING_2005_QNAME
+ = new QName(ADDR_WSDL_2005_NAMESPACE_URI, USING_ADDRESSING_ELEM_NAME);
+ public static final QName USING_ADDRESSING_2006_QNAME
+ = new QName(ADDR_WSDL_2006_NAMESPACE_URI, USING_ADDRESSING_ELEM_NAME);
private MetadataConstants() {
}
Modified:
incubator/cxf/trunk/rt/ws/addr/src/main/resources/META-INF/cxf/cxf-extension-addr.xml
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/addr/src/main/resources/META-INF/cxf/cxf-extension-addr.xml?view=diff&rev=556903&r1=556902&r2=556903
==============================================================================
---
incubator/cxf/trunk/rt/ws/addr/src/main/resources/META-INF/cxf/cxf-extension-addr.xml
(original)
+++
incubator/cxf/trunk/rt/ws/addr/src/main/resources/META-INF/cxf/cxf-extension-addr.xml
Tue Jul 17 05:32:21 2007
@@ -28,4 +28,24 @@
<bean
class="org.apache.cxf.ws.addressing.policy.AddressingPolicyInterceptorProvider"/>
+ <bean
id="org.apache.cxf.ws.addressing.policy.UsingAddressingAssertionBuilder"
+
class="org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertionBuilder">
+ <property name="knownElements">
+ <set>
+ <bean class="javax.xml.namespace.QName">
+ <constructor-arg
value="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy"/>
+ <constructor-arg value="UsingAddressing"/>
+ </bean>
+ <bean class="javax.xml.namespace.QName">
+ <constructor-arg
value="http://www.w3.org/2005/02/addressing/wsdl"/>
+ <constructor-arg value="UsingAddressing"/>
+ </bean>
+ <bean class="javax.xml.namespace.QName">
+ <constructor-arg
value="http://www.w3.org/2006/05/addressing/wsdl"/>
+ <constructor-arg value="UsingAddressing"/>
+ </bean>
+ </set>
+ </property>
+ </bean>
+
</beans>
Modified:
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/AssertionBuilderRegistryImpl.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/AssertionBuilderRegistryImpl.java?view=diff&rev=556903&r1=556902&r2=556903
==============================================================================
---
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/AssertionBuilderRegistryImpl.java
(original)
+++
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/AssertionBuilderRegistryImpl.java
Tue Jul 17 05:32:21 2007
@@ -19,8 +19,11 @@
package org.apache.cxf.ws.policy;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
+import java.util.logging.Logger;
import javax.xml.namespace.QName;
@@ -28,6 +31,7 @@
import org.apache.cxf.common.i18n.BundleUtils;
import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.extension.BusExtension;
import org.apache.cxf.extension.RegistryImpl;
import org.apache.neethi.Assertion;
@@ -38,8 +42,13 @@
public class AssertionBuilderRegistryImpl extends RegistryImpl<QName,
AssertionBuilder> implements
AssertionBuilderRegistry, BusExtension {
- private static final ResourceBundle BUNDLE =
BundleUtils.getBundle(AssertionBuilderRegistry.class);
-
+ private static final ResourceBundle BUNDLE =
BundleUtils.getBundle(AssertionBuilderRegistryImpl.class);
+ private static final Logger LOG
+ = LogUtils.getL7dLogger(AssertionBuilderRegistryImpl.class);
+ private static final int IGNORED_CACHE_SIZE = 10;
+ private boolean ignoreUnknownAssertions;
+ private List<QName> ignored = new ArrayList<QName>(IGNORED_CACHE_SIZE);
+
public AssertionBuilderRegistryImpl() {
this(null);
}
@@ -52,6 +61,13 @@
return AssertionBuilderRegistry.class;
}
+ public boolean isIgnoreUnknownAssertions() {
+ return ignoreUnknownAssertions;
+ }
+
+ public void setIgnoreUnknownAssertions(boolean ignore) {
+ ignoreUnknownAssertions = ignore;
+ }
public Assertion build(Element element) {
@@ -61,7 +77,22 @@
builder = get(qname);
if (null == builder) {
- throw new PolicyException(new Message("NO_ASSERTIONBUILDER_EXC",
BUNDLE, qname.toString()));
+ Message m = new Message("NO_ASSERTIONBUILDER_EXC", BUNDLE,
qname.toString());
+ if (ignoreUnknownAssertions) {
+ boolean alreadyWarned = ignored.contains(qname);
+ if (alreadyWarned) {
+ ignored.remove(qname);
+ } else if (ignored.size() == IGNORED_CACHE_SIZE) {
+ ignored.remove(IGNORED_CACHE_SIZE - 1);
+ }
+ ignored.add(0, qname);
+ if (!alreadyWarned) {
+ LOG.warning(m.toString());
+ }
+ return null;
+ } else {
+ throw new PolicyException(m);
+ }
}
return builder.build(element);
Modified:
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyBuilderImpl.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyBuilderImpl.java?view=diff&rev=556903&r1=556902&r2=556903
==============================================================================
---
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyBuilderImpl.java
(original)
+++
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyBuilderImpl.java
Tue Jul 17 05:32:21 2007
@@ -184,7 +184,9 @@
} else if (null != assertionBuilderRegistry) {
Assertion a = assertionBuilderRegistry.build(childElement);
- operator.addPolicyComponent(a);
+ if (null != a) {
+ operator.addPolicyComponent(a);
+ }
}
}
return operator;
Modified:
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java?view=diff&rev=556903&r1=556902&r2=556903
==============================================================================
---
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java
(original)
+++
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java
Tue Jul 17 05:32:21 2007
@@ -58,6 +58,7 @@
private PolicyRegistry registry;
private Collection<PolicyProvider> policyProviders;
private boolean enabled;
+ private boolean ignoreUnknownAssertions;
private boolean addedBusInterceptors;
private AlternativeSelector alternativeSelector;
@@ -125,8 +126,17 @@
alternativeSelector = as;
}
+ public boolean isIgnoreUnknownAssertions() {
+ return ignoreUnknownAssertions;
+ }
+
+ public void setIgnoreUnknownAssertions(boolean ignore) {
+ ignoreUnknownAssertions = ignore;
+ }
+
// BusExtension interface
+
public Class<?> getRegistrationType() {
return PolicyEngine.class;
}
@@ -315,6 +325,11 @@
if (null == bus || !enabled) {
return;
+ }
+
+ AssertionBuilderRegistry abr =
bus.getExtension(AssertionBuilderRegistry.class);
+ if (null != abr) {
+ abr.setIgnoreUnknownAssertions(ignoreUnknownAssertions);
}
ClientPolicyOutInterceptor clientOut = new
ClientPolicyOutInterceptor();
Added:
incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/AssertionBuilderRegistryImplTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/AssertionBuilderRegistryImplTest.java?view=auto&rev=556903
==============================================================================
---
incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/AssertionBuilderRegistryImplTest.java
(added)
+++
incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/AssertionBuilderRegistryImplTest.java
Tue Jul 17 05:32:21 2007
@@ -0,0 +1,81 @@
+/**
+ * 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 javax.xml.namespace.QName;
+
+import org.w3c.dom.Element;
+
+import org.easymock.classextension.EasyMock;
+import org.easymock.classextension.IMocksControl;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class AssertionBuilderRegistryImplTest extends Assert {
+
+ private IMocksControl control;
+
+ @Before
+ public void setUp() {
+ control = EasyMock.createNiceControl();
+ }
+
+ @After
+ public void tearDown() {
+ control.verify();
+ }
+
+ @Test
+ public void testBuildUnknownAssertion() {
+ AssertionBuilderRegistry reg = new AssertionBuilderRegistryImpl();
+ Element[] elems = new Element[11];
+ QName[] qnames = new QName[11];
+ for (int i = 0; i < 11; i++) {
+ qnames[i] = new QName("http://my.company.com", "type" +
Integer.toString(i));
+ elems[i] = control.createMock(Element.class);
+
EasyMock.expect(elems[i].getNamespaceURI()).andReturn(qnames[i].getNamespaceURI()).anyTimes();
+
EasyMock.expect(elems[i].getLocalName()).andReturn(qnames[i].getLocalPart()).anyTimes();
+ }
+
+ control.replay();
+
+ assertTrue(!reg.isIgnoreUnknownAssertions());
+ try {
+ reg.build(elems[0]);
+ fail("Expected PolicyException not thrown.");
+ } catch (PolicyException ex) {
+ assertEquals("NO_ASSERTIONBUILDER_EXC", ex.getCode());
+ }
+ reg.setIgnoreUnknownAssertions(true);
+ assertTrue(reg.isIgnoreUnknownAssertions());
+ for (int i = 0; i < 10; i++) {
+ assertNull(reg.build(elems[i]));
+ }
+ for (int i = 9; i >= 0; i--) {
+ assertNull(reg.build(elems[i]));
+ }
+ assertNull(reg.build(elems[10]));
+ }
+}
Propchange:
incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/AssertionBuilderRegistryImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/AssertionBuilderRegistryImplTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date