📄 axisfault.java
字号:
* data structure, if it is needed. */ protected void initFaultSubCodes() { if (faultSubCode == null) { faultSubCode = new Vector(); } } /** * Add a fault sub-code. * This is new in SOAP 1.2, ignored in SOAP 1.1. * * @param code the <code>QName</code> of the fault sub-code to add * @since axis1.1 */ public void addFaultSubCode(QName code) { initFaultSubCodes(); faultSubCode.add(code); } /** * Clear all fault sub-codes. * This is new in SOAP 1.2, ignored in SOAP 1.1. * * @since axis1.1 */ public void clearFaultSubCodes() { faultSubCode = null; } /** * get the fault subcode list; only used in SOAP 1.2 * @since axis1.1 * @return null for no subcodes, or a QName array */ public QName[] getFaultSubCodes() { if (faultSubCode == null) { return null; } QName[] q = new QName[faultSubCode.size()]; return (QName[])faultSubCode.toArray(q); } /** * Set a fault string. * @param str new fault string; null is turned into "" */ public void setFaultString(String str) { if (str != null) { faultString = str ; } else { faultString = ""; } } /** * Get the fault string; this will never be null but may be the * empty string. * * @return a fault string */ public String getFaultString() { return( faultString ); } /** * This is SOAP 1.2 equivalent of {@link #setFaultString(java.lang.String)}. * * @param str the fault reason as a <code>String</code> * @since axis1.1 */ public void setFaultReason(String str) { setFaultString(str); } /** * This is SOAP 1.2 equivalent of {@link #getFaultString()}. * @since axis1.1 * @return the fault <code>String</code> */ public String getFaultReason() { return getFaultString(); } /** * Set the fault actor. * * @param actor fault actor */ public void setFaultActor(String actor) { faultActor = actor ; } /** * get the fault actor * @return actor or null */ public String getFaultActor() { return( faultActor ); } /** * This is SOAP 1.2 equivalent of {@link #getFaultActor()}. * @since axis1.1 * @return the name of the fault actor */ public String getFaultRole() { return getFaultActor(); } // fixme: both faultRole and faultActor refer to the other one - can we // break the circularity here? /** * This is SOAP 1.2 equivalent of {@link #setFaultActor(java.lang.String)}. * @since axis1.1 */ public void setFaultRole(String role) { setFaultActor(role); } /** * Get the fault node. * * This is new in SOAP 1.2 * @since axis1.1 * @return */ public String getFaultNode() { return( faultNode ); } /** * Set the fault node. * * This is new in SOAP 1.2. * * @param node a <code>String</code> representing the fault node * @since axis1.1 */ public void setFaultNode(String node) { faultNode = node; } /** * Set the fault detail element to the arrary of details. * * @param details list of detail elements, can be null */ public void setFaultDetail(Element[] details) { if ( details == null ) { faultDetails=null; return ; } faultDetails = new Vector( details.length ); for ( int loop = 0 ; loop < details.length ; loop++ ) { faultDetails.add( details[loop] ); } } /** * set the fault details to a string element. * @param details XML fragment */ public void setFaultDetailString(String details) { clearFaultDetails(); addFaultDetailString(details); } /** * add a string tag to the fault details. * @param detail XML fragment */ public void addFaultDetailString(String detail) { 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); } } /** * Append an element to the fault detail list. * * @param detail the new element to add * @since Axis1.1 */ public void addFaultDetail(Element detail) { initFaultDetails(); faultDetails.add(detail); } /** * Create an element of the given qname and add it to the details. * * @param qname qname of the element * @param body string to use as body */ public void addFaultDetail(QName qname,String body) { Element detail = XMLUtils.StringToElement(qname.getNamespaceURI(), qname.getLocalPart(), body); addFaultDetail(detail); } // fixme: should we be returning null for none or a zero length array? /** * Get all the fault details. * * @return an array of fault details, or null for none */ public Element[] getFaultDetails() { 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; } /** * Find a fault detail element by its qname. * @param qname name of the node to look for * @return the matching element or null * @since axis1.1 */ public Element lookupFaultDetail(QName 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; } /** * Find and remove a specified fault detail element. * * @param qname qualified name of detail * @return true if it was found and removed, false otherwise * @since axis1.1 */ public boolean removeFaultDetail(QName qname) { Element elt=lookupFaultDetail(qname); if(elt==null) { return false; } else { return faultDetails.remove(elt); } } /** * Add this fault and any needed headers to the output context. * * @param context * @throws Exception */ public void output(SerializationContext context) throws Exception { 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); } /** * Stringify this fault as the current fault string. * * @return the fault string, possibly the empty string, but never null */ public String toString() { return faultString; } /** * Gets the stack trace as a string. */ private String getPlainStackTrace() { StringWriter sw = new StringWriter(512); PrintWriter pw = new PrintWriter(sw); super.printStackTrace(pw); pw.close(); return sw.toString(); } /** * The override of the base class method prints out the * fault info before the stack trace. * * @param ps where to print */ public void printStackTrace(PrintStream ps) { ps.println(dumpToString()); super.printStackTrace(ps); } /** * The override of the base class method prints out the * fault info before the stack trace. * * @param pw where to print */ public void printStackTrace(java.io.PrintWriter pw) { pw.println(dumpToString()); super.printStackTrace(pw); } /** * Add a SOAP header which should be serialized along with the * fault. * * @param header a SOAPHeaderElement containing some fault-relevant stuff */ public void addHeader(SOAPHeaderElement header) { if (faultHeaders == null) { faultHeaders = new ArrayList(); } faultHeaders.add(header); } /** * Get the SOAP headers associated with this fault. * * @return an ArrayList containing any headers associated with this fault */ public ArrayList getHeaders() { return faultHeaders; } /** * Clear all fault headers. */ public void clearHeaders() { faultHeaders = null; } /** * 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. * * @param qname the <code>QName</code> to write this under * @param context the <code>SerializationContext</code> to write this fault * to * @throws java.io.IOException if we can't write ourselves for any reason */ public void writeDetails(QName qname, SerializationContext context) throws java.io.IOException { 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); } } /** * add the hostname of the current system. This is very useful for * locating faults on a cluster. * @since Axis1.2 */ public void addHostnameIfNeeded() { //look for an existing declaration if(lookupFaultDetail(Constants.QNAME_FAULTDETAIL_HOSTNAME)!=null) { //and do nothing if it exists return; } addHostname(NetworkUtils.getLocalHostname()); } /** * add the hostname string. If one already exists, remove it. * @param hostname string name of a host * @since Axis1.2 */ public void addHostname(String hostname) { //add the hostname removeHostname(); addFaultDetail(Constants.QNAME_FAULTDETAIL_HOSTNAME, hostname); } /** * strip out the hostname on a message. This * is useful for security reasons. */ public void removeHostname() { removeFaultDetail(Constants.QNAME_FAULTDETAIL_HOSTNAME); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -