dims 2002/06/23 07:25:52
Modified: java/src/org/apache/axis/message Detail.java
DetailEntry.java SOAPBody.java SOAPFault.java
java/test/functional TestJAXMSamples.java
Added: java/samples/jaxm SOAPFaultTest.java
Log:
Hooking up Detail/DetailEntry etc of SAAJ.
Revision Changes Path
1.1 xml-axis/java/samples/jaxm/SOAPFaultTest.java
Index: SOAPFaultTest.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002 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 samples.jaxm;
import javax.xml.soap.Detail;
import javax.xml.soap.DetailEntry;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.Name;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPFault;
import javax.xml.soap.SOAPMessage;
import java.util.Iterator;
public class SOAPFaultTest {
public static void main(String[] args) 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);
}
}
}
}
}
1.4 +5 -4 xml-axis/java/src/org/apache/axis/message/Detail.java
Index: Detail.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/Detail.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Detail.java 22 Jun 2002 23:14:04 -0000 1.3
+++ Detail.java 23 Jun 2002 14:25:51 -0000 1.4
@@ -63,6 +63,7 @@
import javax.xml.soap.Name;
import javax.xml.soap.SOAPException;
import java.util.Iterator;
+import java.util.Vector;
/**
* Detail Container implementation
@@ -92,8 +93,9 @@
* @throws SOAPException thrown when there is a problem in adding a
DetailEntry object to this Detail object.
*/
public DetailEntry addDetailEntry(Name name) throws SOAPException {
- //TODO: Flesh this out.
- return null;
+ DetailEntry entry = new org.apache.axis.message.DetailEntry(name);
+ addChildElement(entry);
+ return entry;
}
/**
@@ -102,7 +104,6 @@
* objects in this <code>Detail</code> object
*/
public Iterator getDetailEntries() {
- //TODO: Flesh this out.
- return null;
+ return this.getChildElements();
}
}
1.2 +3 -0 xml-axis/java/src/org/apache/axis/message/DetailEntry.java
Index: DetailEntry.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/DetailEntry.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DetailEntry.java 29 May 2002 17:00:00 -0000 1.1
+++ DetailEntry.java 23 Jun 2002 14:25:51 -0000 1.2
@@ -61,4 +61,7 @@
* @author Davanum Srinivas ([EMAIL PROTECTED])
*/
public class DetailEntry extends MessageElement implements
javax.xml.soap.DetailEntry {
+ public DetailEntry(javax.xml.soap.Name name){
+ super(name);
+ }
}
1.21 +15 -5 xml-axis/java/src/org/apache/axis/message/SOAPBody.java
Index: SOAPBody.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/SOAPBody.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- SOAPBody.java 11 Jun 2002 14:53:59 -0000 1.20
+++ SOAPBody.java 23 Jun 2002 14:25:51 -0000 1.21
@@ -222,17 +222,27 @@
}
public javax.xml.soap.SOAPFault addFault() throws SOAPException {
- // not yet implemented
- return null;
+ SOAPFault fault = new SOAPFault(new AxisFault());
+ addBodyElement(fault);
+ return fault;
}
public javax.xml.soap.SOAPFault getFault() {
- // not yet implemented
- return null;
+ try {
+ return
(javax.xml.soap.SOAPFault)getBodyByName(Constants.URI_SOAP11_ENV,
Constants.ELEM_FAULT);
+ } catch(AxisFault af){
+ log.fatal(JavaUtils.getMessage("exception00"), af);
+ return null;
+ }
}
public boolean hasFault() {
- // not yet implemented
+ try {
+ if(getBodyByName(Constants.URI_SOAP11_ENV, Constants.ELEM_FAULT)!=null)
+ return true;
+ } catch(AxisFault af){
+ log.fatal(JavaUtils.getMessage("exception00"), af);
+ }
return false;
}
}
1.3 +9 -4 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SOAPFault.java 22 Jun 2002 23:14:04 -0000 1.2
+++ SOAPFault.java 23 Jun 2002 14:25:51 -0000 1.3
@@ -237,8 +237,9 @@
* application-specific error information
*/
public javax.xml.soap.Detail getDetail() {
- //TODO: Flesh this out.
- return null;
+ if(this.getChildren()==null || this.getChildren().size()<=0)
+ return null;
+ return (javax.xml.soap.Detail) this.getChildren().get(0);
}
/**
@@ -255,7 +256,11 @@
* <CODE>Detail</CODE> object
*/
public javax.xml.soap.Detail addDetail() throws javax.xml.soap.SOAPException {
- //TODO: Flesh this out.
- return null;
+ if(getDetail()!=null){
+ throw new
javax.xml.soap.SOAPException(org.apache.axis.utils.JavaUtils.getMessage("valuePresent"));
+ }
+ Detail detail = new Detail(fault);
+ addChildElement(detail);
+ return detail;
}
}
1.6 +11 -1 xml-axis/java/test/functional/TestJAXMSamples.java
Index: TestJAXMSamples.java
===================================================================
RCS file: /home/cvs/xml-axis/java/test/functional/TestJAXMSamples.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TestJAXMSamples.java 22 Jun 2002 16:15:34 -0000 1.5
+++ TestJAXMSamples.java 23 Jun 2002 14:25:52 -0000 1.6
@@ -61,6 +61,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import samples.jaxm.UddiPing;
+import samples.jaxm.SOAPFaultTest;
import java.net.ConnectException;
@@ -74,6 +75,15 @@
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);
+ }
+ }
+
public void testUddiPing() throws Exception {
try {
log.info("Testing JAXM UddiPing sample.");
@@ -129,7 +139,7 @@
public static void main(String args[]) throws Exception {
TestJAXMSamples tester = new TestJAXMSamples("tester");
- tester.testUddiPing();
+ tester.testSOAPFaultTest();
} // main
}