Author: gdaniels
Date: Fri Mar 23 04:59:54 2007
New Revision: 521686
URL: http://svn.apache.org/viewvc?view=rev&rev=521686
Log:
Fix https://issues.apache.org/jira/browse/WSCOMMONS-151.
Disallow null or empty localName values when building OMAttributeImpls.
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMAttributeTest.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java?view=diff&rev=521686&r1=521685&r2=521686
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
Fri Mar 23 04:59:54 2007
@@ -43,8 +43,11 @@
* @param ns
* @param value
*/
- public OMAttributeImpl(String localName, OMNamespace ns, String value,
- OMFactory factory) {
+ public OMAttributeImpl(String localName, OMNamespace ns, String value,
OMFactory factory)
+ {
+ if (localName == null || localName.length() == 0)
+ throw new IllegalArgumentException("Local name may not be null or
empty");
+
this.localName = localName;
this.value = value;
this.namespace = ns;
@@ -77,6 +80,8 @@
* @param localName
*/
public void setLocalName(String localName) {
+ if (localName == null || localName.length() == 0)
+ throw new IllegalArgumentException("Local name may not be null or
empty");
this.localName = localName;
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMAttributeTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMAttributeTest.java?view=diff&rev=521686&r1=521685&r2=521686
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMAttributeTest.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMAttributeTest.java
Fri Mar 23 04:59:54 2007
@@ -29,67 +29,66 @@
public class OMAttributeTest extends TestCase {
- public void testAddAttribute() {
- String xmlString =
- "<soapenv:Envelope
xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header
name = \"jhon\"/><soapenv:Body><my:uploadFileUsingMTOM
xmlns:my=\"http://localhost/my\"><my:folderName>/home/saliya/Desktop</my:folderName></my:uploadFileUsingMTOM></soapenv:Body><Body>TTTT</Body>
</soapenv:Envelope>";
-
+ public void testNullLocalName() throws Exception {
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ try {
+ factory.createOMAttribute(null, null, null);
+ } catch (IllegalArgumentException e) {
+ return;
+ }
+ fail("Null localname was accepted!");
+ }
- String test1 = "";
- String test2 = "";
+ public void testEmptyLocalName() throws Exception {
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ try {
+ factory.createOMAttribute("", null, null);
+ } catch (IllegalArgumentException e) {
+ return;
+ }
+ fail("Empty localname was accepted!");
+ }
- test1 = addAttributeMethod1(xmlString);
- test2 = addAttributeMethod2(xmlString);
+ public void testAddAttribute() throws Exception {
+ String xmlString =
+ "<soapenv:Envelope
xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header
name = \"jhon\"/><soapenv:Body><my:uploadFileUsingMTOM
xmlns:my=\"http://localhost/my\"><my:folderName>/home/saliya/Desktop</my:folderName></my:uploadFileUsingMTOM></soapenv:Body><Body>TTTT</Body>
</soapenv:Envelope>";
- assertEquals(test1, test2);
+ assertEquals(addAttributeMethod1(xmlString),
addAttributeMethod2(xmlString));
}
- private String addAttributeMethod1(String xmlString) {
+ private String addAttributeMethod1(String xmlString) throws Exception {
XMLStreamReader parser2;
- try {
- parser2 = XMLInputFactory.newInstance()
- .createXMLStreamReader(new
ByteArrayInputStream(xmlString.getBytes()));
- StAXOMBuilder builder2 = new StAXOMBuilder(parser2);
- OMElement doc = builder2.getDocumentElement();
-
- OMFactory factory = OMAbstractFactory.getOMFactory();
- OMNamespace ns = factory.createOMNamespace("http://www.me.com",
"axiom");
-
- //code line to be tested
- OMAttribute at = factory.createOMAttribute("id", ns, "value");
- doc.addAttribute(at);
-
- return doc.toString();
-
- } catch (Exception e) {
- return "ERROR";
- //e.printStackTrace();
- }
+ parser2 = XMLInputFactory.newInstance()
+ .createXMLStreamReader(new
ByteArrayInputStream(xmlString.getBytes()));
+ StAXOMBuilder builder2 = new StAXOMBuilder(parser2);
+ OMElement doc = builder2.getDocumentElement();
+
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ OMNamespace ns = factory.createOMNamespace("http://www.me.com",
"axiom");
+
+ //code line to be tested
+ OMAttribute at = factory.createOMAttribute("id", ns, "value");
+ doc.addAttribute(at);
+ return doc.toString();
}
- private String addAttributeMethod2(String xmlString) {
+ private String addAttributeMethod2(String xmlString) throws Exception {
XMLStreamReader parser2;
- try {
- parser2 = XMLInputFactory.newInstance()
- .createXMLStreamReader(new
ByteArrayInputStream(xmlString.getBytes()));
- StAXOMBuilder builder2 = new StAXOMBuilder(parser2);
- OMElement doc = builder2.getDocumentElement();
-
- OMFactory factory = OMAbstractFactory.getOMFactory();
- OMNamespace ns = factory.createOMNamespace("http://www.me.com",
"axiom");
-
- //code line to be tested
- doc.addAttribute("id", "value", ns);
-
- return doc.toString();
-
- } catch (Exception e) {
- return "ERROR";
- //e.printStackTrace();
- }
+ parser2 = XMLInputFactory.newInstance()
+ .createXMLStreamReader(new
ByteArrayInputStream(xmlString.getBytes()));
+ StAXOMBuilder builder2 = new StAXOMBuilder(parser2);
+ OMElement doc = builder2.getDocumentElement();
+
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ OMNamespace ns = factory.createOMNamespace("http://www.me.com",
"axiom");
+
+ //code line to be tested
+ doc.addAttribute("id", "value", ns);
+ return doc.toString();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]