You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by st...@apache.org on 2004/05/17 16:42:03 UTC

cvs commit: ws-axis/java/src/org/apache/axis Constants.java AxisFault.java

stevel      2004/05/17 07:42:03

  Modified:    java/src/org/apache/axis Constants.java AxisFault.java
  Log:
  this is still a work-in-progress (I want an off switch), but as I'm not sure my laptop will come up when it next reboots, I wanted to check it in.
  
  The patch saves a hostname element to the fault detail unless one exists; its aim in life is to be useful tracking down on which machine something went wrong, especially with load balancing server farms or chained requests coming in to play.
  
  Revision  Changes    Path
  1.133     +10 -0     ws-axis/java/src/org/apache/axis/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/Constants.java,v
  retrieving revision 1.132
  retrieving revision 1.133
  diff -u -r1.132 -r1.133
  --- Constants.java	8 Apr 2004 13:09:05 -0000	1.132
  +++ Constants.java	17 May 2004 14:42:03 -0000	1.133
  @@ -641,6 +641,16 @@
        */
       public static final QName QNAME_FAULTDETAIL_HTTPERRORCODE = new QName(NS_URI_AXIS, "HttpErrorCode");
   
  +    /**
  +     * QName of a nested fault in an axis fault detail.
  +     */
  +    public static final QName QNAME_FAULTDETAIL_NESTEDFAULT = new QName(NS_URI_AXIS, "nestedFault");
  +
  +    /**
  +     * QName of a hostname in an axis fault detail.
  +     */
  +    public static final QName QNAME_FAULTDETAIL_HOSTNAME = new QName(NS_URI_AXIS, "hostname");
  +
       //QNames of well known faults
       /**
        * The no-service fault value.
  
  
  
  1.87      +65 -15    ws-axis/java/src/org/apache/axis/AxisFault.java
  
  Index: AxisFault.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/AxisFault.java,v
  retrieving revision 1.86
  retrieving revision 1.87
  diff -u -r1.86 -r1.87
  --- AxisFault.java	18 Apr 2004 18:07:36 -0000	1.86
  +++ AxisFault.java	17 May 2004 14:42:03 -0000	1.87
  @@ -21,6 +21,8 @@
   import java.util.ArrayList;
   import java.util.Iterator;
   import java.util.Vector;
  +import java.net.InetAddress;
  +import java.net.UnknownHostException;
   
   import javax.xml.namespace.QName;
   import javax.xml.parsers.ParserConfigurationException;
  @@ -34,6 +36,7 @@
   import org.apache.axis.soap.SOAPConstants;
   import org.apache.axis.utils.JavaUtils;
   import org.apache.axis.utils.XMLUtils;
  +import org.apache.axis.utils.NetworkUtils;
   import org.apache.commons.logging.Log;
   import org.w3c.dom.Document;
   import org.w3c.dom.Element;
  @@ -176,11 +179,17 @@
           // ? 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)
  -            initFromSOAPFaultException((SOAPFaultException)target);
  +        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();
  +        }
  +
       }
   
       /**
  @@ -218,6 +227,7 @@
           super (message, t);
           setFaultCodeAsString(Constants.FAULT_SERVER_GENERAL);
           setFaultString(getMessage());
  +        addHostnameIfNeeded();
       }
   
       /**
  @@ -257,6 +267,9 @@
           //add stack trace
           addFaultDetail(Constants.QNAME_FAULTDETAIL_STACKTRACE,
                   JavaUtils.stackToString(target));
  +
  +        //add the hostname
  +        addHostnameIfNeeded();
       }
       
       /**
  @@ -266,19 +279,23 @@
       private void initFromSOAPFaultException(SOAPFaultException fault) {
           
           // faultcode
  -        if ( fault.getFaultCode() != null)
  -            setFaultCode( fault.getFaultCode());
  +        if ( fault.getFaultCode() != null ) {
  +            setFaultCode(fault.getFaultCode());
  +        }
           
           // faultstring
  -        if ( fault.getFaultString() != null)        
  -            setFaultString( fault.getFaultString());
  +        if ( fault.getFaultString() != null ) {
  +            setFaultString(fault.getFaultString());
  +        }
           
           // actor
  -        if ( fault.getFaultActor() != null)
  -            setFaultActor( fault.getFaultActor());          
  -        
  -        if ( null == fault.getDetail())
  -            return;        
  +        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();       
  @@ -311,8 +328,7 @@
       /**
        * Dump the fault info to the log at debug level.
        */
  -    public void dump()
  -    {
  +    public void dump() {
           log.debug(dumpToString());
       }
   
  @@ -795,7 +811,7 @@
       /**
        * Writes any exception data to the faultDetails.
        *
  -     * This can be overrided (and is) by emitted exception clases.
  +     * 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.
        *
  @@ -826,5 +842,39 @@
               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);
       }
   }