Example usage for javax.xml.ws WebServiceException toString

List of usage examples for javax.xml.ws WebServiceException toString

Introduction

In this page you can find the example usage for javax.xml.ws WebServiceException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:org.apache.axis2.jaxws.marshaller.impl.alt.MethodMarshallerUtils.java

/**
 * This method is used by WebService Impl and Provider to create an XMLFault (for marshalling)
 * from an exception that is a non-service exception
 *
 * @param t Throwable that represents a Service Exception
 * @return XMLFault/*  w ww  .ja  v a2  s . com*/
 */
public static XMLFault createXMLFaultFromSystemException(Throwable t) {

    try {
        XMLFault xmlfault = null;
        if (t instanceof SOAPFaultException) {
            if (log.isErrorEnabled()) {
                log.debug("Marshal SOAPFaultException");
            }
            // Category C: SOAPFaultException 
            // Construct the xmlFault from the SOAPFaultException's Fault
            SOAPFaultException sfe = (SOAPFaultException) t;
            SOAPFault soapFault = sfe.getFault();
            if (soapFault == null) {
                // No fault ?  I will treat this like category E
                xmlfault = new XMLFault(null, // Use the default XMLFaultCode
                        new XMLFaultReason(t.toString())); // Assumes text lang of current Locale
            } else {
                xmlfault = XMLFaultUtils.createXMLFault(soapFault);
            }

        } else if (t instanceof WebServiceException) {
            if (log.isErrorEnabled()) {
                log.debug("Marshal as a WebServiceException");
            }
            // Category D: WebServiceException
            // The reason is constructed with the getMessage of the exception.  
            // There is no detail
            WebServiceException wse = (WebServiceException) t;

            // Get the fault text using algorithm defined in JAX-WS 10.2.2.3
            String text = wse.getMessage();
            if (text == null || text.length() == 0) {
                text = wse.toString();
            }
            xmlfault = new XMLFault(null, // Use the default XMLFaultCode
                    new XMLFaultReason(text)); // Assumes text lang of current Locale
        } else {
            if (log.isErrorEnabled()) {
                log.debug("Marshal as a unchecked System Exception");
            }
            // Category E: Other System Exception
            // The reason is constructed with the toString of the exception.  
            // This places the class name of the exception in the reason
            // There is no detail.
            // Get the fault text using algorithm defined in JAX-WS 10.2.2.3
            String text = t.getMessage();
            if (text == null || text.length() == 0) {
                text = t.toString();
            }
            xmlfault = new XMLFault(null, // Use the default XMLFaultCode
                    new XMLFaultReason(text)); // Assumes text lang of current Locale
        }
        return xmlfault;
    } catch (Throwable e) {
        try {
            // If an exception occurs while demarshalling an exception, 
            // then rinse and repeat with a webservice exception
            if (log.isDebugEnabled()) {
                log.debug("An exception (" + e + ") occurred while marshalling exception (" + t + ")");
            }
            // Get the fault text using algorithm defined in JAX-WS 10.2.2.3
            String text = e.getMessage();
            if (text == null || text.length() == 0) {
                text = e.toString();
            }
            WebServiceException wse = ExceptionFactory.makeWebServiceException(e);

            return new XMLFault(null, // Use the default XMLFaultCode
                    new XMLFaultReason(text)); // Assumes text lang of current Locale
        } catch (Exception e2) {
            // Exception while creating Exception for Exception
            throw ExceptionFactory.makeWebServiceException(e2);
        }
    }
}