com.google.gdata.util
Class ServiceException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by com.google.gdata.util.ServiceException
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
AppsForYourDomainException, AuthenticationException, BatchInterruptedException, EntityTooLargeException, InvalidEntryException, Kind.AdaptorException, NotAcceptableException, NotImplementedException, NotModifiedException, ParseException, PreconditionFailedException, RedirectRequiredException, ResourceNotFoundException, ServiceConfigurationException, ServiceForbiddenException, ServiceUnavailableException, VersionConflictException

public class ServiceException
extends java.lang.Exception

The ServiceException class is the base exception class used to indicate an error while processing a GDataRequest.

See Also:
Serialized Form

Nested Class Summary
static class ServiceException.LocationType
          Enumerated constants for error location types.
 
Constructor Summary
ServiceException(ErrorDomain.ErrorCode errorCode)
          Initializes the ServiceException using an ErrorCode object that encapsulates most of the information about the error.
ServiceException(ErrorDomain.ErrorCode errorCode, java.lang.Throwable cause)
          Initializes the ServiceException using an ErrorCode object that encapsulates most of the information about the error, and an embedded exception.
ServiceException(java.net.HttpURLConnection httpConn)
          Initializes the ServiceException using the error response data from an HTTP connection.
ServiceException(java.lang.String message)
           
ServiceException(java.lang.String message, java.lang.Throwable cause)
           
ServiceException(java.lang.Throwable cause)
           
 
Method Summary
 ServiceException addSibling(ServiceException newbie)
          Make and siblings, returning .
 java.lang.String getCodeName()
          Return error code.
 java.lang.String getDebugInfo()
          Return debugging information.
 java.lang.String getDomainName()
          Return error domain.
 java.lang.String getExtendedHelp()
          Return URI for extended help No default.
 int getHttpErrorCodeOverride()
           
 java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHttpHeaders()
          Return the internal HTTP headers in modifiable form.
 java.lang.String getInternalReason()
          Return error internal reason.
 java.lang.String getLocation()
          Return error location.
 ServiceException.LocationType getLocationType()
           
 java.lang.String getMessage()
          Return message: same as getInternalReason.
 java.lang.String getResponseBody()
           
 ContentType getResponseContentType()
           
 java.lang.String getSendReport()
          Return URI to send report to.
 java.util.List<ServiceException> getSiblings()
          Return an unmodifiable copy of the sibling list.
 boolean matches(ErrorDomain.ErrorCode errorCode)
          Return true if this ServiceException matches the specified ErrorDomain.ErrorCode in domain name and code name.
 boolean matchesAny(ErrorDomain.ErrorCode errorCode)
          Return true if this ServiceException or any of its sibling exceptions matches the specified ErrorDomain.ErrorCode in domain name and code name.
 void setCode(java.lang.String code)
          Set error code.
 void setDebugInfo(java.lang.String debugInfo)
          Set debugging information.
 void setDomain(java.lang.String domain)
          Set error domain.
 void setExtendedHelp(java.lang.String extendedHelp)
          Set URI for extended help.
 void setHeaderLocation(java.lang.String location)
          Set header name for an error in a header.
 void setHttpErrorCodeOverride(int v)
           
 void setInternalReason(java.lang.String internalReason)
          Set error internal reason.
 void setLocation(java.lang.String location)
          Set generic error location.
 void setResponse(ContentType contentType, java.lang.String body)
          Set HTTP response type and body simultaneously.
 void setResponseBody(java.lang.String body)
           
 void setResponseContentType(ContentType v)
           
 void setSendReport(java.lang.String sendReport)
          Set URI to send report to.
 void setXpathLocation(java.lang.String location)
          Set XPath-based error location.
 java.lang.String toString()
           
 java.lang.String toXmlErrorMessage()
          Generate error message in XML format.
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ServiceException

public ServiceException(java.lang.String message)

ServiceException

public ServiceException(java.lang.String message,
                        java.lang.Throwable cause)

ServiceException

public ServiceException(java.lang.Throwable cause)

ServiceException

public ServiceException(java.net.HttpURLConnection httpConn)
                 throws java.io.IOException
Initializes the ServiceException using the error response data from an HTTP connection. This constructor is used in the client library to approximately reconstitute the constructor as it appeared in the server.

