dims 2002/06/21 06:00:37 Modified: java/src/org/apache/axis/message HeaderBuilder.java java/test/encoding TestDOM.java Added: java/src/org/apache/axis/message HeaderElementBuilder.java Log: - Fix for Bug 10091 Message with 3 headers causes NPE - Testcase for making sure this does not happen again :-) Revision Changes Path 1.12 +16 -32 xml-axis/java/src/org/apache/axis/message/HeaderBuilder.java Index: HeaderBuilder.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/HeaderBuilder.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- HeaderBuilder.java 24 May 2002 18:20:43 -0000 1.11 +++ HeaderBuilder.java 21 Jun 2002 13:00:37 -0000 1.12 @@ -2,7 +2,7 @@ * The Apache Software License, Version 1.1 * * - * Copyright (c) 2001 The Apache Software Foundation. All rights + * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -10,7 +10,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -18,7 +18,7 @@ * distribution. * * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: + * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, @@ -26,7 +26,7 @@ * * 4. The names "Axis" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this - * software without prior written permission. For written + * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", @@ -56,7 +56,7 @@ package org.apache.axis.message; /** - * + * * @author Glen Daniels ([EMAIL PROTECTED]) */ @@ -66,30 +66,26 @@ import org.xml.sax.Attributes; import org.xml.sax.SAXException; -public class HeaderBuilder extends SOAPHandler -{ +public class HeaderBuilder extends SOAPHandler { protected static Log log = - LogFactory.getLog(HeaderBuilder.class.getName()); + LogFactory.getLog(HeaderBuilder.class.getName()); - private SOAPHeaderElement header; private SOAPEnvelope envelope; - - HeaderBuilder(SOAPEnvelope envelope) - { + + HeaderBuilder(SOAPEnvelope envelope) { this.envelope = envelope; } - + public void startElement(String namespace, String localName, String qName, Attributes attributes, DeserializationContext context) - throws SAXException - { + throws SAXException { if (!context.isDoneParsing()) { if (myElement == null) { myElement = new SOAPHeader(namespace, localName, qName, - attributes, context, - envelope.getSOAPConstants()); - envelope.setHeader((SOAPHeader)myElement); + attributes, context, + envelope.getSOAPConstants()); + envelope.setHeader((SOAPHeader) myElement); } context.pushNewElement(myElement); } @@ -100,20 +96,8 @@ String prefix, Attributes attributes, DeserializationContext context) - throws SAXException - { - header = new SOAPHeaderElement(namespace, localName, prefix, - attributes, context); - - SOAPHandler handler = new SOAPHandler(); - handler.myElement = header; - + throws SAXException { + HeaderElementBuilder handler = new HeaderElementBuilder((SOAPHeader) myElement); return handler; - } - - public void onEndChild(String namespace, String localName, - DeserializationContext context) - { - envelope.addHeader(header); } } 1.1 xml-axis/java/src/org/apache/axis/message/HeaderElementBuilder.java Index: HeaderElementBuilder.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Axis" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.axis.message; /** * * @author Davanum Srinivas ([EMAIL PROTECTED]) */ import org.apache.axis.encoding.DeserializationContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.xml.sax.Attributes; import org.xml.sax.SAXException; public class HeaderElementBuilder extends SOAPHandler { protected static Log log = LogFactory.getLog(HeaderElementBuilder.class.getName()); private SOAPHeader header; HeaderElementBuilder(SOAPHeader header) { this.header = header; } public void startElement(String namespace, String localName, String qName, Attributes attributes, DeserializationContext context) throws SAXException { if (!context.isDoneParsing()) { if (myElement == null) { myElement = new SOAPHeaderElement(namespace, localName, "", attributes, context); header.addHeader((SOAPHeaderElement) myElement); } context.pushNewElement(myElement); } } } 1.12 +32 -1 xml-axis/java/test/encoding/TestDOM.java Index: TestDOM.java =================================================================== RCS file: /home/cvs/xml-axis/java/test/encoding/TestDOM.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- TestDOM.java 29 May 2002 14:30:02 -0000 1.11 +++ TestDOM.java 21 Jun 2002 13:00:37 -0000 1.12 @@ -8,6 +8,7 @@ import org.apache.axis.MessageContext; import org.apache.axis.message.SOAPBodyElement; import org.apache.axis.message.SOAPEnvelope; +import org.apache.axis.message.SOAPHeaderElement; import org.apache.axis.server.AxisServer; import org.apache.axis.utils.XMLUtils; @@ -53,7 +54,7 @@ AxisEngine engine = new AxisServer(); engine.init(); MessageContext msgContext = new MessageContext(engine); - msgContext.setHighFidelity(true); + msgContext.setHighFidelity(true); Message message = new Message(request); message.setMessageContext(msgContext); @@ -65,6 +66,35 @@ assertEquals("Request is not the same as the result.", request, result); } + public void testHeaders() throws Exception { + AxisEngine engine = new AxisServer(); + engine.init(); + MessageContext msgContext = new MessageContext(engine); + msgContext.setHighFidelity(true); + Message message = new Message(request); + message.setMessageContext(msgContext); + + // Now completely round trip it + SOAPEnvelope envelope = message.getSOAPEnvelope(); + envelope.addHeader(new SOAPHeaderElement("foo1", "foo1")); + envelope.addHeader(new SOAPHeaderElement("foo2", "foo2")); + envelope.addHeader(new SOAPHeaderElement("foo3", "foo3")); + String result = message.getSOAPPartAsString(); + + assertTrue(result.indexOf("foo1")!=-1); + assertTrue(result.indexOf("foo2")!=-1); + assertTrue(result.indexOf("foo3")!=-1); + + Message message2 = new Message(result); + message2.setMessageContext(msgContext); + SOAPEnvelope envelope2 = message2.getSOAPEnvelope(); + String result2 = message2.getSOAPPartAsString(); + + assertTrue(result2.indexOf("foo1")!=-1); + assertTrue(result2.indexOf("foo2")!=-1); + assertTrue(result2.indexOf("foo3")!=-1); + } + public void testEmptyNode() throws Exception { SOAPBodyElement body = new SOAPBodyElement(XMLUtils.newDocument().createElement("tmp")); @@ -82,6 +112,7 @@ public static void main(String [] args) throws Exception { TestDOM tester = new TestDOM("TestDOM"); + tester.testHeaders(); tester.testNodeWithAttribute(); tester.testEmptyNode(); tester.testDOM();