From 35be612396d0f3a92a4982c09435ab970aac321c Mon Sep 17 00:00:00 2001 From: Andreas Veithen Date: Sat, 6 Apr 2013 21:10:20 +0200 Subject: [PATCH] Prevent invalid Axiom attributes Axiom 1.2.14 allows creation of attributes with a namespace URI and an empty prefix, but the behavior for attributes with such an invalid name is undefined. Axiom 1.2.15 will refuse to create such an attribute. This change modifies AxiomSoapElement#addAttribute so that it lets Axiom generate a prefix if necessary. All tests now pass successfully with Axiom 1.2.15-SNAPSHOT. --- .../ws/soap/axiom/AxiomSoapElement.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapElement.java b/core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapElement.java index bfc3b699..4999f4e2 100644 --- a/core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapElement.java +++ b/core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapElement.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,17 +22,17 @@ import java.util.List; import javax.xml.namespace.QName; import javax.xml.transform.Source; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; -import org.springframework.util.xml.StaxUtils; -import org.springframework.ws.soap.SoapElement; - import org.apache.axiom.om.OMAttribute; import org.apache.axiom.om.OMElement; import org.apache.axiom.om.OMException; import org.apache.axiom.om.OMNamespace; import org.apache.axiom.soap.SOAPFactory; +import org.springframework.util.Assert; +import org.springframework.util.StringUtils; +import org.springframework.util.xml.StaxUtils; +import org.springframework.ws.soap.SoapElement; + /** * Axiom-specific version of {@link SoapElement}. * @@ -72,8 +72,14 @@ class AxiomSoapElement implements SoapElement { public final void addAttribute(QName name, String value) { try { - OMNamespace namespace = getAxiomFactory().createOMNamespace(name.getNamespaceURI(), name.getPrefix()); - OMAttribute attribute = getAxiomFactory().createOMAttribute(name.getLocalPart(), namespace, value); + String namespaceUri = name.getNamespaceURI(); + String prefix = name.getPrefix(); + if (StringUtils.hasLength(namespaceUri) && !StringUtils.hasLength(prefix)) { + prefix = null; + } + OMNamespace namespace = + getAxiomFactory().createOMNamespace(namespaceUri, prefix); + OMAttribute attribute = getAxiomFactory().createOMAttribute(name.getLocalPart(), namespace, value); getAxiomElement().addAttribute(attribute); } catch (OMException ex) {