Constructors Summary |
---|
public AxisFault(String code, String faultString, String actor, Element[] details)Make a fault in the Constants.NS_URI_AXIS namespace.
this(new QName(Constants.NS_URI_AXIS, code),
faultString, actor, details);
|
public AxisFault(QName code, String faultString, String actor, Element[] details)Make a fault in any namespace.
super (faultString);
setFaultCode( code );
setFaultString( faultString );
setFaultActor( actor );
setFaultDetail( details );
if (details == null) {
initFromException(this);
}
|
public AxisFault(QName code, QName[] subcodes, String faultString, String actor, String node, Element[] details)Make a fault in any namespace.
super (faultString);
setFaultCode( code );
if (subcodes != null) {
for (int i = 0; i < subcodes.length; i++) {
addFaultSubCode( subcodes[i] );
}
}
setFaultString( faultString );
setFaultActor( actor );
setFaultNode( node );
setFaultDetail( details );
if (details == null) {
initFromException(this);
}
|
protected AxisFault(Exception target)Wrap an AxisFault around an existing Exception. This is private
to force everyone to use makeFault() above, which sanity-checks us.
super ("", target);
// ? SOAP 1.2 or 1.1 ?
setFaultCodeAsString( Constants.FAULT_SERVER_USER );
initFromException(target);
// if the target is a JAX-RPC SOAPFaultException init
// AxisFault with the values from the SOAPFaultException
if ( target instanceof SOAPFaultException ) {
//strip out the hostname as we want any new one
removeHostname();
initFromSOAPFaultException((SOAPFaultException) target);
//but if they left it out, add it
addHostnameIfNeeded();
}
|
public AxisFault(String message)create a simple axis fault from the message. Classname and stack trace
go into the fault details.
super (message);
setFaultCodeAsString(Constants.FAULT_SERVER_GENERAL);
setFaultString(message);
initFromException(this);
|
public AxisFault()No-arg constructor for building one from an XML stream.
super();
setFaultCodeAsString(Constants.FAULT_SERVER_GENERAL);
initFromException(this);
|
public AxisFault(String message, Throwable t)create a fault from any throwable;
When faulting a throwable (as opposed to an exception),
stack trace information does not go into the fault.
super (message, t);
setFaultCodeAsString(Constants.FAULT_SERVER_GENERAL);
setFaultString(getMessage());
addHostnameIfNeeded();
|
Methods Summary |
---|
public void | addFaultDetail(org.w3c.dom.Element detail)Append an element to the fault detail list.
initFaultDetails();
faultDetails.add(detail);
|
public void | addFaultDetail(javax.xml.namespace.QName qname, java.lang.String body)Create an element of the given qname and add it to the details.
Element detail = XMLUtils.StringToElement(qname.getNamespaceURI(),
qname.getLocalPart(),
body);
addFaultDetail(detail);
|
public void | addFaultDetailString(java.lang.String detail)add a string tag to the fault details.
initFaultDetails();
try {
Document doc = XMLUtils.newDocument();
Element element = doc.createElement("string");
Text text = doc.createTextNode(detail);
element.appendChild(text);
faultDetails.add(element);
} catch (ParserConfigurationException e) {
// This should not occur
throw new InternalException(e);
}
|
public void | addFaultSubCode(javax.xml.namespace.QName code)Add a fault sub-code.
This is new in SOAP 1.2, ignored in SOAP 1.1.
initFaultSubCodes();
faultSubCode.add(code);
|
public void | addFaultSubCodeAsString(java.lang.String code)Add a fault sub-code with the local name code and namespace
Constants.NS_URI_AXIS .
This is new in SOAP 1.2, ignored in SOAP 1.1
initFaultSubCodes();
faultSubCode.add(new QName(Constants.NS_URI_AXIS, code));
|
public void | addHeader(org.apache.axis.message.SOAPHeaderElement header)Add a SOAP header which should be serialized along with the
fault.
if (faultHeaders == null) {
faultHeaders = new ArrayList();
}
faultHeaders.add(header);
|
public void | addHostname(java.lang.String hostname)add the hostname string. If one already exists, remove it.
//add the hostname
removeHostname();
addFaultDetail(Constants.QNAME_FAULTDETAIL_HOSTNAME,
hostname);
|
public void | addHostnameIfNeeded()add the hostname of the current system. This is very useful for
locating faults on a cluster.
//look for an existing declaration
if(lookupFaultDetail(Constants.QNAME_FAULTDETAIL_HOSTNAME)!=null) {
//and do nothing if it exists
return;
}
addHostname(NetworkUtils.getLocalHostname());
|
public void | clearFaultDetails()Clear the fault details list.
faultDetails=null;
|
public void | clearFaultSubCodes()Clear all fault sub-codes.
This is new in SOAP 1.2, ignored in SOAP 1.1.
faultSubCode = null;
|
public void | clearHeaders()Clear all fault headers.
faultHeaders = null;
|
public void | dump()Dump the fault info to the log at debug level.
log.debug(dumpToString());
|
public java.lang.String | dumpToString()turn the fault and details into a string, with XML escaping.
subclassers: for security (cross-site-scripting) reasons,
escape everything that could contain caller-supplied data.
StringBuffer buf = new StringBuffer("AxisFault");
buf.append(JavaUtils.LS);
buf.append(" faultCode: ");
buf.append(XMLUtils.xmlEncodeString(faultCode.toString()));
buf.append(JavaUtils.LS);
buf.append(" faultSubcode: ");
if (faultSubCode != null) {
for (int i = 0; i < faultSubCode.size(); i++) {
buf.append(JavaUtils.LS);
buf.append(faultSubCode.elementAt(i).toString());
}
}
buf.append(JavaUtils.LS);
buf.append(" faultString: ");
try {
buf.append(XMLUtils.xmlEncodeString(faultString));
} catch (RuntimeException re) {
buf.append(re.getMessage());
}
buf.append(JavaUtils.LS);
buf.append(" faultActor: ");
buf.append(XMLUtils.xmlEncodeString(faultActor));
buf.append(JavaUtils.LS);
buf.append(" faultNode: ");
buf.append(XMLUtils.xmlEncodeString(faultNode));
buf.append(JavaUtils.LS);
buf.append(" faultDetail: ");
if (faultDetails != null) {
for (int i=0; i < faultDetails.size(); i++) {
Element e = (Element) faultDetails.get(i);
buf.append(JavaUtils.LS);
buf.append("\t{");
buf.append(null == e.getNamespaceURI() ? "" : e.getNamespaceURI());
buf.append("}");
buf.append(null == e.getLocalName() ? "" : e.getLocalName());
buf.append(":");
buf.append(XMLUtils.getInnerXMLString(e));
}
}
buf.append(JavaUtils.LS);
return buf.toString();
|
public java.lang.String | getFaultActor()get the fault actor
return( faultActor );
|
public javax.xml.namespace.QName | getFaultCode()Get the fault code QName .
return( faultCode );
|
public org.w3c.dom.Element[] | getFaultDetails()Get all the fault details.
if (faultDetails == null) {
return null;
}
Element result[] = new Element[faultDetails.size()];
for (int i=0; i<result.length; i++) {
result[i] = (Element) faultDetails.elementAt(i);
}
return result;
|
public java.lang.String | getFaultNode()Get the fault node.
This is new in SOAP 1.2
return( faultNode );
|
public java.lang.String | getFaultReason()This is SOAP 1.2 equivalent of {@link #getFaultString()}.
return getFaultString();
|
public java.lang.String | getFaultRole()This is SOAP 1.2 equivalent of {@link #getFaultActor()}.
return getFaultActor();
|
public java.lang.String | getFaultString()Get the fault string; this will never be null but may be the
empty string.
return( faultString );
|
public javax.xml.namespace.QName[] | getFaultSubCodes()get the fault subcode list; only used in SOAP 1.2
if (faultSubCode == null) {
return null;
}
QName[] q = new QName[faultSubCode.size()];
return (QName[])faultSubCode.toArray(q);
|
public java.util.ArrayList | getHeaders()Get the SOAP headers associated with this fault.
return faultHeaders;
|
private java.lang.String | getPlainStackTrace()Gets the stack trace as a string.
StringWriter sw = new StringWriter(512);
PrintWriter pw = new PrintWriter(sw);
super.printStackTrace(pw);
pw.close();
return sw.toString();
|
private void | initFaultDetails()Init the fault details data structure; does nothing
if this exists already.
if (faultDetails == null) {
faultDetails = new Vector();
}
|
protected void | initFaultSubCodes()Do whatever is needed to create the fault subcodes
data structure, if it is needed.
if (faultSubCode == null) {
faultSubCode = new Vector();
}
|
private void | initFromException(java.lang.Exception target)fill in soap fault details from the exception, unless
this object already has a stack trace in its details. Which, given
the way this private method is invoked, is a pretty hard situation to ever achieve.
This method adds classname of the exception and the stack trace.
//look for old stack trace
Element oldStackTrace = lookupFaultDetail(Constants.QNAME_FAULTDETAIL_STACKTRACE);
if (oldStackTrace != null) {
// todo: Should we replace it or just let it be?
return;
}
// Set the exception message (if any) as the fault string
setFaultString( target.toString() );
// Put the exception class into the AXIS SPECIFIC HACK
// "exceptionName" element in the details. This allows
// us to get back a correct Java Exception class on the other side
// (assuming they have it available).
// NOTE: This hack is obsolete! We now serialize exception data
// and the other side uses *that* QName to figure out what exception
// to use, because the class name may be completly different on the
// client.
if ((target instanceof AxisFault) &&
(target.getClass() != AxisFault.class)) {
addFaultDetail(Constants.QNAME_FAULTDETAIL_EXCEPTIONNAME,
target.getClass().getName());
}
//add stack trace
if (target == this) {
// only add stack trace. JavaUtils.stackToString() call would
// include dumpToString() info which is already sent as different
// elements of this fault.
addFaultDetail(Constants.QNAME_FAULTDETAIL_STACKTRACE,
getPlainStackTrace());
} else {
addFaultDetail(Constants.QNAME_FAULTDETAIL_STACKTRACE,
JavaUtils.stackToString(target));
}
//add the hostname
addHostnameIfNeeded();
|
private void | initFromSOAPFaultException(javax.xml.rpc.soap.SOAPFaultException fault)Initiates the AxisFault with the values from a SOAPFaultException
// faultcode
if ( fault.getFaultCode() != null ) {
setFaultCode(fault.getFaultCode());
}
// faultstring
if ( fault.getFaultString() != null ) {
setFaultString(fault.getFaultString());
}
// actor
if ( fault.getFaultActor() != null ) {
setFaultActor(fault.getFaultActor());
}
if ( null == fault.getDetail() ) {
return;
}
// We get an Iterator but we need a List
Vector details = new Vector();
Iterator detailIter = fault.getDetail().getChildElements();
while (detailIter.hasNext()) {
details.add( detailIter.next());
}
// Convert the List in an Array an return the array
setFaultDetail( XMLUtils.asElementArray(details));
|
public org.w3c.dom.Element | lookupFaultDetail(javax.xml.namespace.QName qname)Find a fault detail element by its qname.
if (faultDetails != null) {
//extract details from the qname. the empty namespace is represented
//by the empty string
String searchNamespace = qname.getNamespaceURI();
String searchLocalpart = qname.getLocalPart();
//now spin through the elements, seeking a match
Iterator it=faultDetails.iterator();
while (it.hasNext()) {
Element e = (Element) it.next();
String localpart= e.getLocalName();
if(localpart==null) {
localpart=e.getNodeName();
}
String namespace= e.getNamespaceURI();
if(namespace==null) {
namespace="";
}
//we match on matching namespace and local part; empty namespace
//in an element may be null, which matches QName's ""
if(searchNamespace.equals(namespace)
&& searchLocalpart.equals(localpart)) {
return e;
}
}
}
return null;
|
public static org.apache.axis.AxisFault | makeFault(java.lang.Exception e)Make an AxisFault based on a passed Exception. If the Exception is
already an AxisFault, simply use that. Otherwise, wrap it in an
AxisFault. If the Exception is an InvocationTargetException (which
already wraps another Exception), get the wrapped Exception out from
there and use that instead of the passed one.
if (e instanceof InvocationTargetException) {
Throwable t = ((InvocationTargetException)e).getTargetException();
if (t instanceof Exception) {
e = (Exception)t;
}
}
if (e instanceof AxisFault) {
return (AxisFault)e;
}
return new AxisFault(e);
|
public void | output(org.apache.axis.encoding.SerializationContext context)Add this fault and any needed headers to the output context.
SOAPConstants soapConstants = Constants.DEFAULT_SOAP_VERSION;
if (context.getMessageContext() != null) {
soapConstants = context.getMessageContext().getSOAPConstants();
}
SOAPEnvelope envelope = new SOAPEnvelope(soapConstants);
SOAPFault fault = new SOAPFault(this);
envelope.addBodyElement(fault);
// add any headers we need
if (faultHeaders != null) {
for (Iterator i = faultHeaders.iterator(); i.hasNext();) {
SOAPHeaderElement header = (SOAPHeaderElement) i.next();
envelope.addHeader(header);
}
}
envelope.output(context);
|
public void | printStackTrace(java.io.PrintStream ps)The override of the base class method prints out the
fault info before the stack trace.
ps.println(dumpToString());
super.printStackTrace(ps);
|
public void | printStackTrace(java.io.PrintWriter pw)The override of the base class method prints out the
fault info before the stack trace.
pw.println(dumpToString());
super.printStackTrace(pw);
|
public boolean | removeFaultDetail(javax.xml.namespace.QName qname)Find and remove a specified fault detail element.
Element elt=lookupFaultDetail(qname);
if(elt==null) {
return false;
} else {
return faultDetails.remove(elt);
}
|
public void | removeHostname()strip out the hostname on a message. This
is useful for security reasons.
removeFaultDetail(Constants.QNAME_FAULTDETAIL_HOSTNAME);
|
public void | setFaultActor(java.lang.String actor)Set the fault actor.
faultActor = actor ;
|
public void | setFaultCode(javax.xml.namespace.QName code)Set the fault code.
faultCode = code ;
|
public void | setFaultCode(java.lang.String code)Set the fault code (as a String).
setFaultCodeAsString(code);
|
public void | setFaultCodeAsString(java.lang.String code)set a fault code string that is turned into a qname
in the SOAP 1.1 or 1.2 namespace, depending on the current context
SOAPConstants soapConstants = MessageContext.getCurrentContext() == null ?
SOAPConstants.SOAP11_CONSTANTS :
MessageContext.getCurrentContext().getSOAPConstants();
faultCode = new QName(soapConstants.getEnvelopeURI(), code);
|
public void | setFaultDetail(org.w3c.dom.Element[] details)Set the fault detail element to the arrary of details.
if ( details == null ) {
faultDetails=null;
return ;
}
faultDetails = new Vector( details.length );
for ( int loop = 0 ; loop < details.length ; loop++ ) {
faultDetails.add( details[loop] );
}
|
public void | setFaultDetailString(java.lang.String details)set the fault details to a string element.
clearFaultDetails();
addFaultDetailString(details);
|
public void | setFaultNode(java.lang.String node)Set the fault node.
This is new in SOAP 1.2.
faultNode = node;
|
public void | setFaultReason(java.lang.String str)This is SOAP 1.2 equivalent of {@link #setFaultString(java.lang.String)}.
setFaultString(str);
|
public void | setFaultRole(java.lang.String role)This is SOAP 1.2 equivalent of {@link #setFaultActor(java.lang.String)}.
setFaultActor(role);
|
public void | setFaultString(java.lang.String str)Set a fault string.
if (str != null) {
faultString = str ;
} else {
faultString = "";
}
|
public java.lang.String | toString()Stringify this fault as the current fault string.
return faultString;
|
public void | writeDetails(javax.xml.namespace.QName qname, org.apache.axis.encoding.SerializationContext context)Writes any exception data to the faultDetails.
This can be overridden (and is) by emitted exception clases.
The base implementation will attempt to serialize exception data the
fault was created from an Exception and a type mapping is found for it.
Object detailObject = this.detail;
if (detailObject == null) {
return;
}
boolean haveSerializer = false;
try {
if (context.getTypeMapping().getSerializer(detailObject.getClass()) != null) {
haveSerializer = true;
}
} catch (Exception e) {
// swallow this exception, it means that we don't know how to serialize
// the details.
}
if (haveSerializer) {
boolean oldMR = context.getDoMultiRefs();
context.setDoMultiRefs(false);
context.serialize(qname, null, detailObject);
context.setDoMultiRefs(oldMR);
}
|