axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: ws-axis/java/test/saaj TestSOAPFaults.java
Date Tue, 06 Jul 2004 19:00:55 GMT
dims        2004/07/06 12:00:55

  Modified:    java/src/org/apache/axis/message Detail.java
                        DetailEntry.java SOAPFault.java
               java/test/functional TestJAXMSamples.java
               java/test/saaj TestSOAPFaults.java
  Removed:     java/samples/jaxm SOAPFaultTest.java
  Log:
  Fix for AXIS-1432 : Creating a SOAPFault with additional detail elements
  
  Notes:
  - moved a test case that was in samples/jaxm into test/saaj itself.
  
  Revision  Changes    Path
  1.10      +1 -20     ws-axis/java/src/org/apache/axis/message/Detail.java
  
  Index: Detail.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/message/Detail.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Detail.java	25 Feb 2004 14:02:42 -0000	1.9
  +++ Detail.java	6 Jul 2004 19:00:54 -0000	1.10
  @@ -30,21 +30,9 @@
    *
    * @author Davanum Srinivas (dims@yahoo.com)
    */
  -public class Detail extends SOAPFault implements javax.xml.soap.Detail {
  -
  -    public Detail(String namespace, String localName, String prefix,
  -                  Attributes attrs, DeserializationContext context)
  -            throws AxisFault
  -    {
  -        super(namespace, localName, prefix, attrs, context);
  -    }
  +public class Detail extends SOAPFaultElement implements javax.xml.soap.Detail {
   
       public Detail() {
  -        super(new AxisFault());
  -    }
  -
  -    public Detail(AxisFault fault) {
  -        super(fault);
       }
   
       /**
  @@ -57,13 +45,6 @@
       public DetailEntry addDetailEntry(Name name) throws SOAPException {
           org.apache.axis.message.DetailEntry entry = new org.apache.axis.message.DetailEntry(name);
           addChildElement(entry);
  -        if(fault != null) {
  -            try {
  -                fault.addFaultDetail(entry.getAsDOM());
  -            } catch (Exception e) {
  -                throw new SOAPException(e);
  -            }
  -        }
           return entry;
       }
   
  
  
  
  1.6       +0 -8      ws-axis/java/src/org/apache/axis/message/DetailEntry.java
  
  Index: DetailEntry.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/message/DetailEntry.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DetailEntry.java	25 Feb 2004 14:02:42 -0000	1.5
  +++ DetailEntry.java	6 Jul 2004 19:00:54 -0000	1.6
  @@ -25,12 +25,4 @@
       public DetailEntry(javax.xml.soap.Name name){
           super(name);
       }
  -
  -    public javax.xml.soap.SOAPElement addTextNode(String text) throws javax.xml.soap.SOAPException
{
  -        javax.xml.soap.SOAPElement element = super.addTextNode(text);
  -        org.apache.axis.message.Detail detail = (org.apache.axis.message.Detail)this.getParentElement();
  -        org.apache.axis.AxisFault fault = detail.getFault();
  -        fault.addFaultDetailString(text);
  -        return element;
  -    }
   }
  
  
  
  1.29      +13 -3     ws-axis/java/src/org/apache/axis/message/SOAPFault.java
  
  Index: SOAPFault.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/message/SOAPFault.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- SOAPFault.java	27 Jun 2004 12:28:31 -0000	1.28
  +++ SOAPFault.java	6 Jul 2004 19:00:54 -0000	1.29
  @@ -36,6 +36,7 @@
   import java.io.IOException;
   import java.util.List;
   import java.util.Locale;
  +import java.util.Iterator;
   
   /** A Fault body element.
    *
  @@ -48,6 +49,7 @@
       protected AxisFault fault;
       protected String prefix;
       private java.util.Locale locale;
  +    protected Detail detail = null;
       
       public SOAPFault(String namespace, String localName, String prefix,
                        Attributes attrs, DeserializationContext context)
  @@ -62,7 +64,7 @@
       }
       
       public void outputImpl(SerializationContext context)
  -            throws IOException
  +            throws Exception
       {
           SOAPConstants soapConstants = context.getMessageContext() == null ?
                                           SOAPConstants.SOAP11_CONSTANTS :
  @@ -166,6 +168,13 @@
                   for (int i = 0; i < faultDetails.length; i++) {
                       context.writeDOMElement(faultDetails[i]);
                   }
  +
  +                if (detail!= null) {
  +                    for (Iterator it = detail.getChildren().iterator(); it.hasNext();)
{
  +                        ((NodeImpl)it.next()).output(context);
  +                    }
  +                }
  +        
                   context.endElement();
               }
           }
  @@ -360,11 +369,12 @@
        * @return a detail element contructed from the AxisFault details
        * @throws SOAPException
        */
  -    private static Detail convertToDetail(AxisFault fault)
  +    private Detail convertToDetail(AxisFault fault)
               throws SOAPException
       {
  -        Detail detail = new Detail(fault);
  +        detail = new Detail();
           Element[] darray = fault.getFaultDetails();
  +        fault.setFaultDetail(new Element[]{});
           for (int i = 0; i < darray.length; i++)
           {
               Element detailtEntryElem = darray[i];
  
  
  
  1.23      +0 -11     ws-axis/java/test/functional/TestJAXMSamples.java
  
  Index: TestJAXMSamples.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/test/functional/TestJAXMSamples.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- TestJAXMSamples.java	25 Feb 2004 14:02:55 -0000	1.22
  +++ TestJAXMSamples.java	6 Jul 2004 19:00:55 -0000	1.23
  @@ -21,8 +21,6 @@
   import org.apache.axis.components.logger.LogFactory;
   import org.apache.commons.logging.Log;
   import samples.jaxm.DelayedStockQuote;
  -import samples.jaxm.SOAPFaultTest;
  -import samples.jaxm.UddiPing;
   
   import javax.xml.messaging.URLEndpoint;
   import javax.xml.soap.MessageFactory;
  @@ -46,15 +44,6 @@
       public TestJAXMSamples(String name) {
           super(name);
       } // ctor
  -
  -    public void testSOAPFaultTest () throws Exception {
  -        try {
  -            SOAPFaultTest.main(new String[0]);
  -        } catch (Throwable t) {
  -            t.printStackTrace();
  -            throw new Exception("Fault returned from test: " + t);
  -        }
  -    }
   
   //    // This is timing out for some reason - removed for the nonce.
   //    // -- gdaniels, 4/21/2003
  
  
  
  1.2       +130 -1    ws-axis/java/test/saaj/TestSOAPFaults.java
  
  Index: TestSOAPFaults.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/test/saaj/TestSOAPFaults.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestSOAPFaults.java	10 Jun 2003 16:27:34 -0000	1.1
  +++ TestSOAPFaults.java	6 Jul 2004 19:00:55 -0000	1.2
  @@ -1,13 +1,24 @@
   package test.saaj;
   
  +import test.AxisTestBase;
  +
   import javax.xml.soap.Detail;
   import javax.xml.soap.MessageFactory;
   import javax.xml.soap.SOAPFactory;
   import javax.xml.soap.SOAPFault;
   import javax.xml.soap.SOAPMessage;
  +import javax.xml.soap.SOAPElement;
  +import javax.xml.soap.DetailEntry;
  +import javax.xml.soap.Name;
  +import javax.xml.soap.SOAPPart;
  +import javax.xml.soap.SOAPEnvelope;
  +import javax.xml.soap.SOAPBody;
  +import javax.xml.soap.SOAPHeader;
  +import javax.xml.soap.SOAPHeaderElement;
   import java.io.ByteArrayOutputStream;
  +import java.util.Iterator;
   
  -public class TestSOAPFaults extends junit.framework.TestCase {
  +public class TestSOAPFaults extends AxisTestBase {
       public TestSOAPFaults(String name) {
           super(name);
       }
  @@ -33,6 +44,124 @@
           }
           String xml = new String(baos.toByteArray());
           assertTrue(xml.indexOf("Hello")!=-1);
  +    }
  +    
  +    public void testSOAPFaultSaveChanges() throws Exception {
  +        MessageFactory msgFactory =
  +                MessageFactory.newInstance();
  +        SOAPMessage msg = msgFactory.createMessage();
  +        SOAPEnvelope envelope =
  +                msg.getSOAPPart().getEnvelope();
  +        SOAPBody body = envelope.getBody();
  +        SOAPFault fault = body.addFault();
  +
  +        fault.setFaultCode("Client");
  +        fault.setFaultString(
  +                "Message does not have necessary info");
  +        fault.setFaultActor("http://gizmos.com/order");
  +
  +        Detail detail = fault.addDetail();
  +
  +        Name entryName = envelope.createName("order", "PO",
  +                "http://gizmos.com/orders/");
  +        DetailEntry entry = detail.addDetailEntry(entryName);
  +        entry.addTextNode(
  +                "quantity element does not have a value");
  +
  +        Name entryName2 = envelope.createName("confirmation",
  +                "PO", "http://gizmos.com/confirm");
  +        DetailEntry entry2 = detail.addDetailEntry(entryName2);
  +        entry2.addTextNode("Incomplete address: no zip code");
  +
  +        msg.saveChanges();
  +
  +        // Now retrieve the SOAPFault object and its contents
  +        //after checking to see that there is one
  +
  +        if (body.hasFault()) {
  +            fault = body.getFault();
  +            String code = fault.getFaultCode();
  +            String string = fault.getFaultString();
  +            String actor = fault.getFaultActor();
  +
  +            System.out.println("SOAP fault contains: ");
  +            System.out.println("    fault code = " + code);
  +            System.out.println("    fault string = " + string);
  +            if (actor != null) {
  +                System.out.println("    fault actor = " + actor);
  +            }
  +
  +            detail = fault.getDetail();
  +            if (detail != null) {
  +                Iterator it = detail.getDetailEntries();
  +                while (it.hasNext()) {
  +                    entry = (DetailEntry) it.next();
  +                    String value = entry.getValue();
  +                    System.out.println("    Detail entry = " + value);
  +                }
  +            }
  +        }
  +        
  +    }
  +
  +    public void testAxis1432() throws Exception {
  +        String xml ="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:cwmp=\"http://cwmp.com\">\n" +
  +                " <soapenv:Header>\n" +
  +                "  <cwmp:ID soapenv:mustUnderstand=\"1\">HEADERID-7867678</cwmp:ID>\n"
+
  +                " </soapenv:Header>\n" +
  +                " <soapenv:Body>\n" +
  +                "  <soapenv:Fault>\n" +
  +                "   <faultcode>soapenv:Client</faultcode>\n" +
  +                "   <faultstring>CWMP fault</faultstring>\n" +
  +                "   <detail>\n" +
  +                "    <cwmp:Fault>\n" +
  +                "     <cwmp:FaultCode>This is the fault code</cwmp:FaultCode>\n"
+
  +                "     <cwmp:FaultString>Fault Message</cwmp:FaultString>\n"
+
  +                "    </cwmp:Fault>\n" +
  +                "   </detail>\n" +
  +                "  </soapenv:Fault>\n" +
  +                " </soapenv:Body>\n" +
  +                "</soapenv:Envelope>";
  +        
  +        MessageFactory fac = MessageFactory.newInstance();
  +        SOAPMessage faultMessage = fac.createMessage();
  +
  +        // Create the response to the message
  +        faultMessage = fac.createMessage();
  +        SOAPPart part = faultMessage.getSOAPPart();
  +        SOAPEnvelope envelope = part.getEnvelope();
  +        envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
  +        SOAPBody body = envelope.getBody();
  +        SOAPHeader header = envelope.getHeader();
  +        Name idName = envelope.createName("ID", "cwmp", "http://cwmp.com");
  +        SOAPHeaderElement id = header.addHeaderElement(idName);
  +        id.setMustUnderstand(true);
  +        id.addTextNode("HEADERID-7867678");
  +        id.setActor(null);
  +
  +        // Create the SOAPFault object
  +        SOAPFault fault = body.addFault();
  +        fault.setFaultCode("Client");
  +        fault.setFaultString("CWMP fault");
  +        fault.setFaultActor(null);
  +
  +        // Add Fault Detail information
  +        Detail faultDetail = fault.addDetail();
  +        Name cwmpFaultName = envelope.createName("Fault", "cwmp",
  +                "http://cwmp.com");
  +        DetailEntry cwmpFaultDetail =
  +                faultDetail.addDetailEntry(cwmpFaultName);
  +        SOAPElement e = cwmpFaultDetail.addChildElement("FaultCode");
  +
  +        e.addTextNode("This is the fault code");
  +        SOAPElement e2 = cwmpFaultDetail.addChildElement(envelope.createName("FaultString",
"cwmp", "http://cwmp.com"));
  +        e2.addTextNode("Fault Message");
  +        faultMessage.saveChanges();
  +
  +        ByteArrayOutputStream baos = new ByteArrayOutputStream();
  +        faultMessage.writeTo(baos);
  +        String xml2 = new String(baos.toByteArray());
  +        assertXMLEqual(xml,xml2);
       }
   
       public static void main(String[] args) throws Exception {
  
  
  

Mime
View raw message