Return-Path: Delivered-To: apmail-xml-axis-dev-archive@xml.apache.org Received: (qmail 11824 invoked by uid 500); 17 Dec 2002 20:10:56 -0000 Mailing-List: contact axis-dev-help@xml.apache.org; run by ezmlm Precedence: bulk Reply-To: axis-dev@xml.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list axis-dev@xml.apache.org Received: (qmail 11815 invoked by uid 500); 17 Dec 2002 20:10:56 -0000 Delivered-To: apmail-xml-axis-cvs@apache.org Date: 17 Dec 2002 20:10:55 -0000 Message-ID: <20021217201055.87016.qmail@icarus.apache.org> From: tomj@apache.org To: xml-axis-cvs@apache.org Subject: cvs commit: xml-axis/java/src/org/apache/axis/message SOAPFault.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N tomj 2002/12/17 12:10:54 Modified: java/test/saaj PackageTests.java build.xml java/src/org/apache/axis/message SOAPFault.java Added: java/test/saaj TestSOAPFaultDetail.java Log: Fix for bug 14611: Fault Detail access code inside SOAPFault operates on the detail objects NOT used in serialization Use the utility code provided in the bug by Jan Hrabowski [jhrabows@brooks.com] to tie the AxisFault details to the SOAPFaultDetails. Add a test case to verify this works as expected. Turned off the Axis server when running the SAAJ tests. This change should have the SAAJ TCK test run against it to verify compliance with the SAAJ spec. Revision Changes Path 1.5 +1 -0 xml-axis/java/test/saaj/PackageTests.java Index: PackageTests.java =================================================================== RCS file: /home/cvs/xml-axis/java/test/saaj/PackageTests.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- PackageTests.java 6 Sep 2002 20:09:26 -0000 1.4 +++ PackageTests.java 17 Dec 2002 20:10:54 -0000 1.5 @@ -19,6 +19,7 @@ } }catch( Throwable t){;} suite.addTestSuite(test.saaj.TestEnvelope.class); + suite.addTestSuite(test.saaj.TestSOAPFaultDetail.class); return suite; } } 1.6 +1 -1 xml-axis/java/test/saaj/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/xml-axis/java/test/saaj/build.xml,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- build.xml 10 Sep 2002 16:06:52 -0000 1.5 +++ build.xml 17 Dec 2002 20:10:54 -0000 1.6 @@ -60,7 +60,7 @@ - + 1.1 xml-axis/java/test/saaj/TestSOAPFaultDetail.java Index: TestSOAPFaultDetail.java =================================================================== package test.saaj; import org.apache.axis.Message; import org.apache.axis.MessageContext; import org.apache.axis.server.AxisServer; import org.apache.axis.message.SOAPBodyElement; import org.apache.axis.message.SOAPFault; import org.apache.axis.message.SOAPEnvelope; import org.apache.axis.encoding.DeserializationContextImpl; import org.apache.axis.encoding.DeserializationContext; import org.xml.sax.InputSource; import javax.xml.soap.DetailEntry; import java.io.Reader; import java.io.StringReader; import java.util.Iterator; public class TestSOAPFaultDetail extends junit.framework.TestCase { private MessageContext _msgContext; public TestSOAPFaultDetail(String name) { super(name); _msgContext = new MessageContext(new AxisServer()); } String xmlString = "" + "" + " " + " " + " soapenv:Server.generalException" + " " + " " + " MACR" + " test.wsdl.faults.InvalidTickerFaultMessage" + " " + " " + " " + ""; public void testDetails() throws Exception { Reader reader = new StringReader(xmlString); InputSource src = new InputSource(reader); SOAPBodyElement bodyItem = getFirstBody(src); assertTrue("The SOAPBodyElement I got was not a SOAPFault", bodyItem instanceof SOAPFault); SOAPFault flt = (SOAPFault)bodyItem; flt.addDetail(); javax.xml.soap.Detail d = flt.getDetail(); Iterator i = d.getDetailEntries(); while (i.hasNext()) { DetailEntry entry = (DetailEntry) i.next(); String name = entry.getElementName().getLocalName(); if ("tickerSymbol".equals(name)) { assertEquals("the value of the tickerSymbol element didn't match", "MACR", entry.getValue()); } else if ("exceptionName".equals(name)) { assertEquals("the value of the exceptionName element didn't match", "test.wsdl.faults.InvalidTickerFaultMessage", entry.getValue()); } else { assertTrue("Expecting details element name of 'tickerSymbol' or 'expceptionName' - I found :" + name, false); } } assertTrue(d != null); } private SOAPBodyElement getFirstBody(InputSource msgSource) throws Exception { DeserializationContext dser = new DeserializationContextImpl( msgSource, _msgContext, Message.RESPONSE); dser.parse(); SOAPEnvelope env = dser.getEnvelope(); return env.getFirstBody(); } /** * Main */ public static void main(String[] args) throws Exception { TestSOAPFaultDetail detailTest = new TestSOAPFaultDetail("faultdetails"); detailTest.testDetails(); } } 1.12 +81 -6 xml-axis/java/src/org/apache/axis/message/SOAPFault.java Index: SOAPFault.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/SOAPFault.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- SOAPFault.java 11 Dec 2002 22:38:20 -0000 1.11 +++ SOAPFault.java 17 Dec 2002 20:10:54 -0000 1.12 @@ -62,11 +62,15 @@ import org.apache.axis.soap.SOAPConstants; import org.apache.axis.utils.Messages; import org.w3c.dom.Element; +import org.w3c.dom.Node; import org.xml.sax.Attributes; import javax.xml.namespace.QName; import javax.xml.soap.SOAPException; +import javax.xml.soap.SOAPElement; +import javax.xml.soap.DetailEntry; import java.io.IOException; +import java.util.ArrayList; /** A Fault body element. * @@ -82,7 +86,6 @@ Attributes attrs, DeserializationContext context) { super(namespace, localName, prefix, attrs, context); - this.fault = fault; } public SOAPFault(AxisFault fault) @@ -107,7 +110,7 @@ // XXX - Can fault be anything but an AxisFault here? if (fault instanceof AxisFault) { - AxisFault axisFault = (AxisFault) fault; + AxisFault axisFault = fault; if (axisFault.getFaultCode() != null) { // Do this BEFORE starting the element, so the prefix gets // registered if needed. @@ -299,9 +302,18 @@ * application-specific error information */ public javax.xml.soap.Detail getDetail() { - if(this.getChildren()==null || this.getChildren().size()<=0) + ArrayList children = this.getChildren(); + if(children==null || children.size()<=0) return null; - return (javax.xml.soap.Detail) this.getChildren().get(0); + + // find detail element + for (int i=0; i < children.size(); i++) { + Object obj = children.get(i); + if (obj instanceof javax.xml.soap.Detail) { + return (javax.xml.soap.Detail) obj; + } + } + return null; } /** @@ -318,11 +330,74 @@ * Detail object */ public javax.xml.soap.Detail addDetail() throws SOAPException { - if(getDetail()!=null){ + if(getDetail() != null){ throw new SOAPException(Messages.getMessage("valuePresent")); } - Detail detail = new Detail(fault); + Detail detail = convertToDetail(fault); addChildElement(detail); return detail; + } + + + /** + * Convert the details in an AxisFault to a Detail object + * + * @param fault source of the fault details + * @return a detail element contructed from the AxisFault details + * @throws SOAPException + */ + private static Detail convertToDetail(AxisFault fault) + throws SOAPException + { + Detail detail = new Detail(fault); + Element[] darray = fault.getFaultDetails(); + for (int i = 0; i < darray.length; i++) + { + Element detailtEntryElem = darray[i]; + DetailEntry detailEntry = detail.addDetailEntry( + new PrefixedQName(detailtEntryElem.getNamespaceURI(), + detailtEntryElem.getLocalName(), detailtEntryElem.getPrefix())); + copyChildren(detailEntry, detailtEntryElem); + } + return detail; + } + + /** + * Copy the children of a DOM element to a SOAPElement. + * + * @param soapElement target of the copy + * @param domElement source for the copy + * @throws SOAPException + */ + private static void copyChildren(SOAPElement soapElement, Element domElement) + throws SOAPException + { + org.w3c.dom.NodeList nl = domElement.getChildNodes(); + for (int j = 0; j < nl.getLength(); j++) + { + org.w3c.dom.Node childNode = nl.item(j); + if (childNode.getNodeType() == Node.TEXT_NODE) + { + soapElement.addTextNode(childNode.getNodeValue()); + break; // only one text node assmed + } + if (childNode.getNodeType() == Node.ELEMENT_NODE) + { + String uri = childNode.getNamespaceURI(); + SOAPElement childSoapElement = null; + if (uri == null) + { + childSoapElement = soapElement.addChildElement(childNode.getLocalName + ()); + } + else + { + childSoapElement = soapElement.addChildElement( + childNode.getLocalName(), + childNode.getPrefix(), uri); + } + copyChildren(childSoapElement, (Element) childNode); + } + } } }