Repository: cxf Updated Branches: refs/heads/master c04c27200 -> 5f5db6440
[CXF-6315] When chosing the alternative for the response, use the longest one that matched so any optionals that were asserted on the incoming message will apply to the outgoing message as well. Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/5f5db644 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/5f5db644 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/5f5db644 Branch: refs/heads/master Commit: 5f5db64402557f5cfa7390353ebd33c0728cb382 Parents: c04c272 Author: Daniel Kulp <[email protected]> Authored: Mon Apr 13 15:08:13 2015 -0400 Committer: Daniel Kulp <[email protected]> Committed: Mon Apr 13 15:08:13 2015 -0400 ---------------------------------------------------------------------- .../selector/MinimalAlternativeSelector.java | 21 ++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/5f5db644/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MinimalAlternativeSelector.java ---------------------------------------------------------------------- diff --git a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MinimalAlternativeSelector.java b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MinimalAlternativeSelector.java index 2926859..06cab19 100644 --- a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MinimalAlternativeSelector.java +++ b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MinimalAlternativeSelector.java @@ -33,7 +33,7 @@ import org.apache.neethi.Policy; * */ public class MinimalAlternativeSelector extends BaseAlternativeSelector { - + public Collection<Assertion> selectAlternative( Policy policy, PolicyEngine engine, Assertor assertor, @@ -46,9 +46,22 @@ public class MinimalAlternativeSelector extends BaseAlternativeSelector { List<Assertion> alternative = alternatives.next(); if (engine.supportsAlternative(alternative, assertor, msg) - && isCompatibleWithRequest(alternative, request) - && (null == choice || alternative.size() < choice.size())) { - choice = alternative; + && isCompatibleWithRequest(alternative, request)) { + + if (null == choice) { + choice = alternative; + } else if (request != null) { + //we have a request policy, we likely want the one longest alternative that + //matches as any of "optional" incoming policies so that asssertions that were + //asserted on the incoming will also be assertable on the outgoing. + //Example: ws:addressing policy asserted on incoming should also be + // used to add headers for the response + if (alternative.size() > choice.size()) { + choice = alternative; + } + } else if (alternative.size() < choice.size()) { + choice = alternative; + } } } if (choice == null) {
