diff options
author | Android (Google) Code Review <android-gerrit@google.com> | 2009-08-04 14:14:27 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2009-08-04 14:14:27 -0700 |
commit | 8f3167b4aa41107f31a97f702338506ba91a6e46 (patch) | |
tree | 5908853db7d2d94edb3bfeb2d4cd9079ce6567f0 | |
parent | 0521b859f58f907ca6eec33c404f7c64d8f3d468 (diff) | |
parent | f06ed2847456b3dfc372e40d6ac92ea1d456ea83 (diff) | |
download | gdata-8f3167b4aa41107f31a97f702338506ba91a6e46.tar.gz |
Merge change 8996
* changes:
- add ForbiddenException for response 403 - fix a bug in parsing the etag from the entries
3 files changed, 79 insertions, 27 deletions
diff --git a/src/com/google/wireless/gdata2/client/ForbiddenException.java b/src/com/google/wireless/gdata2/client/ForbiddenException.java new file mode 100644 index 0000000..49a19cb --- /dev/null +++ b/src/com/google/wireless/gdata2/client/ForbiddenException.java @@ -0,0 +1,37 @@ +// Copyright 2009 The Android Open Source Project. + +package com.google.wireless.gdata2.client; + +import com.google.wireless.gdata2.GDataException; + +/** + * Exception thrown when the server returns a 403 Forbidden. + */ +public class ForbiddenException extends GDataException { + + /** + * Creates a new AuthenticationException. + */ + public ForbiddenException() { + } + + /** + * Creates a new ForbiddenException with a supplied message. + * @param message The message for the exception. + */ + public ForbiddenException(String message) { + super(message); + } + + /** + * Creates a new ForbiddenException with a supplied message and + * underlying cause. + * + * @param message The message for the exception. + * @param cause Another throwable that was caught and wrapped in this + * exception. + */ + public ForbiddenException(String message, Throwable cause) { + super(message, cause); + } +}
\ No newline at end of file diff --git a/src/com/google/wireless/gdata2/client/GDataServiceClient.java b/src/com/google/wireless/gdata2/client/GDataServiceClient.java index e776460..dfdc31f 100644 --- a/src/com/google/wireless/gdata2/client/GDataServiceClient.java +++ b/src/com/google/wireless/gdata2/client/GDataServiceClient.java @@ -106,7 +106,8 @@ public abstract class GDataServiceClient { */ public GDataParser getParserForFeed(Class feedEntryClass, String feedUrl, String authToken, String eTag) throws AuthenticationException, ResourceGoneException, - ResourceNotModifiedException, HttpException, ParseException, IOException { + ResourceNotModifiedException, HttpException, ParseException, IOException, + ForbiddenException { try { InputStream is = gDataClient.getFeedAsStream(feedUrl, authToken, eTag, getProtocolVersion()); return gDataParserFactory.createParser(feedEntryClass, is); @@ -138,8 +139,8 @@ public abstract class GDataServiceClient { * GData service. */ public InputStream getMediaEntryAsStream(String mediaEntryUrl, String authToken, String eTag) - throws AuthenticationException, ResourceGoneException, ResourceNotModifiedException, - ResourceNotFoundException, HttpException, IOException { + throws AuthenticationException, ResourceGoneException, ResourceNotModifiedException, + ResourceNotFoundException, HttpException, IOException, ForbiddenException { try { return gDataClient .getMediaEntryAsStream(mediaEntryUrl, authToken, eTag, getProtocolVersion()); @@ -170,16 +171,22 @@ public abstract class GDataServiceClient { * GData service. */ public Entry createEntry(String feedUrl, String authToken, Entry entry) - throws ConflictDetectedException, AuthenticationException, PreconditionFailedException, - HttpException, ParseException, IOException { + throws ConflictDetectedException, AuthenticationException, PreconditionFailedException, + HttpException, ParseException, IOException, ForbiddenException { GDataSerializer serializer = gDataParserFactory.createSerializer(entry); try { InputStream is = gDataClient.createEntry(feedUrl, authToken, getProtocolVersion(), serializer); return parseEntry(entry.getClass(), is); } catch (HttpException e) { - convertHttpExceptionForWrites(entry.getClass(), "Could not create " + "entry " + feedUrl, e); - return null; // never reached. + try { + convertHttpExceptionForWrites(entry.getClass(), + "Could not create " + "entry " + feedUrl, e); + } catch (ResourceNotFoundException e1) { + // this should never happen + throw e; + } + return null; // never reached. } } @@ -204,8 +211,8 @@ public abstract class GDataServiceClient { * GData service. */ public Entry getEntry(Class entryClass, String id, String authToken, String eTag) - throws AuthenticationException, ResourceNotFoundException, ResourceNotModifiedException, - HttpException, ParseException, IOException { + throws AuthenticationException, ResourceNotFoundException, ResourceNotModifiedException, + HttpException, ParseException, IOException, ForbiddenException { try { InputStream is = getGDataClient().getFeedAsStream(id, authToken, eTag, getProtocolVersion()); return parseEntry(entryClass, is); @@ -236,8 +243,8 @@ public abstract class GDataServiceClient { * GData service. */ public Entry updateEntry(Entry entry, String authToken) throws AuthenticationException, - ConflictDetectedException, PreconditionFailedException, HttpException, ParseException, - IOException { + ConflictDetectedException, PreconditionFailedException, HttpException, ParseException, + IOException, ForbiddenException, ResourceNotFoundException { String editUri = entry.getEditUri(); if (StringUtils.isEmpty(editUri)) { throw new ParseException("No edit URI -- cannot update."); @@ -282,7 +289,8 @@ public abstract class GDataServiceClient { */ public MediaEntry updateMediaEntry(String editUri, InputStream inputStream, String contentType, String authToken, String eTag) throws AuthenticationException, ConflictDetectedException, - PreconditionFailedException, HttpException, ParseException, IOException { + PreconditionFailedException, HttpException, ParseException, IOException, + ForbiddenException, ResourceNotFoundException { if (StringUtils.isEmpty(editUri)) { throw new IllegalArgumentException("No edit URI -- cannot update."); } @@ -317,8 +325,9 @@ public abstract class GDataServiceClient { * GData service. */ public void deleteEntry(String editUri, String authToken, String eTag) - throws AuthenticationException, ConflictDetectedException, PreconditionFailedException, - HttpException, ParseException, IOException { + throws AuthenticationException, ConflictDetectedException, PreconditionFailedException, + HttpException, ParseException, IOException, ForbiddenException, + ResourceNotFoundException { try { gDataClient.deleteEntry(editUri, authToken, eTag); } catch (HttpException e) { @@ -359,7 +368,7 @@ public abstract class GDataServiceClient { */ public GDataParser submitBatch(Class feedEntryClass, String batchUrl, String authToken, Enumeration entries) throws AuthenticationException, HttpException, ParseException, - IOException { + IOException, ForbiddenException { GDataSerializer serializer = gDataParserFactory.createSerializer(entries); try { InputStream is = @@ -372,10 +381,11 @@ public abstract class GDataServiceClient { } protected void convertHttpExceptionForFeedReads(String message, HttpException cause) - throws AuthenticationException, ResourceGoneException, ResourceNotModifiedException, - HttpException { + throws AuthenticationException, ResourceGoneException, ResourceNotModifiedException, + HttpException, ForbiddenException { switch (cause.getStatusCode()) { case HttpException.SC_FORBIDDEN: + throw new ForbiddenException(message, cause); case HttpException.SC_UNAUTHORIZED: throw new AuthenticationException(message, cause); case HttpException.SC_GONE: @@ -389,10 +399,11 @@ public abstract class GDataServiceClient { } protected void convertHttpExceptionForEntryReads(String message, HttpException cause) - throws AuthenticationException, HttpException, ResourceNotFoundException, - ResourceNotModifiedException { + throws AuthenticationException, HttpException, ResourceNotFoundException, + ResourceNotModifiedException, ForbiddenException { switch (cause.getStatusCode()) { case HttpException.SC_FORBIDDEN: + throw new ForbiddenException(message, cause); case HttpException.SC_UNAUTHORIZED: throw new AuthenticationException(message, cause); case HttpException.SC_NOT_FOUND: @@ -406,9 +417,10 @@ public abstract class GDataServiceClient { } protected void convertHttpExceptionsForBatches(String message, HttpException cause) - throws AuthenticationException, ParseException, HttpException { + throws AuthenticationException, ParseException, HttpException, ForbiddenException { switch (cause.getStatusCode()) { case HttpException.SC_FORBIDDEN: + throw new ForbiddenException(message, cause); case HttpException.SC_UNAUTHORIZED: throw new AuthenticationException(message, cause); case HttpException.SC_BAD_REQUEST: @@ -419,9 +431,11 @@ public abstract class GDataServiceClient { } } - protected void convertHttpExceptionForWrites(Class entryClass, String message, HttpException cause) - throws ConflictDetectedException, AuthenticationException, PreconditionFailedException, - ParseException, HttpException, IOException { + protected void convertHttpExceptionForWrites(Class entryClass, String message, + HttpException cause) + throws ConflictDetectedException, AuthenticationException, PreconditionFailedException, + ParseException, HttpException, IOException, ForbiddenException, + ResourceNotFoundException { switch (cause.getStatusCode()) { case HttpException.SC_CONFLICT: Entry entry = null; @@ -435,10 +449,13 @@ public abstract class GDataServiceClient { case HttpException.SC_BAD_REQUEST: throw new ParseException(message + ": " + cause); case HttpException.SC_FORBIDDEN: + throw new ForbiddenException(message, cause); case HttpException.SC_UNAUTHORIZED: throw new AuthenticationException(message, cause); case HttpException.SC_PRECONDITION_FAILED: throw new PreconditionFailedException(message, cause); + case HttpException.SC_NOT_FOUND: + throw new ResourceNotFoundException(message, cause); default: throw new HttpException(message + ": " + cause.getMessage(), cause.getStatusCode(), cause .getResponseStream()); diff --git a/src/com/google/wireless/gdata2/contacts/parser/xml/XmlContactsGDataParser.java b/src/com/google/wireless/gdata2/contacts/parser/xml/XmlContactsGDataParser.java index 078539e..58e090c 100644 --- a/src/com/google/wireless/gdata2/contacts/parser/xml/XmlContactsGDataParser.java +++ b/src/com/google/wireless/gdata2/contacts/parser/xml/XmlContactsGDataParser.java @@ -31,10 +31,8 @@ public class XmlContactsGDataParser extends XmlGDataParser { /** The photo link rels */ public static final String LINK_REL_PHOTO = "http://schemas.google.com/contacts/2008/rel#photo"; - public static final String LINK_REL_EDIT_PHOTO = - "http://schemas.google.com/contacts/2008/rel#edit-photo"; - /** The phone number type gdata string. */ + /** The phone number type gdata string. */ private static final String GD_NAMESPACE = "http://schemas.google.com/g/2005#"; public static final String TYPESTRING_MOBILE = GD_NAMESPACE + "mobile"; public static final String TYPESTRING_HOME = GD_NAMESPACE + "home"; @@ -493,7 +491,7 @@ public class XmlContactsGDataParser extends XmlGDataParser { if (LINK_REL_PHOTO.equals(rel)) { ContactEntry contactEntry = (ContactEntry) entry; XmlPullParser parser = getParser(); - String etag = parser.getAttributeValue(null /* ns */, XmlNametable.ETAG); + String etag = parser.getAttributeValue(NAMESPACE_GD_URI, XmlNametable.ETAG); contactEntry.setLinkPhoto(href, type, etag); } } |