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.
This commit is contained in:
Andreas Veithen
2013-04-06 21:10:20 +02:00
committed by Arjen Poutsma
parent c7311f4baf
commit 35be612396

View File

@@ -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) {