Fix of non thread safe map reqHeaders - SOAP_ACTION is shared between different requests
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/193c5c40 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/193c5c40 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/193c5c40 Branch: refs/heads/3.1.x-fixes Commit: 193c5c4095d93ca8efe3e9a4b91fba705de8af46 Parents: 45ec20a Author: Dmitry Panov <vbnhfy...@gmail.com> Authored: Wed Aug 30 15:58:42 2017 +0200 Committer: Dennis Kieselhorst <m...@dekies.de> Committed: Wed Aug 30 16:10:31 2017 +0200 ---------------------------------------------------------------------- .../SoapPreProtocolOutInterceptor.java | 49 ++++++++++---------- 1 file changed, 25 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/193c5c40/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapPreProtocolOutInterceptor.java ---------------------------------------------------------------------- diff --git a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapPreProtocolOutInterceptor.java b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapPreProtocolOutInterceptor.java index d782ea1..0035705 100644 --- a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapPreProtocolOutInterceptor.java +++ b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapPreProtocolOutInterceptor.java @@ -52,7 +52,7 @@ public class SoapPreProtocolOutInterceptor extends AbstractSoapInterceptor { /** * Mediate a message dispatch. - * + * * @param message the current message * @throws Fault */ @@ -64,10 +64,10 @@ public class SoapPreProtocolOutInterceptor extends AbstractSoapInterceptor { } } - + /** * Ensure the SOAP version is set for this message. - * + * * @param message the current message */ private void ensureVersion(SoapMessage message) { @@ -77,18 +77,18 @@ public class SoapPreProtocolOutInterceptor extends AbstractSoapInterceptor { soapVersion = ((SoapMessage)message.getExchange().getInMessage()).getVersion(); message.setVersion(soapVersion); } - + if (soapVersion == null) { soapVersion = Soap11.getInstance(); message.setVersion(soapVersion); } - + message.put(Message.CONTENT_TYPE, soapVersion.getContentType()); } - + /** * Ensure the SOAP header is set for this message. - * + * * @param message the current message */ private void ensureMimeHeaders(SoapMessage message) { @@ -102,32 +102,33 @@ public class SoapPreProtocolOutInterceptor extends AbstractSoapInterceptor { message.put("soap.attachement.content.transfer.encoding", cte); } } - + private void setSoapAction(SoapMessage message) { BindingOperationInfo boi = message.getExchange().getBindingOperationInfo(); - + // The soap action is set on the wrapped operation. if (boi != null && boi.isUnwrapped()) { boi = boi.getWrappedOperation(); } - + String action = getSoapAction(message, boi); - + if (message.getVersion() instanceof Soap11) { - Map<String, List<String>> reqHeaders - = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS)); - if (reqHeaders == null) { - reqHeaders = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER); + Map<String, List<String>> tempReqHeaders = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER); + Map<String, List<String>> reqHeaders + = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS)); + if (reqHeaders != null) { + tempReqHeaders.putAll(reqHeaders); } - - if (reqHeaders.size() == 0) { - message.put(Message.PROTOCOL_HEADERS, reqHeaders); + + if (!tempReqHeaders.containsKey(SoapBindingConstants.SOAP_ACTION)) { + tempReqHeaders.put(SoapBindingConstants.SOAP_ACTION, Collections.singletonList(action)); } - - reqHeaders.put(SoapBindingConstants.SOAP_ACTION, Collections.singletonList(action)); + + message.put(Message.PROTOCOL_HEADERS, tempReqHeaders); } else if (message.getVersion() instanceof Soap12 && !"\"\"".equals(action)) { String ct = (String) message.get(Message.CONTENT_TYPE); - + if (ct.indexOf("action=\"") == -1) { ct = new StringBuilder().append(ct) .append("; action=").append(action).toString(); @@ -139,7 +140,7 @@ public class SoapPreProtocolOutInterceptor extends AbstractSoapInterceptor { private String getSoapAction(SoapMessage message, BindingOperationInfo boi) { // allow an interceptor to override the SOAPAction if need be String action = (String) message.get(SoapBindingConstants.SOAP_ACTION); - + // Fall back on the SOAPAction in the operation info if (action == null) { if (boi == null) { @@ -149,11 +150,11 @@ public class SoapPreProtocolOutInterceptor extends AbstractSoapInterceptor { action = soi == null ? "\"\"" : soi.getAction() == null ? "\"\"" : soi.getAction(); } } - + if (!action.startsWith("\"")) { action = new StringBuilder().append("\"").append(action).append("\"").toString(); } - + return action; }