Author: alex.guizar(a)jboss.com
Date: 2007-03-10 12:15:29 -0500 (Sat, 10 Mar 2007)
New Revision: 2582
Modified:
trunk/jbossws-core/src/java/javax/xml/soap/SOAPConstants.java
trunk/jbossws-core/src/java/org/jboss/ws/Constants.java
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/SOAPFaultHelperJAXWS.java
trunk/jbossws-core/src/java/org/jboss/ws/core/soap/DetailImpl.java
trunk/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java
trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPBodyImpl.java
trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPElementImpl.java
trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPFaultElementImpl.java
trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPFaultImpl.java
trunk/jbossws-core/src/java/org/jboss/ws/metadata/umdm/FaultMetaData.java
Log:
JBCTS-442 implemented SAAJ 1.3 behavior, moved detail element
population code from EnvelopeBuilderDOM to Detail itself
Modified: trunk/jbossws-core/src/java/javax/xml/soap/SOAPConstants.java
===================================================================
--- trunk/jbossws-core/src/java/javax/xml/soap/SOAPConstants.java 2007-03-10 17:09:00 UTC
(rev 2581)
+++ trunk/jbossws-core/src/java/javax/xml/soap/SOAPConstants.java 2007-03-10 17:15:29 UTC
(rev 2582)
@@ -63,13 +63,13 @@
/** The URI identifying the next application processing a SOAP request as the intended
actor for a SOAP 1.1 header entry (see section 4.2.2 of the SOAP 1.1 specification). */
String URI_SOAP_ACTOR_NEXT = "http://schemas.xmlsoap.org/soap/actor/next";
/** SOAP 1.2 VersionMismatch Fault */
- QName SOAP_VERSIONMISMATCH_FAULT = new
QName("http://www.w3.org/2003/05/soap-envelope", "VersionMismatch");
+ QName SOAP_VERSIONMISMATCH_FAULT = new QName(URI_NS_SOAP_1_2_ENVELOPE,
"VersionMismatch", SOAP_ENV_PREFIX);
/** SOAP 1.2 MustUnderstand Fault */
- QName SOAP_MUSTUNDERSTAND_FAULT = new
QName("http://www.w3.org/2003/05/soap-envelope", "MustUnderstand");
+ QName SOAP_MUSTUNDERSTAND_FAULT = new QName(URI_NS_SOAP_1_2_ENVELOPE,
"MustUnderstand", SOAP_ENV_PREFIX);
/** SOAP 1.2 DataEncodingUnknown Fault */
- QName SOAP_DATAENCODINGUNKNOWN_FAULT = new
QName("http://www.w3.org/2003/05/soap-envelope",
"DataEncodingUnknown");
+ QName SOAP_DATAENCODINGUNKNOWN_FAULT = new QName(URI_NS_SOAP_1_2_ENVELOPE,
"DataEncodingUnknown", SOAP_ENV_PREFIX);
/** SOAP 1.2 Sender Fault */
- QName SOAP_SENDER_FAULT = new
QName("http://www.w3.org/2003/05/soap-envelope", "Sender");
+ QName SOAP_SENDER_FAULT = new QName(URI_NS_SOAP_1_2_ENVELOPE, "Sender",
SOAP_ENV_PREFIX);
/** SOAP 1.2 Receiver Fault */
- QName SOAP_RECEIVER_FAULT = new
QName("http://www.w3.org/2003/05/soap-envelope", "Receiver");
+ QName SOAP_RECEIVER_FAULT = new QName(URI_NS_SOAP_1_2_ENVELOPE, "Receiver",
SOAP_ENV_PREFIX);
}
Modified: trunk/jbossws-core/src/java/org/jboss/ws/Constants.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/Constants.java 2007-03-10 17:09:00 UTC (rev
2581)
+++ trunk/jbossws-core/src/java/org/jboss/ws/Constants.java 2007-03-10 17:15:29 UTC (rev
2582)
@@ -48,6 +48,8 @@
static final String NS_JBOSSWS_URI = "http://www.jboss.org/jbossws";
/** XML Namespace */
static final String NS_XML = "http://www.w3.org/XML/1998/namespace";
+ /** XML namespace declaration namespace */
+ static final String NS_XMLNS = "http://www.w3.org/2000/xmlns/";
/** XMLSchema namespace
http://www.w3.org/2001/XMLSchema */
static final String NS_SCHEMA_XSD = "http://www.w3.org/2001/XMLSchema";
/** XMLSchema instance namespace
http://www.w3.org/2001/XMLSchema-instance */
@@ -61,7 +63,7 @@
/** HTTP binding namespace
http://schemas.xmlsoap.org/wsdl/http/ */
static final String NS_HTTP = "http://schemas.xmlsoap.org/wsdl/http/";
/** SOAP-1.2 envelope namespace
http://www.w3.org/2003/05/soap-envelope */
- static final String NS_SOAP12_ENV =
"http://www.w3.org/2003/05/soap-envelope";
+ static final String NS_SOAP12_ENV = SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE;
/** The namespace for the SwA mime type */
static final String NS_SWA_MIME = "http://schemas.xmlsoap.org/wsdl/mime/";
/** Default namespace for WSDL-1.1
http://schemas.xmlsoap.org/wsdl/ */
@@ -148,8 +150,21 @@
static final Name SOAP11_HEADER = new NameImpl("Header", PREFIX_ENV,
NS_SOAP11_ENV);
static final Name SOAP11_BODY = new NameImpl("Body", PREFIX_ENV,
NS_SOAP11_ENV);
static final Name SOAP11_FAULT = new NameImpl("Fault", PREFIX_ENV,
NS_SOAP11_ENV);
- static final Name SOAP12_FAULT = new NameImpl("Fault", PREFIX_ENV,
NS_SOAP12_ENV);
+ static final QName SOAP11_FAULTCODE = new QName("faultcode");
+ static final QName SOAP11_FAULTSTRING = new QName("faultstring");
+ static final QName SOAP11_FAULTACTOR = new QName("faultactor");
+ static final QName SOAP11_DETAIL = new QName("detail");
+ /**SOAP-1.2 elements */
+ static final QName SOAP12_CODE = new QName(NS_SOAP12_ENV, "Code",
PREFIX_ENV);
+ static final QName SOAP12_VALUE = new QName(NS_SOAP12_ENV, "Value",
PREFIX_ENV);
+ static final QName SOAP12_SUBCODE = new QName(NS_SOAP12_ENV, "Subcode",
PREFIX_ENV);
+ static final QName SOAP12_REASON = new QName(NS_SOAP12_ENV, "Reason",
PREFIX_ENV);
+ static final QName SOAP12_TEXT = new QName(NS_SOAP12_ENV, "Text",
PREFIX_ENV);
+ static final QName SOAP12_ROLE = new QName(NS_SOAP12_ENV, "Role",
PREFIX_ENV);
+ static final QName SOAP12_NODE = new QName(NS_SOAP12_ENV, "Node",
PREFIX_ENV);
+ static final QName SOAP12_DETAIL = new QName(NS_SOAP12_ENV, "Detail",
PREFIX_ENV);
+
/** The default RPC return parameter name */
static final String DEFAULT_RPC_RETURN_NAME = "result"; // FIXME: According
to JSR-181 this should be 'return'
Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/SOAPFaultHelperJAXWS.java
===================================================================
---
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/SOAPFaultHelperJAXWS.java 2007-03-10
17:09:00 UTC (rev 2581)
+++
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/SOAPFaultHelperJAXWS.java 2007-03-10
17:15:29 UTC (rev 2582)
@@ -68,11 +68,12 @@
public static SOAPFaultException getSOAPFaultException(SOAPFault soapFault)
{
SOAPFaultException faultEx = new SOAPFaultException(soapFault);
- Detail detail = soapFault.getDetail();
+ Detail detail = soapFault.getDetail();
CommonMessageContext msgContext = MessageContextAssociation.peekMessageContext();
if (detail != null && msgContext != null)
{
+ log.debug("Processing detail");
SerializationContext serContext = msgContext.getSerializationContext();
TypeMapping typeMapping = serContext.getTypeMapping();
@@ -80,13 +81,14 @@
while (it.hasNext())
{
DetailEntry deElement = (DetailEntry)it.next();
- QName xmlName = new QName(deElement.getNamespaceURI(),
deElement.getLocalName());
+ QName xmlName = deElement.getElementQName();
+ log.debug("Processing detail entry: " + xmlName);
OperationMetaData opMetaData = msgContext.getOperationMetaData();
FaultMetaData faultMetaData = opMetaData.getFault(xmlName);
if (faultMetaData != null)
{
- if(log.isDebugEnabled()) log.debug("Deserialize fault: " +
faultMetaData);
+ log.debug("Deserialize fault: " + faultMetaData);
QName xmlType = faultMetaData.getXmlType();
Class<?> faultBeanClass = faultMetaData.getFaultBean();
@@ -101,8 +103,7 @@
if (prefix != null && prefix.length() > 0)
{
String nsURI = deElement.getNamespaceURI();
- String attrValue = deElement.getAttribute("xmlns:" +
prefix);
- if (nsURI.length() > 0 && attrValue.length() == 0)
+ if (nsURI.length() > 0 &&
deElement.getAttributeNS(Constants.NS_XMLNS, prefix).length() == 0)
{
try
{
@@ -134,9 +135,7 @@
}
}
else
- {
- if(log.isDebugEnabled()) log.debug("Cannot find fault meta data for:
" + xmlName);
- }
+ log.debug("Cannot find fault meta data for: " + xmlName);
}
}
@@ -274,9 +273,7 @@
detail.addChildElement(detailEntry);
}
else
- {
- if(log.isDebugEnabled()) log.debug("Cannot obtain fault meta data for:
" + exClass);
- }
+ log.debug("Cannot obtain fault meta data for: " + exClass);
return soapMessage;
}
Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/soap/DetailImpl.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/soap/DetailImpl.java 2007-03-10 17:09:00
UTC (rev 2581)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/soap/DetailImpl.java 2007-03-10 17:15:29
UTC (rev 2582)
@@ -21,14 +21,24 @@
*/
package org.jboss.ws.core.soap;
+import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import javax.xml.namespace.QName;
import javax.xml.soap.Detail;
import javax.xml.soap.DetailEntry;
import javax.xml.soap.Name;
+import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
+import org.jboss.logging.Logger;
+import org.jboss.ws.WSException;
+import org.jboss.ws.core.utils.DOMUtils;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
/**
* A container for DetailEntry objects. DetailEntry objects give detailed error
information that is application-specific
* and related to the SOAPBody object that contains it.
@@ -42,11 +52,47 @@
*/
public class DetailImpl extends SOAPFaultElementImpl implements Detail
{
+ // provide logging
+ private static Logger log = Logger.getLogger(DetailImpl.class);
+
+ /** Creates a SOAP 1.1 detail element. */
public DetailImpl()
{
super("detail");
}
+ /** Creates a SOAP 1.2 prefix:Detail element. */
+ public DetailImpl(String prefix, String namespace)
+ {
+ super("Detail", prefix, namespace);
+ }
+
+ /** Converts the given element to a Detail. */
+ DetailImpl(SOAPElementImpl element)
+ {
+ super(element.getElementName());
+
+ // altough detail schema does not define attributes, copy them for completeness
+ DOMUtils.copyAttributes(this, element);
+
+ try
+ {
+ NodeList nodeList = element.getChildNodes();
+ for (int i = 0; i < nodeList.getLength(); i++)
+ {
+ Node node = nodeList.item(i);
+ if (node instanceof SOAPElement)
+ addChildElement((SOAPElement)node);
+ else
+ appendChild(node);
+ }
+ }
+ catch (SOAPException e)
+ {
+ throw new WSException("Unable to create fault detail", e);
+ }
+ }
+
public DetailEntry addDetailEntry(Name name) throws SOAPException
{
DetailEntryImpl detailEntry = new DetailEntryImpl(name);
@@ -63,6 +109,42 @@
public Iterator getDetailEntries()
{
- return getChildElements();
+ List<DetailEntry> list = new ArrayList<DetailEntry>();
+
+ NodeList nodeList = getChildNodes();
+ for (int i = 0; i < nodeList.getLength(); i++)
+ {
+ org.w3c.dom.Node node = nodeList.item(i);
+ if (node instanceof DetailEntry)
+ list.add((DetailEntry)node);
+ }
+
+ return list.iterator();
}
+
+ @Override
+ public Node appendChild(Node newChild) throws DOMException
+ {
+ if (newChild instanceof SOAPElementImpl && !(newChild instanceof
DetailEntry))
+ newChild = convertToDetailEntry((SOAPElementImpl) newChild);
+
+ return super.appendChild(newChild);
+ }
+
+ @Override
+ public SOAPElement addChildElement(SOAPElement child) throws SOAPException
+ {
+ if (!(child instanceof DetailEntry))
+ child = convertToDetailEntry((SOAPElementImpl)child);
+
+ return super.addChildElement(child);
+ }
+
+ private static DetailEntry convertToDetailEntry(SOAPElementImpl element)
+ {
+ element.detachNode();
+ DetailEntryImpl detailEntry = new DetailEntryImpl(element);
+ log.trace("convertToDetailEntry : " + detailEntry);
+ return detailEntry;
+ }
}
Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java 2007-03-10
17:09:00 UTC (rev 2581)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java 2007-03-10
17:15:29 UTC (rev 2582)
@@ -23,21 +23,6 @@
//$Id$
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Iterator;
-
-import javax.xml.namespace.QName;
-import javax.xml.soap.Detail;
-import javax.xml.soap.Name;
-import javax.xml.soap.SOAPBody;
-import javax.xml.soap.SOAPElement;
-import javax.xml.soap.SOAPEnvelope;
-import javax.xml.soap.SOAPException;
-import javax.xml.soap.SOAPHeader;
-import javax.xml.soap.SOAPMessage;
-import javax.xml.transform.dom.DOMSource;
-
import org.jboss.logging.Logger;
import org.jboss.ws.WSException;
import org.jboss.ws.core.jaxrpc.Style;
@@ -45,6 +30,13 @@
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
+import javax.xml.namespace.QName;
+import javax.xml.soap.*;
+import javax.xml.transform.dom.DOMSource;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Iterator;
+
/**
* A SOAPEnvelope builder for JAXRPC based on DOM
*
@@ -144,40 +136,9 @@
DOMUtils.copyAttributes(soapFault, domBodyElement);
- Element domFaultCode = DOMUtils.getFirstChildElement(domBodyElement, new
QName("faultcode"));
- if (domFaultCode == null)
- throw new SOAPException("SOAPFault does not contain a
<faultcode> element");
-
- Element domFaultString = DOMUtils.getFirstChildElement(domBodyElement, new
QName("faultstring"));
- if (domFaultString == null)
- throw new SOAPException("SOAPFault does not contain a
<faultstring> element");
-
- String faultCode = DOMUtils.getTextContent(domFaultCode);
- soapFault.setFaultCode(faultCode);
-
- String faultString = DOMUtils.getTextContent(domFaultString);
- soapFault.setFaultString(faultString);
-
- Element domFaultActor = DOMUtils.getFirstChildElement(domBodyElement, new
QName("faultactor"));
- if (domFaultActor != null)
- {
- String faultActor = DOMUtils.getTextContent(domFaultActor);
- soapFault.setFaultActor(faultActor);
- }
-
- // Add the fault detail
- Element domFaultDetail = DOMUtils.getFirstChildElement(domBodyElement,
"detail");
- if (domFaultDetail != null)
- {
- Detail detail = soapFault.addDetail();
- Iterator it = DOMUtils.getChildElements(domFaultDetail);
- while (it.hasNext())
- {
- Element domElement = (Element)it.next();
- SOAPElement detailEntry = new
DetailEntryImpl(soapFactory.createElement(domElement));
- detailEntry = detail.addChildElement(detailEntry);
- }
- }
+ // copy everything and let soapFault discover child elements itself
+ XMLFragment xmlFragment = new XMLFragment(new DOMSource(domBodyElement));
+ soapFault.setXMLFragment(xmlFragment);
}
// Process and RPC or DOCUMENT style message
Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPBodyImpl.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPBodyImpl.java 2007-03-10
17:09:00 UTC (rev 2581)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPBodyImpl.java 2007-03-10
17:15:29 UTC (rev 2582)
@@ -48,7 +48,6 @@
import javax.xml.transform.stream.StreamSource;
import org.jboss.logging.Logger;
-import org.jboss.ws.Constants;
import org.jboss.ws.WSException;
import org.jboss.ws.core.CommonMessageContext;
import org.jboss.ws.core.utils.DOMUtils;
@@ -154,7 +153,10 @@
if (hasFault())
throw new SOAPException("A SOAPBody may contain at most one SOAPFault child
element");
- return addFault(new NameImpl(Constants.SOAP11_FAULT_CODE_SERVER), "Generic
server fault");
+ SOAPFaultImpl soapFault = new SOAPFaultImpl(getPrefix(), getNamespaceURI());
+ soapFault = (SOAPFaultImpl)addChildElement(soapFault);
+ soapFault.setFaultCode(soapFault.getDefaultFaultCode());
+ return soapFault;
}
public SOAPFault addFault(Name faultCode, String faultString) throws SOAPException
@@ -217,7 +219,7 @@
{
log.trace("getFault");
expandToDOM();
- Iterator it = getFaultIterator();
+ Iterator it = faultIterator();
return it.hasNext() ? (SOAPFault)it.next() : null;
}
@@ -225,14 +227,12 @@
{
log.trace("hasFault");
expandToDOM();
- return getFaultIterator().hasNext();
+ return faultIterator().hasNext();
}
- private Iterator getFaultIterator()
+ private Iterator faultIterator()
{
- Name faultName = Constants.NS_SOAP11_ENV.equals(getNamespaceURI()) ?
- Constants.SOAP11_FAULT : Constants.SOAP12_FAULT;
- return getChildElements(faultName);
+ return getChildElements(new QName(getNamespaceURI(), "Fault"));
}
public Node appendChild(Node newChild) throws DOMException
Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPElementImpl.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPElementImpl.java 2007-03-10
17:09:00 UTC (rev 2581)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPElementImpl.java 2007-03-10
17:15:29 UTC (rev 2582)
@@ -487,6 +487,11 @@
*/
public Iterator getChildElements(Name name)
{
+ return getChildElements(((NameImpl)name).toQName());
+ }
+
+ public Iterator getChildElements(QName qname)
+ {
List<SOAPElement> list = new ArrayList<SOAPElement>();
Iterator it = getChildElements();
while (it.hasNext())
@@ -495,18 +500,13 @@
if (elementOrTextNode instanceof SOAPElement)
{
SOAPElement el = (SOAPElement)elementOrTextNode;
- if (el.getElementName().equals(name))
+ if (el.getElementQName().equals(qname))
list.add(el);
}
}
return list.iterator();
}
- public Iterator getChildElements(QName qname)
- {
- return getChildElements(new NameImpl(qname));
- }
-
/**
* Returns the name of this SOAPElement object.
*
Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPFaultElementImpl.java
===================================================================
---
trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPFaultElementImpl.java 2007-03-10
17:09:00 UTC (rev 2581)
+++
trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPFaultElementImpl.java 2007-03-10
17:15:29 UTC (rev 2582)
@@ -40,4 +40,9 @@
{
super(name);
}
+
+ public SOAPFaultElementImpl(SOAPElementImpl element)
+ {
+ super(element);
+ }
}
\ No newline at end of file
Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPFaultImpl.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPFaultImpl.java 2007-03-10
17:09:00 UTC (rev 2581)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPFaultImpl.java 2007-03-10
17:15:29 UTC (rev 2582)
@@ -22,6 +22,8 @@
package org.jboss.ws.core.soap;
import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
import java.util.Locale;
@@ -32,15 +34,13 @@
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFault;
+import javax.xml.soap.SOAPFaultElement;
import org.jboss.logging.Logger;
-import org.jboss.util.NotImplementedException;
import org.jboss.ws.Constants;
-import org.jboss.ws.WSException;
-import org.jboss.ws.core.utils.DOMUtils;
import org.jboss.ws.core.utils.DOMWriter;
import org.jboss.xb.QNameBuilder;
-import org.w3c.dom.Element;
+import org.w3c.dom.Attr;
/**
* An element in the SOAPBody object that contains error and/or status information.
@@ -64,275 +64,725 @@
private static Logger log = Logger.getLogger(SOAPFaultImpl.class);
private SOAPElement faultcode;
+ // also represents Reason
private SOAPElement faultstring;
+ // also represents Role
private SOAPElement faultactor;
- private Locale faultStringLocale;
+ private SOAPElement faultnode;
+ private Detail detail;
- private String faultRole;
-
public SOAPFaultImpl() throws SOAPException
{
- this(SOAPConstants.SOAP_ENV_PREFIX, SOAPConstants.URI_NS_SOAP_ENVELOPE);
+ this(Constants.PREFIX_ENV, Constants.NS_SOAP11_ENV);
}
-
+
public SOAPFaultImpl(String prefix, String namespace) throws SOAPException
{
super(new NameImpl("Fault", prefix, namespace));
- SOAPFactoryImpl factory = new SOAPFactoryImpl();
- addChildElement(faultcode = factory.createElement("faultcode"));
- addChildElement(faultstring = factory.createElement("faultstring"));
}
- /** Creates an optional Detail object and sets it as the Detail object for this
SOAPFault object.
+ /** Gets the fault code for this SOAPFault object.
*/
- public Detail addDetail() throws SOAPException
+ public String getFaultCode()
{
- Detail detail = getDetail();
- if (detail != null)
- throw new SOAPException("SOAPFault already contains a detail node");
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()))
+ {
+ if (faultcode == null)
+ findFaultCodeElement();
- SOAPFactoryImpl factory = new SOAPFactoryImpl();
- detail = (Detail)addChildElement(factory.createDetail());
- return detail;
+ return faultcode.getValue();
+ }
+ else
+ {
+ if (faultcode == null)
+ findCodeElement();
+
+ return getChildValueElement(faultcode).getValue();
+ }
}
- /** Returns the optional detail element for this SOAPFault object.
+ /**
+ * Gets the mandatory SOAP 1.1 fault code for this SOAPFault object as a SAAJ Name
object.
*/
- public Detail getDetail()
+ public Name getFaultCodeAsName()
{
- Detail detail = null;
- Iterator it = getChildElements(new NameImpl("detail"));
- while (it.hasNext())
+ return new NameImpl(getFaultCodeAsQName());
+ }
+
+ public QName getFaultCodeAsQName()
+ {
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()))
{
- Object obj = it.next();
- if (obj instanceof Detail)
+ if (faultcode == null)
+ findFaultCodeElement();
+
+ return QNameBuilder.buildQName(faultcode, faultcode.getValue());
+ }
+ else
+ {
+ if (faultcode == null)
+ findCodeElement();
+
+ SOAPElement valueElement = getChildValueElement(faultcode);
+ return QNameBuilder.buildQName(valueElement, valueElement.getValue());
+ }
+ }
+
+ private void findFaultCodeElement()
+ {
+ faultcode = getChildElement(this, Constants.SOAP11_FAULTCODE);
+ log.trace("findFaultCodeElement : " + faultcode);
+ }
+
+ private void findCodeElement()
+ {
+ faultcode = getChildElement(this, Constants.SOAP12_CODE);
+ log.trace("findCodeElement : " + faultcode);
+ }
+
+ private static SOAPElement getChildValueElement(SOAPElement codeElement)
+ {
+ return getChildElement(codeElement, Constants.SOAP12_VALUE);
+ }
+
+ /** Sets this SOAPFault object with the give fault code.
+ */
+ public void setFaultCode(String faultCode) throws SOAPException
+ {
+ // Must be of the form "prefix:localName" where the prefix has been
defined in a namespace declaration.
+ QName qname = QNameBuilder.buildQName(this, faultCode);
+ setFaultCode(qname);
+ }
+
+ /** Sets this SOAPFault object with the given fault code.
+ */
+ public void setFaultCode(Name faultCode) throws SOAPException
+ {
+ setFaultCode(((NameImpl)faultCode).toQName());
+ }
+
+ public void setFaultCode(QName faultCode) throws SOAPException
+ {
+ String nsURI = faultCode.getNamespaceURI();
+ if (nsURI.length() == 0)
+ throw new SOAPException("code must be namespace qualified: " +
faultCode);
+
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()))
+ {
+ if (faultcode == null)
{
- detail = (Detail)obj;
+ findFaultCodeElement();
+ if (faultcode == null)
+ faultcode = addUnqualifiedFaultElement("faultcode");
}
- else if (obj instanceof SOAPElementImpl)
+ setCode(faultcode, faultCode);
+ }
+ else
+ {
+ if (!(SOAPConstants.SOAP_DATAENCODINGUNKNOWN_FAULT.equals(faultCode) ||
+ SOAPConstants.SOAP_MUSTUNDERSTAND_FAULT.equals(faultCode) ||
+ SOAPConstants.SOAP_RECEIVER_FAULT.equals(faultCode) ||
+ SOAPConstants.SOAP_SENDER_FAULT.equals(faultCode) ||
+ SOAPConstants.SOAP_VERSIONMISMATCH_FAULT.equals(faultCode)))
+ throw new SOAPException(faultCode + " is not a standard SOAP 1.2 Code
value");
+
+ if (faultcode == null)
{
- try
+ findCodeElement();
+ if (faultcode == null)
{
- SOAPElementImpl soapEl = (SOAPElementImpl)obj;
- SOAPFactoryImpl factory = new SOAPFactoryImpl();
- detail = (Detail)addChildElement(factory.createDetail());
-
- Iterator childIt = DOMUtils.getChildElements(soapEl);
- while (childIt.hasNext())
- {
- Element domElement = (Element)childIt.next();
- SOAPElement detailEntry = new
DetailEntryImpl(factory.createElement(domElement));
- detail.addChildElement(detailEntry);
- }
+ faultcode = addQualifiedFaultElement("Code");
+ addChildValueElement(faultcode);
}
- catch (SOAPException e)
- {
- throw new WSException("Unable to create fault detail: " +
e.getMessage());
- }
+ }
+ setCode(getChildValueElement(faultcode), faultCode);
+ }
+ }
+ private static void setCode(SOAPElement codeElement, QName code) throws SOAPException
+ {
+ String nsURI = code.getNamespaceURI();
+ String prefix = code.getPrefix();
+ if (prefix.length() == 0)
+ {
+ // no given prefix, find prefix currently associated to given URI
+ prefix = getNamespacePrefix(codeElement, nsURI);
+ if (prefix == null)
+ {
+ // no prefix currently associated to given URI, declare namespace locally
+ prefix = "codeNS";
+ codeElement.addNamespaceDeclaration(prefix, nsURI);
}
}
+ // verify given prefix is associated to given URI
+ else if (!nsURI.equals(codeElement.getNamespaceURI(prefix)))
+ {
+ // prefix is associated with other/no URI, declare namespace locally
+ codeElement.addNamespaceDeclaration(prefix, nsURI);
+ }
- return detail;
+ codeElement.setValue(prefix + ":" + code.getLocalPart());
}
- /** Gets the fault actor for this SOAPFault object.
+ /**
+ * Returns the prefix of the namespace that has the given URI.
+ * @param nsURI the URI of the namespace to search for
+ * @return the prefix of the namespace or <code>null</code> if not found
*/
- public String getFaultActor()
+ private static String getNamespacePrefix(SOAPElement element, String nsURI)
{
- return (faultactor != null ? faultactor.getValue() : null);
+ Iterator it = element.getVisibleNamespacePrefixes();
+ while (it.hasNext())
+ {
+ String prefix = (String)it.next();
+ if (nsURI.equals(element.getNamespaceURI(prefix)))
+ return prefix;
+ }
+ return null;
}
- /** Gets the fault code for this SOAPFault object.
- */
- public String getFaultCode()
+ private static SOAPElement addChildValueElement(SOAPElement codeElement) throws
SOAPException
{
- String value = faultcode.getValue();
- return value;
+ return codeElement.addChildElement("Value", codeElement.getPrefix(),
codeElement.getNamespaceURI());
}
- /**
- * Gets the mandatory SOAP 1.1 fault code for this SOAPFault object as a SAAJ Name
object.
- */
- public Name getFaultCodeAsName()
+ public Iterator getFaultSubcodes()
{
- QName qname = QNameBuilder.buildQName(this, faultcode.getValue());
- return new NameImpl(qname);
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()))
+ throw new UnsupportedOperationException("SOAP 1.1 Fault does not support
the concept of Subcode");
+
+ ArrayList<QName> subcodes = new ArrayList<QName>();
+
+ SOAPElement baseCodeElement = faultcode;
+ SOAPElement subcodeElement;
+ for (subcodeElement = getChildSubcodeElement(baseCodeElement); subcodeElement !=
null; subcodeElement = getChildSubcodeElement(baseCodeElement))
+ {
+ SOAPElement valueElement = getChildValueElement(subcodeElement);
+ QName subcode = QNameBuilder.buildQName(valueElement, valueElement.getValue());
+ subcodes.add(subcode);
+
+ baseCodeElement = subcodeElement;
+ }
+
+ // this iterator should not support the remove method
+ return Collections.unmodifiableList(subcodes).iterator();
}
+ private static SOAPElement getChildSubcodeElement(SOAPElement element)
+ {
+ return getChildElement(element, Constants.SOAP12_SUBCODE);
+ }
+
+ public void appendFaultSubcode(QName subcode) throws SOAPException
+ {
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()))
+ throw new UnsupportedOperationException("SOAP 1.1 Fault does not support
the concept of Subcode");
+
+ String nsURI = subcode.getNamespaceURI();
+ if (nsURI.length() == 0)
+ throw new SOAPException("subcode must be namespace qualified: " +
subcode);
+
+ if (faultcode == null)
+ findCodeElement();
+
+ // find innermost subcode element
+ SOAPElement baseCodeElement = faultcode;
+ for (SOAPElement subcodeElement = getChildSubcodeElement(baseCodeElement);
subcodeElement != null; subcodeElement = getChildSubcodeElement(baseCodeElement))
+ baseCodeElement = subcodeElement;
+
+ SOAPElement subcodeElement = baseCodeElement.addChildElement("Subcode",
baseCodeElement.getPrefix(), baseCodeElement.getNamespaceURI());
+ SOAPElement valueElement = addChildValueElement(subcodeElement);
+
+ setCode(valueElement, subcode);
+ }
+
+ public void removeAllFaultSubcodes()
+ {
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()))
+ throw new UnsupportedOperationException("SOAP 1.1 Fault does not support
the concept of Subcode");
+
+ if (faultcode == null)
+ findFaultCodeElement();
+
+ SOAPElement subcodeElement = getChildSubcodeElement(faultcode);
+ if (subcodeElement != null)
+ subcodeElement.detachNode();
+ }
+
/** Gets the fault string for this SOAPFault object.
*/
public String getFaultString()
{
- String value = faultstring.getValue();
- return value;
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()))
+ {
+ if (faultstring == null)
+ {
+ findFaultStringElement();
+ if (faultstring == null)
+ return null;
+ }
+ return faultstring.getValue();
+ }
+ else
+ {
+ try
+ {
+ return (String)getFaultReasonTexts().next();
+ }
+ catch (SOAPException e)
+ {
+ return null;
+ }
+ }
}
/** Gets the locale of the fault string for this SOAPFault object.
*/
public Locale getFaultStringLocale()
{
- return faultStringLocale;
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()))
+ {
+ if (faultstring == null)
+ {
+ findFaultStringElement();
+ if (faultstring == null)
+ return null;
+ }
+ return getLocale(faultstring);
+ }
+ else
+ {
+ try
+ {
+ return (Locale)getFaultReasonLocales().next();
+ }
+ catch (SOAPException e)
+ {
+ return null;
+ }
+ }
}
- /** Sets this SOAPFault object with the given fault actor.
+ private void findFaultStringElement()
+ {
+ faultstring = getChildElement(this, Constants.SOAP11_FAULTSTRING);
+ log.trace("findFaultStringElement : " + faultstring);
+ }
+
+ private static Locale getLocale(SOAPElement element)
+ {
+ Attr xmlLang = element.getAttributeNodeNS(Constants.NS_XML, "lang");
+ return xmlLang != null ? toLocale(xmlLang.getValue()) : null;
+ }
+
+ /** Converts a language tag as defined in <a
+ *
href="http://www.ietf.org/rfc/rfc3066.txt">IETF RFC 3066</a> to
a
+ * {@link Locale}.
*/
- public void setFaultActor(String faultActor) throws SOAPException
+ private static Locale toLocale(String languageTag)
{
- if (faultactor == null)
+ String[] subtags = languageTag.split("-");
+ // ignore subtags beyond the second
+ return subtags.length == 1 ? new Locale(subtags[0]) : new Locale(subtags[0],
subtags[1]);
+ }
+
+ /** Sets the fault string for this SOAPFault object to the given string.
+ */
+ public void setFaultString(String faultString) throws SOAPException
+ {
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()))
{
- SOAPFactoryImpl factory = new SOAPFactoryImpl();
- addChildElement(faultactor = factory.createElement("faultactor"));
+ setFaultStringInternal(faultString);
+ faultstring.removeAttributeNS(Constants.NS_XML, "lang");
}
-
- faultactor.setValue(faultActor);
+ else addFaultReasonText(faultString, Locale.getDefault());
}
- /** Sets this SOAPFault object with the give fault code.
+ /** Sets the fault string for this SOAPFault object to the given string and localized
to the given locale.
*/
- public void setFaultCode(String faultCode) throws SOAPException
+ public void setFaultString(String faultString, Locale locale) throws SOAPException
{
- // Must be of the form "prefix:localName" where the prefix has been
defined in a namespace declaration.
- if (faultCode == null || faultCode.indexOf(":") < 1)
- throw new IllegalArgumentException("Invalid faultCode: " +
faultCode);
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()))
+ {
+ setFaultStringInternal(faultString);
+ setLocale(faultstring, locale);
+ }
+ else addFaultReasonText(faultString, locale);
+ }
- QName qname = QNameBuilder.buildQName(this, faultCode);
- setFaultCode(new NameImpl(qname));
+ private void setFaultStringInternal(String faultString) throws SOAPException
+ {
+ if (faultstring == null)
+ {
+ findFaultStringElement();
+ if (faultstring == null)
+ faultstring = addUnqualifiedFaultElement("faultstring");
+ }
+ faultstring.setValue(faultString);
}
- /** Sets this SOAPFault object with the given fault code.
+ private static void setLocale(SOAPElement element, Locale locale)
+ {
+ element.setAttributeNS(Constants.NS_XML, "xml:lang",
toLanguageTag(locale));
+ }
+
+ /** Converts a {@link Locale} to a language tag as defined in <a
+ *
href="http://www.ietf.org/rfc/rfc3066.txt">IETF RFC 3066</a>.
*/
- public void setFaultCode(Name faultName) throws SOAPException
+ private static String toLanguageTag(Locale locale)
{
- String nsURI = faultName.getURI();
- String prefix = faultName.getPrefix();
- String localName = faultName.getLocalName();
+ String languageTag = locale.getLanguage();
- // For lazy folkes like the CTS that don't bother to give
- // a namesapce URI, assume they use a standard code
- if ("".equals(nsURI))
+ String country = locale.getCountry();
+ if (country.length() != 0)
+ languageTag += "-" + country;
+
+ return languageTag;
+ }
+
+ public Iterator getFaultReasonTexts() throws SOAPException
+ {
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()))
+ throw new UnsupportedOperationException("SOAP 1.1 Fault does not support
the concept of Reason");
+
+ if (faultstring == null)
{
- log.warn("Empty namespace URI with fault code '" + faultName +
"', assuming: " + Constants.NS_SOAP11_ENV);
- nsURI = Constants.NS_SOAP11_ENV;
- prefix = getPrefix();
+ findReasonElement();
+ if (faultstring == null)
+ return Collections.EMPTY_LIST.iterator();
}
- if (nsURI.length() > 0 && prefix.length() == 0)
- prefix = "codeNS";
-
- String prevNS = getNamespaceURI(prefix);
- if (prevNS == null)
- addNamespaceDeclaration(prefix, nsURI);
+ ArrayList<String> texts = new ArrayList<String>();
+ Iterator it = faultstring.getChildElements(Constants.SOAP12_TEXT);
+ while (it.hasNext())
+ {
+ SOAPElement textElement = (SOAPElement)it.next();
+ texts.add(textElement.getValue());
+ }
- String faultCode = prefix + ":" + localName;
- faultcode.setValue(faultCode);
+ if (texts.isEmpty())
+ throw new SOAPException("no Text elements found inside Reason");
+
+ return texts.iterator();
}
- public void setFaultCode(QName faultCode) throws SOAPException
+ public Iterator getFaultReasonLocales() throws SOAPException
{
- setFaultCode(new NameImpl(faultCode));
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()))
+ throw new UnsupportedOperationException("SOAP 1.1 Fault does not support
the concept of Reason");
+
+ if (faultstring == null)
+ {
+ findReasonElement();
+ if (faultstring == null)
+ return Collections.EMPTY_LIST.iterator();
+ }
+
+ ArrayList<Locale> locales = new ArrayList<Locale>();
+ Iterator it = faultstring.getChildElements(Constants.SOAP12_TEXT);
+ while (it.hasNext())
+ {
+ SOAPElement textElement = (SOAPElement)it.next();
+ Locale locale = getLocale(textElement);
+ if (locale == null)
+ throw new SOAPException("lang attribute not present on Text
element");
+ locales.add(locale);
+ }
+
+ if (locales.isEmpty())
+ throw new SOAPException("no Text elements found inside Reason");
+
+ return locales.iterator();
}
-
- /** Sets the fault string for this SOAPFault object to the given string.
- */
- public void setFaultString(String faultString) throws SOAPException
+
+ public String getFaultReasonText(Locale locale) throws SOAPException
{
- faultstring.setValue(faultString);
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()))
+ throw new UnsupportedOperationException("SOAP 1.1 Fault does not support
the concept of Reason");
+
+ if (locale == null)
+ return null;
+
+ if (faultstring == null)
+ {
+ findReasonElement();
+ if (faultstring == null)
+ return null;
+ }
+
+ SOAPElement textElement = getTextElement(locale);
+ return textElement != null ? textElement.getValue() : null;
}
- /** Sets the fault string for this SOAPFault object to the given string and localized
to the given locale.
- */
- public void setFaultString(String faultString, Locale locale) throws SOAPException
+ private void findReasonElement()
{
- setFaultString(faultString);
- this.faultStringLocale = locale;
+ faultstring = getChildElement(this, Constants.SOAP12_REASON);
+ log.trace("findReasonElement: " + faultstring);
}
- public void writeElement(Writer writer)
+ private SOAPElement getTextElement(Locale locale)
{
- new DOMWriter(writer).print(this);
+ log.trace("getTextElement(" + locale + ")");
+ SOAPElement textElement = null;
+
+ Iterator it = faultstring.getChildElements(Constants.SOAP12_TEXT);
+ while (it.hasNext())
+ {
+ SOAPElement element = (SOAPElement)it.next();
+ if (locale.equals(getLocale(element)))
+ {
+ textElement = element;
+ break;
+ }
+ }
+
+ log.trace("getTextElement : " + textElement);
+ return textElement;
}
public void addFaultReasonText(String text, Locale locale) throws SOAPException
{
- //TODO: SAAJ 1.3
- throw new NotImplementedException();
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()))
+ throw new UnsupportedOperationException("SOAP 1.1 Fault does not support
the concept of Reason");
+
+ if (locale == null)
+ throw new SOAPException("locale passed is null");
+
+ if (faultstring == null)
+ {
+ findReasonElement();
+ if (faultstring == null)
+ faultstring = addQualifiedFaultElement("Reason");
+ }
+
+ SOAPElement textElement = getTextElement(locale);
+ if (textElement == null)
+ {
+ textElement = faultstring.addChildElement("Text", getPrefix(),
getNamespaceURI());
+ setLocale(textElement, locale);
+ }
+ textElement.setValue(text);
}
- public void appendFaultSubcode(QName subcode) throws SOAPException
+ /** Gets the fault actor for this SOAPFault object.
+ */
+ public String getFaultActor()
{
- //TODO: SAAJ 1.3
- throw new NotImplementedException();
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()))
+ {
+ if (faultactor == null)
+ {
+ findFaultActorElement();
+ if (faultactor == null)
+ return null;
+ }
+ return faultactor.getValue();
+ }
+ else return getFaultRole();
}
- public QName getFaultCodeAsQName()
+ private void findFaultActorElement()
{
- //TODO: SAAJ 1.3
- throw new NotImplementedException();
+ faultactor = getChildElement(this, Constants.SOAP11_FAULTACTOR);
+ log.trace("findFaultActorElement : " + faultactor);
}
- public String getFaultNode()
+ /** Sets this SOAPFault object with the given fault actor.
+ */
+ public void setFaultActor(String faultActor) throws SOAPException
{
- //TODO: SAAJ 1.3
- throw new NotImplementedException();
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()))
+ {
+ if (faultactor == null)
+ {
+ findFaultActorElement();
+ if (faultactor == null)
+ faultactor = addUnqualifiedFaultElement("faultactor");
+ }
+ faultactor.setValue(faultActor);
+ }
+ else setFaultRole(faultActor);
}
- public Iterator getFaultReasonLocales() throws SOAPException
+ public String getFaultRole()
{
- //TODO: SAAJ 1.3
- throw new NotImplementedException();
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()))
+ throw new UnsupportedOperationException("SOAP 1.1 Fault does not support
the concept of Role");
+
+ if (faultactor == null)
+ {
+ findRoleElement();
+ if (faultactor == null)
+ return null;
+ }
+ return faultactor.getValue();
}
- public String getFaultReasonText(Locale locale) throws SOAPException
+ private void findRoleElement()
{
- //TODO: SAAJ 1.3
- throw new NotImplementedException();
+ faultactor = getChildElement(this, Constants.SOAP12_ROLE);
+ log.trace("findRoleElement : " + faultactor);
}
- public Iterator getFaultReasonTexts() throws SOAPException
+ public void setFaultRole(String uri) throws SOAPException
{
- //TODO: SAAJ 1.3
- throw new NotImplementedException();
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()))
+ throw new UnsupportedOperationException("SOAP 1.1 Fault does not support
the concept of Role");
+
+ if (faultactor == null)
+ {
+ findRoleElement();
+ if (faultactor == null)
+ faultactor = addQualifiedFaultElement("Role");
+ }
+ faultactor.setValue(uri);
}
- public String getFaultRole()
+ public String getFaultNode()
{
- return this.faultRole;
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()))
+ throw new UnsupportedOperationException("SOAP 1.1 Fault does not support
the concept of Node");
+
+ if (faultnode == null)
+ {
+ findNodeElement();
+ if (faultnode == null)
+ return null;
+ }
+ return faultnode.getValue();
}
- public Iterator getFaultSubcodes()
+ private void findNodeElement()
{
- //TODO: SAAJ 1.3
- throw new NotImplementedException();
+ faultnode = getChildElement(this, Constants.SOAP12_NODE);
+ log.trace("findNodeElement : " + faultnode);
}
+ public void setFaultNode(String uri) throws SOAPException
+ {
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()))
+ throw new UnsupportedOperationException("SOAP 1.1 Fault does not support
the concept of Node");
+
+ if (faultnode == null)
+ {
+ findNodeElement();
+ if (faultnode == null)
+ faultnode = addQualifiedFaultElement("Node");
+ }
+ faultnode.setValue(uri);
+ }
+
public boolean hasDetail()
{
- //TODO: SAAJ 1.3
- throw new NotImplementedException();
+ return getDetail() != null;
}
- public void removeAllFaultSubcodes()
+ /** Returns the optional detail element for this SOAPFault object.
+ */
+ public Detail getDetail()
{
- //TODO: SAAJ 1.3
- throw new NotImplementedException();
+ if (detail == null)
+ {
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()))
+ findSoap11DetailElement();
+ else
+ findSoap12DetailElement();
+ }
+ return detail;
}
- public void setFaultNode(String uri) throws SOAPException
+ /** Creates an optional Detail object and sets it as the Detail object for this
SOAPFault object.
+ */
+ public Detail addDetail() throws SOAPException
{
- //TODO: SAAJ 1.3
- throw new NotImplementedException();
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()))
+ {
+ if (detail == null)
+ findSoap11DetailElement();
+
+ if (detail != null)
+ throw new SOAPException("this fault already contains a detail
element");
+
+ detail = new DetailImpl();
+ }
+ else
+ {
+ if (detail == null)
+ findSoap12DetailElement();
+
+ if (detail != null)
+ throw new SOAPException("this fault already contains a detail
element");
+
+ detail = new DetailImpl(getPrefix(), getNamespaceURI());
+ }
+
+ detail = (Detail)addChildElement(detail);
+ return detail;
}
- public void setFaultRole(String uri) throws SOAPException
+ private void findSoap11DetailElement()
{
- assertSOAPBinding();
- this.faultRole = uri;
+ detail = (Detail)getChildElement(this, Constants.SOAP11_DETAIL);
+ log.trace("findSoap11DetailElement : " + detail);
}
- private void assertSOAPBinding()
+ private void findSoap12DetailElement()
{
- if(getNamespaceURI().equals(Constants.NS_SOAP11_ENV))
- throw new UnsupportedOperationException();
+ detail = (Detail)getChildElement(this, Constants.SOAP12_DETAIL);
+ log.trace("findSoap12DetailElement : " + detail);
}
+
+ @Override
+ public SOAPElement addChildElement(SOAPElement child) throws SOAPException
+ {
+ if (!(child instanceof SOAPFaultElement))
+ child = convertToFaultElement((SOAPElementImpl)child);
+
+ return super.addChildElement(child);
+ }
+
+ private SOAPFaultElement convertToFaultElement(SOAPElementImpl element)
+ {
+ element.detachNode();
+
+ QName elementName = element.getElementQName();
+ SOAPFaultElement faultElement;
+ if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()) ?
+ Constants.SOAP11_DETAIL.equals(elementName) :
+ Constants.SOAP12_DETAIL.equals(elementName))
+ faultElement = new DetailImpl(element);
+ else
+ faultElement = new SOAPFaultElementImpl(element);
+
+ log.trace("convertToFaultElement : " + faultElement);
+ return faultElement;
+ }
+
+ QName getDefaultFaultCode()
+ {
+ return Constants.NS_SOAP11_ENV.equals(getNamespaceURI()) ?
Constants.SOAP11_FAULT_CODE_SERVER : SOAPConstants.SOAP_RECEIVER_FAULT;
+ }
+
+ public void writeElement(Writer writer)
+ {
+ new DOMWriter(writer).print(this);
+ }
+
+ private static SOAPElement getChildElement(SOAPElement element, QName name)
+ {
+ Iterator it = element.getChildElements(name);
+ return it.hasNext() ? (SOAPElement)it.next() : null;
+ }
+
+ private SOAPElement addUnqualifiedFaultElement(String localName) throws SOAPException
+ {
+ log.trace("addUnqualifiedFaultElement(" + localName + ")");
+ return addChildElement(new SOAPFaultElementImpl(localName));
+ }
+
+ private SOAPElement addQualifiedFaultElement(String localName) throws SOAPException
+ {
+ log.trace("addQualifiedFaultElement(" + localName + ")");
+ return addChildElement(new SOAPFaultElementImpl(localName, getPrefix(),
getNamespaceURI()));
+ }
}
\ No newline at end of file
Modified: trunk/jbossws-core/src/java/org/jboss/ws/metadata/umdm/FaultMetaData.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/metadata/umdm/FaultMetaData.java 2007-03-10
17:09:00 UTC (rev 2581)
+++ trunk/jbossws-core/src/java/org/jboss/ws/metadata/umdm/FaultMetaData.java 2007-03-10
17:15:29 UTC (rev 2582)
@@ -63,8 +63,8 @@
private QName xmlType;
private String javaTypeName;
private String faultBeanName;
- private Class javaType;
- private Class faultBean;
+ private Class<? extends Exception> javaType;
+ private Class<?> faultBean;
private Method faultInfoMethod;
private Constructor<? extends Exception> serviceExceptionConstructor;
@@ -123,28 +123,31 @@
/** Load the java type.
* It should only be cached during eager initialization.
*/
- public Class<?> getJavaType()
+ public Class<? extends Exception> getJavaType()
{
- Class<?> tmpJavaType = javaType;
- if (tmpJavaType == null && javaTypeName != null)
+ if (javaType != null)
+ return javaType;
+
+ if (javaTypeName == null)
+ return null;
+
+ try
{
- try
- {
- ClassLoader loader = opMetaData.getEndpointMetaData().getClassLoader();
- tmpJavaType = JavaUtils.loadJavaType(javaTypeName, loader);
+ ClassLoader loader = opMetaData.getEndpointMetaData().getClassLoader();
+ Class<?> genericType = JavaUtils.loadJavaType(javaTypeName, loader);
+ Class<? extends Exception> exceptionType =
genericType.asSubclass(Exception.class);
- if
(opMetaData.getEndpointMetaData().getServiceMetaData().getUnifiedMetaData().isEagerInitialized())
- {
- log.warn("Loading java type after eager initialization");
- javaType = tmpJavaType.asSubclass(Exception.class);
- }
- }
- catch (ClassNotFoundException ex)
+ if
(opMetaData.getEndpointMetaData().getServiceMetaData().getUnifiedMetaData().isEagerInitialized())
{
- throw new WSException("Cannot load java type: " + javaTypeName,
ex);
+ log.warn("Loading java type after eager initialization");
+ javaType = exceptionType;
}
+ return exceptionType;
}
- return tmpJavaType;
+ catch (ClassNotFoundException ex)
+ {
+ throw new WSException("Cannot load java type: " + javaTypeName, ex);
+ }
}
public String getFaultBeanName()
@@ -283,8 +286,8 @@
try
{
/* use PropertyDescriptor(String, Class, String, String) instead
- * of PropertyDescriptor(String, Class) because the latter fails
- * with an IntrospectionException: Method not found: setXXX */
+ * of PropertyDescriptor(String, Class) because the latter requires
+ * the setter method to be present */
PropertyDescriptor propertyDescriptor = new
PropertyDescriptor(propertyName, javaType, "is" +
JavaUtils.capitalize(propertyName), null);
serviceExceptionGetters[i] = propertyDescriptor.getReadMethod();
}
@@ -391,7 +394,7 @@
for (int i = 0; i < propertyCount; i++)
propertyValues[i] = faultBeanProperties[i].accessor().get(faultBean);
- if(log.isDebugEnabled()) log.debug("constructing " +
javaType.getSimpleName() + ": " + Arrays.toString(propertyValues));
+ log.debug("constructing " + javaType.getSimpleName() + ":
" + Arrays.toString(propertyValues));
serviceException = serviceExceptionConstructor.newInstance(propertyValues);
}
}