public class

ServiceException

extends Exception
java.lang.Object
   ↳ java.lang.Throwable
     ↳ java.lang.Exception
       ↳ com.google.gdata.util.ServiceException
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

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

Summary

[Expand]
Inherited Constants
From class java.lang.Exception
From class java.lang.Throwable
Fields
ErrorElement errorElement
int httpErrorCodeOverride HTTP error code.
Map<String, List<String>> httpHeaders Optional HTTP headers to be output when HTTP response is generated.
String responseBody Retrieve HTTP response body or error message.
ContentType responseContentType Optional HTTP content type for a response.
List<ServiceException> siblings Set to the exception we are filling during parsing.
[Expand]
Inherited Fields
From class java.lang.Throwable
Public Constructors
ServiceException(String message)
ServiceException(String message, Throwable cause)
ServiceException(Throwable cause)
ServiceException(HttpURLConnection httpConn)
Initializes the ServiceException using the error response data from an HTTP connection.
ServiceException(ErrorContent errorCode)
Initializes the ServiceException using an ErrorContent object that encapsulates most of the information about the error.
ServiceException(ErrorContent errorCode, Throwable cause)
Initializes the ServiceException using an ErrorContent object that encapsulates most of the information about the error, and an embedded exception.
Public Methods
ServiceException addSibling(ServiceException newbie)
Make {@tt this} and {@tt newbie} siblings, returning {@tt this}.
String getCodeName()
Return error code.
String getDebugInfo()
Return debugging information.
String getDomainName()
Return error domain.
String getExtendedHelp()
Return URI for extended help
int getHttpErrorCodeOverride()
List<String> getHttpHeader(String header)
Return the value for requested internal HTTP header or null if the header is not present.
Map<String, List<String>> getHttpHeaders()
Return the internal HTTP headers in modifiable form.
String getInternalReason()
Return error internal reason.
String getLocation()
Return error location.
ErrorContent.LocationType getLocationType()
Return error location type.
String getMessage()
Return message: same as getInternalReason.
OAuthProxyResponse getOAuthProxyResponse()
Returns the headers related to the OAuth Proxy.
String getResponseBody()
ContentType getResponseContentType()
String getSendReport()
Return URI to send report to.
List<ServiceException> getSiblings()
Return an unmodifiable copy of the sibling list.
boolean hasOAuthProxyResponse()
Returns whether or not the request has OAuth Proxy-related headers.
Throwable initCause(Throwable cause)

If cause is a ServiceException, it is added to the list of siblings so that the original exception appears when using XML error output.

boolean matches(ErrorContent code)
Return true if this ServiceException matches the specified ErrorContent in domain name and code name.
boolean matchesAny(ErrorContent errorCode)
Return true if this ServiceException or any of its sibling exceptions matches the specified ErrorContent in domain name and code name.
void setCode(String code)
Set error code.
void setDebugInfo(String debugInfo)
Set debugging information.
void setDomain(String domain)
Set error domain.
void setExtendedHelp(String extendedHelp)
Set URI for extended help.
void setHeaderLocation(String location)
Set header name for an error in a header.
void setHttpErrorCodeOverride(int v)
void setInternalReason(String internalReason)
Sets the internal reason of the error.
void setLocation(String location)
Set generic error location.
void setResponse(ContentType contentType, String body)
Set HTTP response type and body simultaneously.
void setResponseBody(String body)
void setResponseContentType(ContentType v)
void setSendReport(String sendReport)
Set URI to send report to.
void setXpathLocation(String location)
Set XPath-based error location.
String toString()
String toXmlErrorMessage()
Converts the exception into a well-formated XML error message suitable for external uses.
String toXmlErrorMessage(boolean includeDebugInfo)
Converts the exception into a well-formated XML error message suitable for external uses.
[Expand]
Inherited Methods
From class java.lang.Throwable
From class java.lang.Object

Fields

ErrorElement errorElement

int httpErrorCodeOverride

HTTP error code.

Map<String, List<String>> httpHeaders

Optional HTTP headers to be output when HTTP response is generated. It is a mapping from header name to list of header values.

String responseBody

Retrieve HTTP response body or error message. The content type must be set correctly.

ContentType responseContentType

Optional HTTP content type for a response.

List<ServiceException> siblings

Set to the exception we are filling during parsing.

Public Constructors

public ServiceException (String message)

Parameters
message

public ServiceException (String message, Throwable cause)

Parameters
message
cause

public ServiceException (Throwable cause)

Parameters
cause

