@@ -53,17 +53,22 @@ public abstract class DbxRawClientV2 {
5353 private final DbxRequestConfig requestConfig ;
5454 private final DbxHost host ;
5555
56+ /* for multiple Dropbox account use-case */
57+ private final String userId ;
58+
5659 /**
5760 * @param requestConfig Configuration controlling How requests should be issued to Dropbox
5861 * servers.
5962 * @param host Dropbox server hostnames (primarily for internal use)
63+ * @param userId The user ID of the current Dropbox account. Used for multi-Dropbox account use-case.
6064 */
61- protected DbxRawClientV2 (DbxRequestConfig requestConfig , DbxHost host ) {
65+ protected DbxRawClientV2 (DbxRequestConfig requestConfig , DbxHost host , String userId ) {
6266 if (requestConfig == null ) throw new NullPointerException ("requestConfig" );
6367 if (host == null ) throw new NullPointerException ("host" );
6468
6569 this .requestConfig = requestConfig ;
6670 this .host = host ;
71+ this .userId = userId ;
6772 }
6873
6974 /**
@@ -95,6 +100,8 @@ public <ArgT,ResT,ErrT> ResT rpcStyle(final String host,
95100 headers .add (new HttpRequestor .Header ("Content-Type" , "application/json; charset=utf-8" ));
96101
97102 return executeRetriable (requestConfig .getMaxRetries (), new RetriableExecution <ResT > () {
103+ private String userIdAnon ;
104+
98105 @ Override
99106 public ResT execute () throws DbxWrappedException , DbxException {
100107 HttpRequestor .Response response = DbxRequestUtil .startPostRaw (requestConfig , USER_AGENT_ID , host , path , body , headers );
@@ -103,9 +110,9 @@ public ResT execute() throws DbxWrappedException, DbxException {
103110 case 200 :
104111 return responseSerializer .deserialize (response .getBody ());
105112 case 409 :
106- throw DbxWrappedException .fromResponse (errorSerializer , response );
113+ throw DbxWrappedException .fromResponse (errorSerializer , response , userIdAnon );
107114 default :
108- throw DbxRequestUtil .unexpectedStatus (response );
115+ throw DbxRequestUtil .unexpectedStatus (response , userIdAnon );
109116 }
110117 } catch (JsonProcessingException ex ) {
111118 String requestId = DbxRequestUtil .getRequestId (response );
@@ -114,7 +121,12 @@ public ResT execute() throws DbxWrappedException, DbxException {
114121 throw new NetworkIOException (ex );
115122 }
116123 }
117- });
124+
125+ private RetriableExecution <ResT > init (String userId ){
126+ this .userIdAnon = userId ;
127+ return this ;
128+ }
129+ }.init (this .userId ));
118130 }
119131
120132 public <ArgT ,ResT ,ErrT > DbxDownloader <ResT > downloadStyle (final String host ,
@@ -138,6 +150,8 @@ public <ArgT,ResT,ErrT> DbxDownloader<ResT> downloadStyle(final String host,
138150 final byte [] body = new byte [0 ];
139151
140152 return executeRetriable (requestConfig .getMaxRetries (), new RetriableExecution <DbxDownloader <ResT >>() {
153+ private String userIdAnon ;
154+
141155 @ Override
142156 public DbxDownloader <ResT > execute () throws DbxWrappedException , DbxException {
143157 HttpRequestor .Response response = DbxRequestUtil .startPostRaw (requestConfig , USER_AGENT_ID , host , path , body , headers );
@@ -163,17 +177,22 @@ public DbxDownloader<ResT> execute() throws DbxWrappedException, DbxException {
163177 ResT result = responseSerializer .deserialize (resultHeader );
164178 return new DbxDownloader <ResT >(result , response .getBody ());
165179 case 409 :
166- throw DbxWrappedException .fromResponse (errorSerializer , response );
180+ throw DbxWrappedException .fromResponse (errorSerializer , response , userIdAnon );
167181 default :
168- throw DbxRequestUtil .unexpectedStatus (response );
182+ throw DbxRequestUtil .unexpectedStatus (response , userIdAnon );
169183 }
170184 } catch (JsonProcessingException ex ) {
171185 throw new BadResponseException (requestId , "Bad JSON: " + ex .getMessage (), ex );
172186 } catch (IOException ex ) {
173187 throw new NetworkIOException (ex );
174188 }
175189 }
176- });
190+
191+ private RetriableExecution <DbxDownloader <ResT >> init (String userId ){
192+ this .userIdAnon = userId ;
193+ return this ;
194+ }
195+ }.init (this .userId ));
177196 }
178197
179198 private static <T > byte [] writeAsBytes (StoneSerializer <T > serializer , T arg ) throws DbxException {
@@ -243,6 +262,15 @@ public DbxHost getHost() {
243262 return host ;
244263 }
245264
265+ /**
266+ * Returns the {@code userId} that was passed in to the constructor.
267+ *
268+ * @return The user ID of the current Dropbox account.
269+ */
270+ public String getUserId () {
271+ return userId ;
272+ }
273+
246274 /**
247275 * Retries the execution at most a maximum number of times.
248276 *
0 commit comments