This constructor uses a ServiceExceptionInitializer to do the work of parsing the connection and calling our setters to initialize our fields. The initializer object may also create sibling ServiceExceptions.

Parameters:
httpConn - is the http connection from which the error message (structured or simple) is read
Throws:
java.io.IOException - if network error receiving the error response

ServiceException

public ServiceException(ErrorDomain.ErrorCode errorCode)
Initializes the ServiceException using an ErrorCode object that encapsulates most of the information about the error. ErrorCodes are declared in a subclass of ErrorDomain containing all the errors for this GData domain (service or portion of service).


ServiceException

public ServiceException(ErrorDomain.ErrorCode errorCode,
                        java.lang.Throwable cause)
Initializes the ServiceException using an ErrorCode object that encapsulates most of the information about the error, and an embedded exception. ErrorCodes are declared in a subclass of ErrorDomain containing all the errors for this GData domain (service or portion of service).

Method Detail

getHttpErrorCodeOverride

public int getHttpErrorCodeOverride()

setHttpErrorCodeOverride

public void setHttpErrorCodeOverride(int v)

getResponseContentType

public ContentType getResponseContentType()

setResponseContentType

public void setResponseContentType(ContentType v)

getResponseBody

public java.lang.String getResponseBody()

setResponseBody

public void setResponseBody(java.lang.String body)

setResponse

public void setResponse(ContentType contentType,
                        java.lang.String body)
Set HTTP response type and body simultaneously. They are inherently coupled together: a body without a content type is meaningless; a content type without a body is useless.


toXmlErrorMessage

public java.lang.String toXmlErrorMessage()
Generate error message in XML format.


getHttpHeaders

public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHttpHeaders()
Return the internal HTTP headers in modifiable form.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Throwable

getDomainName

public java.lang.String getDomainName()
Return error domain. Defaults to "GData", indicating an error that has not yet been upgraded to the new architecture.


setDomain

public void setDomain(java.lang.String domain)
Set error domain.


getCodeName

public java.lang.String getCodeName()
Return error code. Defaults to the class name of this.


setCode

public void setCode(java.lang.String code)
Set error code.


getLocation

public java.lang.String getLocation()
Return error location. No default.


getLocationType

public ServiceException.LocationType getLocationType()

setXpathLocation

public void setXpathLocation(java.lang.String location)
Set XPath-based error location. This must be a valid XPath expression sibling to the atom:entry element (or the atom:feed element if we are not in an entry).


setHeaderLocation

public void setHeaderLocation(java.lang.String location)
Set header name for an error in a header.


setLocation

public void setLocation(java.lang.String location)
Set generic error location.


getInternalReason

public java.lang.String getInternalReason()
Return error internal reason. Defaults to the message set at construction time.


getMessage

public java.lang.String getMessage()
Return message: same as getInternalReason.

Overrides:
getMessage in class java.lang.Throwable

setInternalReason

public void setInternalReason(java.lang.String internalReason)
Set error internal reason.


getExtendedHelp

public java.lang.String getExtendedHelp()
Return URI for extended help No default.


setExtendedHelp

public void setExtendedHelp(java.lang.String extendedHelp)
Set URI for extended help.


getSendReport

public java.lang.String getSendReport()
Return URI to send report to. No default.


setSendReport

public void setSendReport(java.lang.String sendReport)
Set URI to send report to. No default.


getDebugInfo

public java.lang.String getDebugInfo()
Return debugging information. Defaults to the stack trace.


setDebugInfo

public void setDebugInfo(java.lang.String debugInfo)
Set debugging information.


getSiblings

public java.util.List<ServiceException> getSiblings()
Return an unmodifiable copy of the sibling list.


addSibling

public ServiceException addSibling(ServiceException newbie)
Make and siblings, returning . All sibling exceptions are jointly converted to an error message when any of them are thrown.


matches

public boolean matches(ErrorDomain.ErrorCode errorCode)
Return true if this ServiceException matches the specified ErrorDomain.ErrorCode in domain name and code name. Sibling exceptions are not checked.


matchesAny

public boolean matchesAny(ErrorDomain.ErrorCode errorCode)
Return true if this ServiceException or any of its sibling exceptions matches the specified ErrorDomain.ErrorCode in domain name and code name. If you want to know which particular ServiceException matched, call getSiblings() and examine the individual ServiceExceptions with #match.