public ServiceException (HttpURLConnection httpConn)

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
IOException if network error receiving the error response

public ServiceException (ErrorContent errorCode)

Initializes the ServiceException using an ErrorContent object that encapsulates most of the information about the error. Most ErrorContent instances are declared in a subclass of ErrorDomain containing all the errors for a GData domain (service or portion of service).

Parameters
errorCode

public ServiceException (ErrorContent errorCode, Throwable cause)

Initializes the ServiceException using an ErrorContent object that encapsulates most of the information about the error, and an embedded exception. Most ErrorContent instances are declared in a subclass of ErrorDomain containing all the errors for this GData domain (service or portion of service).

Parameters
errorCode
cause

Public Methods

public ServiceException addSibling (ServiceException newbie)

Make {@tt this} and {@tt newbie} siblings, returning {@tt this}. All sibling exceptions are jointly converted to an error message when any of them are thrown.

Parameters
newbie

public String getCodeName ()

Return error code.

Defaults to the class name of this.

public String getDebugInfo ()

Return debugging information. Defaults to the stack trace.

public String getDomainName ()

Return error domain.

Defaults to "GData", indicating an error that has not yet been upgraded to the new architecture.

public String getExtendedHelp ()

Return URI for extended help

public int getHttpErrorCodeOverride ()

public List<String> getHttpHeader (String header)

Return the value for requested internal HTTP header or null if the header is not present.

Parameters
header Requested header name
Returns
  • list of string values for the specified header or null if requested header is not found.

public Map<String, List<String>> getHttpHeaders ()

Return the internal HTTP headers in modifiable form.

public String getInternalReason ()

Return error internal reason.

Defaults to the message set at construction time.

public String getLocation ()

Return error location.

public ErrorContent.LocationType getLocationType ()

Return error location type.

public String getMessage ()

Return message: same as getInternalReason.

public OAuthProxyResponse getOAuthProxyResponse ()

Returns the headers related to the OAuth Proxy. If there are no OAuth Proxy related headers on the request, this method will return an OAuthProxyResponse object with null values for the headers. Use hasOAuthProxyResponse() to determine whether the request has OAuth Proxy information.

public String getResponseBody ()

public ContentType getResponseContentType ()

public String getSendReport ()

Return URI to send report to.

public List<ServiceException> getSiblings ()

Return an unmodifiable copy of the sibling list.

public boolean hasOAuthProxyResponse ()

Returns whether or not the request has OAuth Proxy-related headers.

public Throwable initCause (Throwable cause)

If cause is a ServiceException, it is added to the list of siblings so that the original exception appears when using XML error output.

Parameters
cause

public boolean matches (ErrorContent code)

Return true if this ServiceException matches the specified ErrorContent in domain name and code name. Sibling exceptions are not checked.

Parameters
code

public boolean matchesAny (ErrorContent errorCode)

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

Parameters
errorCode

public void setCode (String code)

Set error code.

Parameters
code
Throws
NullPointerException if code is null.

public void setDebugInfo (String debugInfo)

Set debugging information.

Parameters
debugInfo
Throws
NullPointerException if debugInfo is null.

public void setDomain (String domain)

Set error domain.

Parameters
domain
Throws
NullPointerException if domain is null.

public void setExtendedHelp (String extendedHelp)

Set URI for extended help.

Parameters
extendedHelp
Throws
NullPointerException if extendedHelp is null.

public void setHeaderLocation (String location)

Set header name for an error in a header.

Parameters
location
Throws
NullPointerException if location is null.

public void setHttpErrorCodeOverride (int v)

Parameters
v

public void setInternalReason (String internalReason)

Sets the internal reason of the error.

Parameters
internalReason
Throws
NullPointerException if internalReason is null.

public void setLocation (String location)

Set generic error location.

Parameters
location
Throws
NullPointerException if location is null.

public void setResponse (ContentType contentType, 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.

Parameters
contentType
body

public void setResponseBody (String body)

Parameters
body

public void setResponseContentType (ContentType v)

Parameters
v

public void setSendReport (String sendReport)

Set URI to send report to.

Parameters
sendReport
Throws
NullPointerException if sendReport is null.

public void setXpathLocation (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).

Parameters
location
Throws
NullPointerException if location is null.

public String toString ()

public String toXmlErrorMessage ()

Converts the exception into a well-formated XML error message suitable for external uses.

public String toXmlErrorMessage (boolean includeDebugInfo)

Converts the exception into a well-formated XML error message suitable for external uses.

Parameters
includeDebugInfo If true, include debug information. Such error message should only be returned to internal clients.