[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/b906f99c Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/b906f99c Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/b906f99c Branch: refs/heads/3.0.x-fixes Commit: b906f99c54d58756f31f1a58663e139331c0dbbb Parents: 40c2449 Author: Daniel Kulp <[email protected]> Authored: Mon Apr 13 15:08:13 2015 -0400 Committer: Daniel Kulp <[email protected]> Committed: Mon Apr 13 15:29:13 2015 -0400 ---------------------------------------------------------------------- .../selector/MinimalAlternativeSelector.java | 21 ++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/b906f99c/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) {
