Skip to content

Commit 6c5f9dd

Browse files
author
Karl Rieb
committed
2.0-beta-5 release.
1 parent 886b128 commit 6c5f9dd

25 files changed

+46980
-4059
lines changed

ChangeLog.txt

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
2+
---------------------------------------------
3+
2.0-beta-5 (2016-01-22)
4+
- Updated to latest API specs.
5+
- Change format of tagged union classes.
6+
- Change getter method format from getAbc() to getAbcValue().
7+
- Add new isAbc() convenience methods.
8+
- Add new getTag() method for tag discrimination.
9+
- Accept List instead of ArrayList for requests.
10+
- Fix BadRequest exception for DbxFiles.listFolderLongpoll(String).
11+
- Uppercase enum and static fields.
12+
- Add support for Dropbox API team endpoints.
13+
- Expose localized user messages and request IDs in exceptions.
14+
115
---------------------------------------------
216
2.0-beta-4 (2015-12-10)
317
- Update sharing endpoints to support new paging routes.

ReadMe.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A Java library to access [Dropbox's HTTP-based Core API v2](https://www.dropbox.
44

55
License: [MIT](License.txt)
66

7-
[Javadoc.](http://dropbox.github.io/dropbox-sdk-java/api-docs/v2.0.x/)
7+
[Javadoc.](https://dropbox.github.io/dropbox-sdk-java/api-docs/v2.0.x/)
88

99
## Setup
1010

@@ -14,12 +14,12 @@ If you're using Maven, then edit your project's "pom.xml" and add this to the `<
1414
<dependency>
1515
<groupId>com.dropbox.core</groupId>
1616
<artifactId>dropbox-core-sdk</artifactId>
17-
<version>2.0-beta-4</version>
17+
<version>2.0-beta-5</version>
1818
</dependency>
1919
```
2020

2121
If you aren't using Maven, here are the JARs you need:
22-
- [Dropbox Core SDK 2.0-beta-4](https://oss.sonatype.org/content/repositories/releases/com/dropbox/core/dropbox-core-sdk/2.0-beta-4/dropbox-core-sdk-2.0-beta-4.jar)
22+
- [Dropbox Core SDK 2.0-beta-5](https://oss.sonatype.org/content/repositories/releases/com/dropbox/core/dropbox-core-sdk/2.0-beta-5/dropbox-core-sdk-2.0-beta-5.jar)
2323
- [Jackson Core 2.6.1](https://oss.sonatype.org/content/repositories/releases/com/fasterxml/jackson/core/jackson-core/2.6.1/jackson-core-2.6.1.jar) (JSON parser)
2424

2525
## Get a Dropbox API key
@@ -156,4 +156,4 @@ mvn package -Dosgi.bnd.noee=true
156156

157157
(This is equivalent to passing the "-noee" option to the OSGi "bnd" tool.)
158158

159-
Another workaround is to tell your OSGi container to provide that requirement: [StackOverflow answer](http://stackoverflow.com/a/24673359/163832).
159+
Another workaround is to tell your OSGi container to provide that requirement: [StackOverflow answer](https://stackoverflow.com/a/24673359/163832).

examples/account-info/src/com/dropbox/core/examples/account_info/Main.java

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public static void main(String[] args)
6161

6262
// Make the /account/info API call.
6363
DbxUsers.FullAccount dbxAccountInfo;
64-
DbxUsers.SpaceUsage dbxSpaceUsage;
6564
try {
6665
dbxAccountInfo = dbxClient.users.getCurrentAccount();
6766
}

examples/web-file-browser/src/com/dropbox/core/examples/web_file_browser/DropboxBrowse.java

+13-14
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ private DbxClientV2 requireDbxClient(HttpServletRequest request, HttpServletResp
5050
private boolean checkPathError(HttpServletResponse response, String path, DbxFiles.LookupError le)
5151
throws IOException
5252
{
53-
switch (le.tag) {
54-
case notFound: case notFolder:
53+
switch (le.getTag()) {
54+
case NOT_FOUND:
55+
case NOT_FOLDER:
5556
response.sendError(400, "Path doesn't exist on Dropbox: " + jq(path));
5657
return true;
5758
}
@@ -70,8 +71,8 @@ private void renderFolder(HttpServletResponse response, User user, DbxClientV2 d
7071
result = dbxClient.files.listFolder(path);
7172
}
7273
catch (DbxFiles.ListFolderException ex) {
73-
if (ex.errorValue.tag == DbxFiles.ListFolderError.Tag.path) {
74-
if (checkPathError(response, path, ex.errorValue.getPath())) return;
74+
if (ex.errorValue.isPath()) {
75+
if (checkPathError(response, path, ex.errorValue.getPathValue())) return;
7576
}
7677
throw ex;
7778
}
@@ -91,8 +92,8 @@ private void renderFolder(HttpServletResponse response, User user, DbxClientV2 d
9192
result = dbxClient.files.listFolderContinue(result.cursor);
9293
}
9394
catch (DbxFiles.ListFolderContinueException ex) {
94-
if (ex.errorValue.tag == DbxFiles.ListFolderContinueError.Tag.path) {
95-
if (checkPathError(response, path, ex.errorValue.getPath())) return;
95+
if (ex.errorValue.isPath()) {
96+
if (checkPathError(response, path, ex.errorValue.getPathValue())) return;
9697
}
9798
throw ex;
9899
}
@@ -196,14 +197,12 @@ public void doBrowse(HttpServletRequest request, HttpServletResponse response)
196197
metadata = dbxClient.files.getMetadata(path);
197198
}
198199
catch (DbxFiles.GetMetadataException ex) {
199-
switch (ex.errorValue.tag) {
200-
case path:
201-
DbxFiles.LookupError le = ex.errorValue.getPath();
202-
switch (le.tag) {
203-
case notFound:
204-
response.sendError(400, "Path doesn't exist on Dropbox: " + jq(path));
205-
return;
206-
}
200+
if (ex.errorValue.isPath()) {
201+
DbxFiles.LookupError le = ex.errorValue.getPathValue();
202+
if (le.isNotFound()) {
203+
response.sendError(400, "Path doesn't exist on Dropbox: " + jq(path));
204+
return;
205+
}
207206
}
208207
common.handleException(response, ex, "getMetadata(" + jq(path) + ")");
209208
return;

src/com/dropbox/core/DbxApiException.java

+34-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,38 @@
55
*/
66
public class DbxApiException extends DbxException
77
{
8-
public DbxApiException(String message) { super(message); }
9-
public DbxApiException(String message, Throwable cause) { super(message, cause); }
8+
/**
9+
* A human-readable message that can be displayed to the end user. Is {@code null} when unavailable.
10+
*/
11+
public final LocalizedText userMessage;
12+
13+
public DbxApiException(String requestId, LocalizedText userMessage, String message)
14+
{
15+
super(requestId, message);
16+
this.userMessage = userMessage;
17+
}
18+
19+
public DbxApiException(String requestId, LocalizedText userMessage, String message, Throwable cause)
20+
{
21+
super(requestId, message, cause);
22+
this.userMessage = userMessage;
23+
}
24+
25+
protected static String buildMessage(String routeName, LocalizedText userMessage)
26+
{
27+
return buildMessage(routeName, userMessage, null);
28+
}
29+
30+
protected static String buildMessage(String routeName, LocalizedText userMessage, Object errorValue)
31+
{
32+
StringBuilder sb = new StringBuilder();
33+
sb.append("Exception in ").append(routeName);
34+
if (errorValue != null) {
35+
sb.append(": ").append(errorValue);
36+
}
37+
if (userMessage != null) {
38+
sb.append(" (user message: ").append(userMessage).append(")");
39+
}
40+
return sb.toString();
41+
}
1042
}

src/com/dropbox/core/DbxAuthInfo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void write(DbxAuthInfo authInfo, JsonGenerator g) throws IOException
7676
g.writeStartObject();
7777
g.writeStringField("access_token", authInfo.accessToken);
7878
if (!authInfo.host.equals(DbxHost.Default)) {
79-
g.writeObjectFieldStart("host");
79+
g.writeFieldName("host");
8080
DbxHost.Writer.write(authInfo.host, g);
8181
}
8282
g.writeEndObject();

src/com/dropbox/core/DbxException.java

+33-15
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,26 @@
1010
*/
1111
public class DbxException extends Exception
1212
{
13-
public DbxException(String message) { super(message); }
14-
public DbxException(String message, Throwable cause) { super(message, cause); }
13+
public final String requestId;
14+
15+
public DbxException(String message) {
16+
this(null, message);
17+
}
18+
19+
public DbxException(String requestId, String message) {
20+
super(message);
21+
this.requestId = requestId;
22+
}
23+
24+
public DbxException(String message, Throwable cause) {
25+
this(null, message, cause);
26+
}
27+
28+
public DbxException(String requestId, String message, Throwable cause) {
29+
super(message, cause);
30+
this.requestId = requestId;
31+
}
32+
1533
public static final long serialVersionUID = 0;
1634

1735
/**
@@ -39,7 +57,7 @@ public class DbxException extends Exception
3957
*/
4058
public static final class ServerError extends DbxException
4159
{
42-
public ServerError(String message) { super(message); }
60+
public ServerError(String requestId, String message) { super(requestId, message); }
4361
public static final long serialVersionUID = 0;
4462
}
4563

@@ -49,9 +67,9 @@ public static final class ServerError extends DbxException
4967
public static final class RetryLater extends DbxException
5068
{
5169
// TODO: Maybe parse out the server's recommended delay
52-
public RetryLater(String message)
70+
public RetryLater(String requestId, String message)
5371
{
54-
super(message);
72+
super(requestId, message);
5573
}
5674
public static final long serialVersionUID = 0;
5775
}
@@ -70,8 +88,8 @@ public RetryLater(String message)
7088
*/
7189
public static abstract class ProtocolError extends DbxException
7290
{
73-
public ProtocolError(String message) { super(message); }
74-
public ProtocolError(String message, Throwable cause) { super(message, cause); }
91+
public ProtocolError(String requestId, String message) { super(requestId, message); }
92+
public ProtocolError(String requestId, String message, Throwable cause) { super(requestId, message, cause); }
7593
public static final long serialVersionUID = 0;
7694
}
7795

@@ -81,7 +99,7 @@ public static abstract class ProtocolError extends DbxException
8199
*/
82100
public static final class BadRequest extends ProtocolError
83101
{
84-
public BadRequest(String message) { super(message); }
102+
public BadRequest(String requestId, String message) { super(requestId, message); }
85103
public static final long serialVersionUID = 0;
86104
}
87105

@@ -91,8 +109,8 @@ public static final class BadRequest extends ProtocolError
91109
*/
92110
public static class BadResponse extends ProtocolError
93111
{
94-
public BadResponse(String message) { super(message); }
95-
public BadResponse(String message, Throwable cause) { super(message, cause); }
112+
public BadResponse(String requestId, String message) { super(requestId, message); }
113+
public BadResponse(String requestId, String message, Throwable cause) { super(requestId, message, cause); }
96114
public static final long serialVersionUID = 0;
97115
}
98116

@@ -103,15 +121,15 @@ public static class BadResponseCode extends BadResponse
103121
{
104122
public final int statusCode;
105123

106-
public BadResponseCode(String message, int statusCode)
124+
public BadResponseCode(String requestId, String message, int statusCode)
107125
{
108-
super(message);
126+
super(requestId, message);
109127
this.statusCode = statusCode;
110128
}
111129

112-
public BadResponseCode(String message, int statusCode, Throwable cause)
130+
public BadResponseCode(String requestId, String message, int statusCode, Throwable cause)
113131
{
114-
super(message, cause);
132+
super(requestId, message, cause);
115133
this.statusCode = statusCode;
116134
}
117135

@@ -152,7 +170,7 @@ public NetworkIO(IOException underlying)
152170
*/
153171
public static final class InvalidAccessToken extends DbxException
154172
{
155-
public InvalidAccessToken(String message) { super(message); }
173+
public InvalidAccessToken(String requestId, String message) { super(requestId, message); }
156174
public static final long serialVersionUID = 0;
157175
}
158176
}

src/com/dropbox/core/DbxOAuth1Upgrader.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public String createOAuth2AccessToken(DbxOAuth1AccessToken token)
5050
null, getHeaders(token), new DbxRequestUtil.ResponseHandler<String>() {
5151
public String handle(HttpRequestor.Response response) throws DbxException {
5252
if (response.statusCode != 200) throw DbxRequestUtil.unexpectedStatus(response);
53-
return DbxRequestUtil.readJsonFromResponse(ResponseReader, response.body);
53+
return DbxRequestUtil.readJsonFromResponse(ResponseReader, response);
5454
}
5555
});
5656
}

0 commit comments

Comments
 (0)