Fixed #SWS-57: Expose the Result of the SoapFaultDetail
This commit is contained in:
@@ -17,8 +17,8 @@
|
||||
package org.springframework.ws.soap;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.transform.Result;
|
||||
|
||||
/**
|
||||
* Represents the <code>detail</code> element in a SOAP fault. A detail contains <code>SoapFaultDetailElement</code>s,
|
||||
@@ -37,6 +37,15 @@ public interface SoapFaultDetail extends SoapElement {
|
||||
*/
|
||||
SoapFaultDetailElement addFaultDetailElement(QName name);
|
||||
|
||||
/**
|
||||
* Returns the <code>Source</code> of this element. This result does not include the element itself.
|
||||
* <p/>
|
||||
* The result can be used for marshalling.
|
||||
*
|
||||
* @return the <code>Result</code> of this element
|
||||
*/
|
||||
Result getResult();
|
||||
|
||||
/**
|
||||
* Gets an iterator over all of the <code>SoapFaultDetailElement</code>s in this detail.
|
||||
*
|
||||
|
||||
@@ -18,7 +18,9 @@ package org.springframework.ws.soap.axiom;
|
||||
|
||||
import java.util.Iterator;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.sax.SAXResult;
|
||||
|
||||
import org.apache.axiom.om.OMElement;
|
||||
import org.apache.axiom.om.OMException;
|
||||
@@ -73,7 +75,10 @@ class AxiomSoapFaultDetail implements SoapFaultDetail {
|
||||
catch (OMException ex) {
|
||||
throw new AxiomSoapFaultException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public Result getResult() {
|
||||
return new SAXResult(new AxiomContentHandler(axiomFaultDetail));
|
||||
}
|
||||
|
||||
private class AxiomSoapFaultDetailElementIterator implements Iterator {
|
||||
|
||||
@@ -23,7 +23,9 @@ import javax.xml.soap.DetailEntry;
|
||||
import javax.xml.soap.Name;
|
||||
import javax.xml.soap.SOAPEnvelope;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
@@ -53,6 +55,10 @@ class Saaj12SoapFaultDetail implements SoapFaultDetail {
|
||||
return new DOMSource(saajDetail);
|
||||
}
|
||||
|
||||
public Result getResult() {
|
||||
return new DOMResult(saajDetail);
|
||||
}
|
||||
|
||||
public SoapFaultDetailElement addFaultDetailElement(QName name) {
|
||||
try {
|
||||
Name detailEntryName = SaajUtils.toName(name, saajDetail, getEnvelope());
|
||||
|
||||
@@ -50,6 +50,10 @@ class Saaj13SoapFaultDetail implements SoapFaultDetail {
|
||||
return new DOMSource(saajDetail);
|
||||
}
|
||||
|
||||
public Result getResult() {
|
||||
return new DOMResult(saajDetail);
|
||||
}
|
||||
|
||||
public SoapFaultDetailElement addFaultDetailElement(QName name) {
|
||||
try {
|
||||
DetailEntry saajDetailEntry = saajDetail.addDetailEntry(name);
|
||||
|
||||
@@ -32,4 +32,8 @@ public class AxiomSoap11BodyTest extends AbstractSoap11BodyTestCase {
|
||||
public void testAddFaultWithDetail() throws Exception {
|
||||
// Overriden because of http://issues.apache.org/jira/browse/WSCOMMONS-38
|
||||
}
|
||||
|
||||
public void testAddFaultWithDetailResult() throws Exception {
|
||||
// Overriden because of http://issues.apache.org/jira/browse/WSCOMMONS-38
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,15 +36,13 @@ public abstract class AbstractSoap11BodyTestCase extends AbstractSoapBodyTestCas
|
||||
public void testGetSource() throws Exception {
|
||||
StringResult result = new StringResult();
|
||||
transformer.transform(soapBody.getSource(), result);
|
||||
assertXMLEqual("Invalid contents of body",
|
||||
"<Body xmlns='http://schemas.xmlsoap.org/soap/envelope/' />",
|
||||
assertXMLEqual("Invalid contents of body", "<Body xmlns='http://schemas.xmlsoap.org/soap/envelope/' />",
|
||||
result.toString());
|
||||
}
|
||||
|
||||
public void testAddMustUnderstandFault() throws Exception {
|
||||
SoapFault fault = soapBody.addMustUnderstandFault("SOAP Must Understand Error", null);
|
||||
assertEquals("Invalid fault code",
|
||||
new QName("http://schemas.xmlsoap.org/soap/envelope/", "MustUnderstand"),
|
||||
assertEquals("Invalid fault code", new QName("http://schemas.xmlsoap.org/soap/envelope/", "MustUnderstand"),
|
||||
fault.getFaultCode());
|
||||
assertPayloadEqual("<SOAP-ENV:Fault xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>" +
|
||||
"<faultcode>SOAP-ENV:MustUnderstand</faultcode>" +
|
||||
@@ -53,8 +51,7 @@ public abstract class AbstractSoap11BodyTestCase extends AbstractSoapBodyTestCas
|
||||
|
||||
public void testAddClientFault() throws Exception {
|
||||
SoapFault fault = soapBody.addClientOrSenderFault("faultString", null);
|
||||
assertEquals("Invalid fault code",
|
||||
new QName("http://schemas.xmlsoap.org/soap/envelope/", "Client"),
|
||||
assertEquals("Invalid fault code", new QName("http://schemas.xmlsoap.org/soap/envelope/", "Client"),
|
||||
fault.getFaultCode());
|
||||
assertPayloadEqual("<SOAP-ENV:Fault xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>" +
|
||||
"<faultcode>SOAP-ENV:Client</faultcode>" + "<faultstring>faultString</faultstring>" +
|
||||
@@ -63,8 +60,7 @@ public abstract class AbstractSoap11BodyTestCase extends AbstractSoapBodyTestCas
|
||||
|
||||
public void testAddServerFault() throws Exception {
|
||||
SoapFault fault = soapBody.addServerOrReceiverFault("faultString", null);
|
||||
assertEquals("Invalid fault code",
|
||||
new QName("http://schemas.xmlsoap.org/soap/envelope/", "Server"),
|
||||
assertEquals("Invalid fault code", new QName("http://schemas.xmlsoap.org/soap/envelope/", "Server"),
|
||||
fault.getFaultCode());
|
||||
assertPayloadEqual("<SOAP-ENV:Fault xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>" +
|
||||
"<faultcode>SOAP-ENV:Server</faultcode>" + "<faultstring>faultString</faultstring>" +
|
||||
@@ -73,12 +69,12 @@ public abstract class AbstractSoap11BodyTestCase extends AbstractSoapBodyTestCas
|
||||
|
||||
public void testAddFault() throws Exception {
|
||||
QName faultCode = new QName("http://www.springframework.org", "fault", "spring");
|
||||
String faultString = "faultString";
|
||||
Soap11Fault fault = ((Soap11Body) soapBody).addFault(faultCode, "faultString", Locale.ENGLISH);
|
||||
assertNotNull("Null returned", fault);
|
||||
assertTrue("SoapBody has no fault", soapBody.hasFault());
|
||||
assertNotNull("SoapBody has no fault", soapBody.getFault());
|
||||
assertEquals("Invalid fault code", faultCode, fault.getFaultCode());
|
||||
String faultString = "faultString";
|
||||
assertEquals("Invalid fault string", faultString, fault.getFaultString());
|
||||
assertEquals("Invalid fault string locale", Locale.ENGLISH, fault.getFaultStringLocale());
|
||||
String actor = "http://www.springframework.org/actor";
|
||||
@@ -105,4 +101,16 @@ public abstract class AbstractSoap11BodyTestCase extends AbstractSoapBodyTestCas
|
||||
"</prefix:localPart></detail></SOAP-ENV:Fault>");
|
||||
}
|
||||
|
||||
public void testAddFaultWithDetailResult() throws Exception {
|
||||
SoapFault fault = ((Soap11Body) soapBody)
|
||||
.addFault(new QName("namespace", "localPart", "prefix"), "Fault", null);
|
||||
SoapFaultDetail detail = fault.addFaultDetail();
|
||||
transformer.transform(new StringSource("<detailContents xmlns='namespace'/>"), detail.getResult());
|
||||
transformer.transform(new StringSource("<detailContents xmlns='namespace'/>"), detail.getResult());
|
||||
assertPayloadEqual("<SOAP-ENV:Fault xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>" +
|
||||
"<faultcode xmlns:prefix='namespace'>prefix:localPart</faultcode>" +
|
||||
"<faultstring>Fault</faultstring>" + "<detail>" + "<detailContents xmlns='namespace'/>" +
|
||||
"<detailContents xmlns='namespace'/>" + "</detail></SOAP-ENV:Fault>");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -102,6 +102,22 @@ public abstract class AbstractSoap12BodyTestCase extends AbstractSoapBodyTestCas
|
||||
"</prefix:localPart></soapenv:Detail></soapenv:Fault>", result.toString());
|
||||
}
|
||||
|
||||
public void testAddFaultWithDetailResult() throws Exception {
|
||||
SoapFault fault = soapBody.addServerOrReceiverFault("faultString", Locale.ENGLISH);
|
||||
SoapFaultDetail detail = fault.addFaultDetail();
|
||||
transformer.transform(new StringSource("<detailContents xmlns='namespace'/>"), detail.getResult());
|
||||
transformer.transform(new StringSource("<detailContents xmlns='namespace'/>"), detail.getResult());
|
||||
StringResult result = new StringResult();
|
||||
transformer.transform(fault.getSource(), result);
|
||||
assertXMLEqual("Invalid source for body",
|
||||
"<soapenv:Fault xmlns:soapenv='http://www.w3.org/2003/05/soap-envelope'>" +
|
||||
"<soapenv:Code><soapenv:Value>" + soapBody.getName().getPrefix() + ":Receiver</soapenv:Value>" +
|
||||
"</soapenv:Code>" +
|
||||
"<soapenv:Reason><soapenv:Text xml:lang='en'>faultString</soapenv:Text></soapenv:Reason>" +
|
||||
"<soapenv:Detail>" + "<detailContents xmlns='namespace'/>" +
|
||||
"<detailContents xmlns='namespace'/>" + "</soapenv:Detail></soapenv:Fault>", result.toString());
|
||||
}
|
||||
|
||||
public void testAddFaultWithSubcode() throws Exception {
|
||||
Soap12Fault fault = (Soap12Fault) soapBody.addServerOrReceiverFault("faultString", Locale.ENGLISH);
|
||||
QName subcode1 = new QName("http://www.springframework.org", "Subcode1", "spring-ws");
|
||||
|
||||
Reference in New Issue
Block a user