axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdani...@apache.org
Subject cvs commit: xml-axis/java/test/faults FaultDecode.java
Date Mon, 19 Nov 2001 21:21:00 GMT
gdaniels    01/11/19 13:21:00

  Modified:    java/src/org/apache/axis/encoding
                        DeserializationContext.java
               java/src/org/apache/axis/message MessageElement.java
                        SOAPFaultBuilder.java
               java/test/faults FaultDecode.java
  Log:
  Make deserialization of fault details actually work.
  
  This required a change to the general deserialization code, in that
  MessageElements now need to keep track of their children as well as
  their parent.  This is to allow grabbing an element like <detail> and
  walking a list of its children so that we can turn them into DOM Elements
  and load them into the AxisFault.   This is a bit of a lose in terms of space
  and performance, though.
  
  Update fault decoder unit test to test more stuff.
  
  Revision  Changes    Path
  1.38      +5 -1      xml-axis/java/src/org/apache/axis/encoding/DeserializationContext.java
  
  Index: DeserializationContext.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/DeserializationContext.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- DeserializationContext.java	2001/11/16 02:57:54	1.37
  +++ DeserializationContext.java	2001/11/19 21:21:00	1.38
  @@ -156,7 +156,11 @@
       }
       
       MessageElement curElement;
  -    
  +
  +    public MessageElement getCurElement() {
  +        return curElement;
  +    }
  +
       public void setCurElement(MessageElement el)
       {
           curElement = el;
  
  
  
  1.64      +22 -2     xml-axis/java/src/org/apache/axis/message/MessageElement.java
  
  Index: MessageElement.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/MessageElement.java,v
  retrieving revision 1.63
  retrieving revision 1.64
  diff -u -r1.63 -r1.64
  --- MessageElement.java	2001/11/14 16:13:47	1.63
  +++ MessageElement.java	2001/11/19 21:21:00	1.64
  @@ -223,8 +223,28 @@
       public void setRecorder(SAX2EventRecorder rec) { recorder = rec; }
   
       public MessageElement getParent() { return parent; }
  -    public void setParent(MessageElement parent) { this.parent = parent; }
  -
  +    public void setParent(MessageElement parent) 
  +    { 
  +        this.parent = parent;
  +        if (parent != null) {
  +            parent.addChild(this);
  +        }
  +    }
  +    
  +    private ArrayList children = null;
  +    
  +    public void addChild(MessageElement el)
  +    {
  +        if (children == null)
  +            children = new ArrayList();
  +        children.add(el);
  +    }
  +    
  +    public ArrayList getChildren()
  +    {
  +        return children;
  +    }
  +    
       public void setContentsIndex(int index)
       {
           startContentsIndex = index;
  
  
  
  1.12      +27 -3     xml-axis/java/src/org/apache/axis/message/SOAPFaultBuilder.java
  
  Index: SOAPFaultBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/SOAPFaultBuilder.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- SOAPFaultBuilder.java	2001/11/07 19:17:16	1.11
  +++ SOAPFaultBuilder.java	2001/11/19 21:21:00	1.12
  @@ -62,9 +62,12 @@
   import org.apache.axis.utils.QFault;
   import org.xml.sax.Attributes;
   import org.xml.sax.SAXException;
  +import org.w3c.dom.Element;
   
   import javax.xml.rpc.namespace.QName;
   import java.util.HashMap;
  +import java.util.ArrayList;
  +import java.util.Iterator;
   
   /** 
    * Build a Fault body element.
  @@ -83,7 +86,7 @@
           fields.put("faultcode", SOAPTypeMappingRegistry.XSD_STRING);
           fields.put("faultstring", SOAPTypeMappingRegistry.XSD_STRING);
           fields.put("faultactor", SOAPTypeMappingRegistry.XSD_STRING);
  -        fields.put("details", null);
  +        fields.put("detail", null);
       }
       
       public SOAPFaultBuilder(SOAPFaultElement element,
  @@ -111,8 +114,29 @@
           }
           
           return currentDeser;
  -    } 
  -    
  +    }
  +
  +    public void onEndChild(String namespace, String localName,
  +                           DeserializationContext context)
  +            throws SAXException {
  +        if ("detail".equals(localName)) {
  +            MessageElement el = context.getCurElement();
  +            ArrayList children = el.getChildren();
  +            if (children != null) {
  +                Element [] elements = new Element [children.size()];
  +                for (int i = 0; i < elements.length; i++) {
  +                    try {
  +                        elements[i] = ((MessageElement)children.get(i)).
  +                                                                    getAsDOM();
  +                    } catch (Exception e) {
  +                        throw new SAXException(e);
  +                    }
  +                }
  +                fault.setFaultDetails(elements);
  +            }
  +        }
  +    }
  +
       public void valueReady(Object value, Object hint)
       {
           String name = (String)hint;
  
  
  
  1.7       +55 -15    xml-axis/java/test/faults/FaultDecode.java
  
  Index: FaultDecode.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/faults/FaultDecode.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FaultDecode.java	2001/11/07 19:20:48	1.6
  +++ FaultDecode.java	2001/11/19 21:21:00	1.7
  @@ -55,25 +55,41 @@
   package test.faults;
   
   import junit.framework.TestCase;
  +import junit.framework.TestResult;
  +import junit.framework.Test;
  +import junit.framework.TestSuite;
  +import junit.textui.TestRunner;
   import org.apache.axis.AxisFault;
   import org.apache.axis.Message;
   import org.apache.axis.MessageContext;
  +import org.apache.axis.utils.QFault;
   import org.apache.axis.message.SOAPBodyElement;
   import org.apache.axis.message.SOAPEnvelope;
   import org.apache.axis.message.SOAPFaultElement;
   import org.apache.axis.server.AxisServer;
  +import org.w3c.dom.Element;
  +import org.w3c.dom.Text;
   
   /**
  - * This class tests a case where the fault is not filled in..
  + * This class tests Fault deserialization.
    *
    * @author Mark Roder <mroder@wamnet.com>
  + * @author Glen Daniels (gdaniels@macromedia.com)
    */
   
   public class FaultDecode extends TestCase {
  -
  +    public static final String FAULT_CODE = "Some.FaultCode";
  +    public static final String FAULT_STRING = "This caused a fault";
  +    public static final String DETAIL_ENTRY_TEXT =
  +        "This was a really bad thing";
  +    
       public FaultDecode(String name) {
           super(name);
       } // ctor
  +    
  +    public static Test suite() {
  +        return new TestSuite(FaultDecode.class);
  +    }
   
       public void testFault() throws Exception {
           String messageText = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"
soap:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
  @@ -82,9 +98,9 @@
               + "</soap:Header> "
               + "<soap:Body>  "
               + "     <soap:Fault>"
  -            + "              <faultcode>Some.FaultCode</faultcode>"
  -            + "              <faultstring>This caused a fault</faultstring>"
  -            + "              <detail>This was a really bad thing</detail>"
  +            + "          <faultcode>" + FAULT_CODE + "</faultcode>"
  +            + "          <faultstring>" + FAULT_STRING + "</faultstring>"
  +            + "          <detail><d1>" + DETAIL_ENTRY_TEXT + "</d1></detail>"
               + "     </soap:Fault>"
               + "</soap:Body>"
               + "</soap:Envelope>";
  @@ -94,20 +110,44 @@
           message.setMessageContext(new MessageContext(server));
   
           SOAPEnvelope envelope = (SOAPEnvelope) message.getSOAPPart().getAsSOAPEnvelope();
  -        this.assertNotNull("envelope", envelope);
  +        assertNotNull("envelope", envelope);
   
           SOAPBodyElement respBody = envelope.getFirstBody();
  -        this.assertTrue("respBody should be a SOAPFaultElement", respBody
  +        assertTrue("respBody should be a SOAPFaultElement", respBody
                           instanceof SOAPFaultElement);
           AxisFault aFault = ((SOAPFaultElement) respBody).getAxisFault();
  -
  -        //Leave in until getFaultDetails is tested
  -        System.out.println(aFault);
   
  -        this.assertNotNull("Fault should not be null", aFault);
  -        this.assertNotNull("faultCode should not be null", aFault.getFaultCode());
  -        this.assertNotNull("faultString should not be null", aFault.getFaultString());
  -        //7 Nov 01 comment out to get tests to pass to allow this to be integrated
  -        //this.assertNotNull("faultDetails should not be null", aFault.getFaultDetails());
  +        assertNotNull("Fault should not be null", aFault);
  +        
  +        QFault faultCode = aFault.getFaultCode();
  +        assertNotNull("faultCode should not be null", faultCode);
  +        assertEquals("faultCode should match",
  +                     faultCode.getLocalPart(), 
  +                     "Some.FaultCode");
  +        
  +        String faultString = aFault.getFaultString();
  +        assertNotNull("faultString should not be null", faultString);
  +        assertEquals("faultString should match", faultString,
  +                     FAULT_STRING);
  +        
  +        Element [] details = aFault.getFaultDetails();
  +        assertNotNull("faultDetails should not be null", details);
  +        assertEquals("details should have exactly one element", details.length, 
  +                     1);
  +        
  +        Element el = details[0];
  +        assertEquals("detail entry tag name should match",
  +                     el.getLocalName(), "d1");
  +        
  +        Text text = (Text)el.getFirstChild();
  +        assertEquals("detail entry string should match",
  +                     text.getData(), DETAIL_ENTRY_TEXT);
  +        
       } // testFault
  +    
  +    public static void main(String[] args) throws Exception {
  +        FaultDecode tester = new FaultDecode("test");
  +        TestRunner runner = new TestRunner();
  +        runner.doRun(tester.suite(), false);
  +    }
   }
  
  
  

Mime
View raw message