Skip to content

Commit a7aee7c

Browse files
committed
[CAMEL-10578] Use proper methods for adding namespace declarations to DOM
1 parent 54826e8 commit a7aee7c

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java

+11-8
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.apache.cxf.binding.soap.Soap12;
5757
import org.apache.cxf.binding.soap.SoapBindingConstants;
5858
import org.apache.cxf.binding.soap.SoapHeader;
59+
import org.apache.cxf.common.util.StringUtils;
5960
import org.apache.cxf.endpoint.Client;
6061
import org.apache.cxf.endpoint.Endpoint;
6162
import org.apache.cxf.headers.Header;
@@ -180,9 +181,7 @@ public void populateExchangeFromCxfResponse(Exchange camelExchange,
180181

181182
// propagate protocol headers
182183
propagateHeadersFromCxfToCamel(cxfMessage, camelExchange.getOut(), camelExchange);
183-
DataFormat dataFormat = camelExchange.getProperty(CxfConstants.DATA_FORMAT_PROPERTY,
184-
DataFormat.class);
185-
boolean isXop = Boolean.valueOf(camelExchange.getProperty(Message.MTOM_ENABLED, String.class));
184+
186185
// propagate attachments
187186
if (cxfMessage.getAttachments() != null) {
188187
// propagate attachments
@@ -761,15 +760,19 @@ protected static Object getContentFromCxf(Message message, DataFormat dataFormat
761760
}
762761

763762
protected static void addNamespace(Element element, Map<String, String> nsMap) {
764-
for (String ns : nsMap.keySet()) {
763+
for (Map.Entry<String, String> ns : nsMap.entrySet()) {
765764
// We should not override the namespace setting of the element
766-
if (XMLConstants.XMLNS_ATTRIBUTE.equals(ns)) {
765+
if (XMLConstants.XMLNS_ATTRIBUTE.equals(ns.getKey())) {
766+
if (ObjectHelper.isEmpty(element.getAttribute(XMLConstants.XMLNS_ATTRIBUTE))) {
767+
element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, ns.getKey(), ns.getValue());
768+
}
769+
} else if (StringUtils.isEmpty(ns.getKey())) {
767770
if (ObjectHelper.isEmpty(element.getAttribute(XMLConstants.XMLNS_ATTRIBUTE))) {
768-
element.setAttribute(ns, nsMap.get(ns));
771+
element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns", ns.getValue());
769772
}
770773
} else {
771-
if (ObjectHelper.isEmpty(element.getAttribute(XMLConstants.XMLNS_ATTRIBUTE + ":" + ns))) {
772-
element.setAttribute(XMLConstants.XMLNS_ATTRIBUTE + ":" + ns, nsMap.get(ns));
774+
if (ObjectHelper.isEmpty(element.getAttribute(XMLConstants.XMLNS_ATTRIBUTE + ":" + ns.getKey()))) {
775+
element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE + ":" + ns.getKey(), ns.getValue());
773776
}
774777
}
775778
}

0 commit comments

Comments
 (0)