cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Back again with another edition of 'How we use Dropbox', so find out how Emma uses to-do lists to get it all done here!

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

java.lang.UnsupportedOperationException

java.lang.UnsupportedOperationException

TejaVarma
Explorer | Level 4

Hi,

 

This is the code I am using 

try {
/**
* Changed URL from dropbox oauth 1 to 2
*/
// String urlToken = "https://api.dropboxapi.com/1/oauth2/token"; api.dropboxapi.com


String urlToken = "https://api.dropboxapi.com/oauth2/token";
String charset = "UTF-8"; // Or in Java 7 and later, use the constant: java.nio.charset.StandardCharsets.UTF_8.name()
String query = String.format("grant_type=authorization_code&%s&code=%s&client_id=%s&client_secret=%s",
"redirect_uri=https://192.168.137.129:8080/0/rest/cloudAdded?provider=dropbox",
URLEncoder.encode(authCode, charset),
URLEncoder.encode(APP_KEY, charset),
URLEncoder.encode(APP_SECRET, charset));
String inputStreamAsString = AccountsManager.getInputStreamAsString(urlToken, charset, query);
JSONObject json = new JSONObject(inputStreamAsString);
if (json.has("access_token"))
token1 = json.getString("access_token");
Log.d(LOG_TAG, "TODO - REMOVE THIS - dropbox core api returned - TOKEN:" + token1);
if (json.has("uid"))
uid1 = json.getString("uid");
Log.d(LOG_TAG, "Dropbox Core API returned - UID:" + uid1);
} catch (Exception e) {
Log.w(LOG_TAG, "Exception thrown " + e.getMessage());
throw new UnsupportedOperationException("TODO : handle this");
}

getInputStreamAsString Code 

public String getInputStreamAsString(String urlStr, String charset, String query)
throws IOException, NoSuchAlgorithmException, KeyManagementException
{
String result = "";
try{
URL url = new URL(urlStr);
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();

// set Timeout and method
conn.setReadTimeout(15000);
conn.setConnectTimeout(15000);
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true); // Triggers POST.

conn.setRequestProperty("Content-Language", "en-US");
conn.setRequestProperty("Accept-Charset", charset);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
OutputStream os = conn.getOutputStream();
os.write(query.getBytes(charset));
os.close();
conn.connect();
Log.d("", "getInputStreamAsString() : responseCode: " + conn.getResponseCode() +
"response message : " + conn.getResponseMessage());

//read the inputStream into a string
result = new String();
InputStream is = conn.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(is));
String inputLine;
while ((inputLine = in.readLine()) != null) {
result += inputLine;
}
} catch (Exception e) {
Log.w("", "Exception thrown " + e.getMessage());
throw new UnsupportedOperationException("TODO : handle this");
}
return result;
}

Please suggest me when we will get java.lang.UnsupportedOperationException

Thanks.
3 Replies 3

Re: java.lang.UnsupportedOperationException

Greg-DB
Dropboxer
It looks like you're throwing the UnsupportedOperationException in your own code in the catch block. Can you share the full error that is causing the catch block to run?

Re: java.lang.UnsupportedOperationException

TejaVarma
Explorer | Level 4

Hi,

 

Please find error

 

com.dropbox.core.NetworkIOException: failed to connect to api.dropboxapi.com/192.168.1.1 (port 443) after 20000ms
01-01 05:39:07.615 3871-5527/com.blueberryfon.filepod W/System.err: at com.dropbox.core.DbxRequestUtil.startPostRaw(DbxRequestUtil.java:240)
01-01 05:39:07.615 3871-5527/com.blueberryfon.filepod W/System.err: at com.dropbox.core.v2.DbxRawClientV2$1.execute(DbxRawClientV2.java:100)
01-01 05:39:07.615 3871-5527/com.blueberryfon.filepod W/System.err: at com.dropbox.core.v2.DbxRawClientV2.executeRetriable(DbxRawClientV2.java:256)
01-01 05:39:07.625 3871-5527/com.blueberryfon.filepod W/System.err: at com.dropbox.core.v2.DbxRawClientV2.rpcStyle(DbxRawClientV2.java:97)
01-01 05:39:07.625 3871-5527/com.blueberryfon.filepod W/System.err: at com.dropbox.core.v2.users.DbxUserUsersRequests.getCurrentAccount(DbxUserUsersRequests.java:120)
01-01 05:39:07.625 3871-5527/com.blueberryfon.filepod W/System.err: at com.blueberryfon.filepod.util.AddAccounts.addDropboxAccount(AddAccounts.java:50)
01-01 05:39:07.625 3871-5527/com.blueberryfon.filepod W/System.err: at com.blueberryfon.filepod.webserver.FilePodWebServer.serve(FilePodWebServer.java:271)
01-01 05:39:07.625 3871-5527/com.blueberryfon.filepod W/System.err: at com.blueberryfon.filepod.webserver.FilePodWebServer.serve(FilePodWebServer.java:124)
01-01 05:39:07.625 3871-5527/com.blueberryfon.filepod W/System.err: at fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:768)
01-01 05:39:07.625 3871-5527/com.blueberryfon.filepod W/System.err: at fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:186)
01-01 05:39:07.625 3871-5527/com.blueberryfon.filepod W/System.err: at java.lang.Thread.run(Thread.java:818)
01-01 05:39:07.625 3871-5527/com.blueberryfon.filepod W/System.err: Caused by: java.net.SocketTimeoutException: failed to connect to api.dropboxapi.com/192.168.1.1 (port 443) after 20000ms
01-01 05:39:07.635 3871-5527/com.blueberryfon.filepod W/System.err: at libcore.io.IoBridge.connectErrno(IoBridge.java:169)
01-01 05:39:07.635 3871-5527/com.blueberryfon.filepod W/System.err: at libcore.io.IoBridge.connect(IoBridge.java:122)
01-01 05:39:07.635 3871-5527/com.blueberryfon.filepod W/System.err: at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
01-01 05:39:07.635 3871-5527/com.blueberryfon.filepod W/System.err: at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456)
01-01 05:39:07.635 3871-5527/com.blueberryfon.filepod W/System.err: at java.net.Socket.connect(Socket.java:882)
01-01 05:39:07.635 3871-5527/com.blueberryfon.filepod W/System.err: at okhttp3.internal.platform.AndroidPlatform.connectSocket(AndroidPlatform.java:63)
01-01 05:39:07.635 3871-5527/com.blueberryfon.filepod W/System.err: at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:223)
01-01 05:39:07.635 3871-5527/com.blueberryfon.filepod W/System.err: at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:149)
01-01 05:39:07.635 3871-5527/com.blueberryfon.filepod W/System.err: at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:195)
01-01 05:39:07.635 3871-5527/com.blueberryfon.filepod W/System.err: at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:121)
01-01 05:39:07.635 3871-5527/com.blueberryfon.filepod W/System.err: at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:100)
01-01 05:39:07.645 3871-5527/com.blueberryfon.filepod W/System.err: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
01-01 05:39:07.645 3871-5527/com.blueberryfon.filepod W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
01-01 05:39:07.645 3871-5527/com.blueberryfon.filepod W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
01-01 05:39:07.645 3871-5527/com.blueberryfon.filepod W/System.err: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
01-01 05:39:07.645 3871-5527/com.blueberryfon.filepod W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
01-01 05:39:07.645 3871-5527/com.blueberryfon.filepod W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
01-01 05:39:07.645 3871-5527/com.blueberryfon.filepod W/System.err: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
01-01 05:39:07.645 3871-5527/com.blueberryfon.filepod W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
01-01 05:39:07.645 3871-5527/com.blueberryfon.filepod W/System.err: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
01-01 05:39:07.645 3871-5527/com.blueberryfon.filepod W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
01-01 05:39:07.645 3871-5527/com.blueberryfon.filepod W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
01-01 05:39:07.645 3871-5527/com.blueberryfon.filepod W/System.err: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185)
01-01 05:39:07.645 3871-5527/com.blueberryfon.filepod W/System.err: at okhttp3.RealCall.execute(RealCall.java:69)
01-01 05:39:07.645 3871-5527/com.blueberryfon.filepod W/System.err: at com.dropbox.core.http.OkHttp3Requestor$BufferedUploader.finish(OkHttp3Requestor.java:282)
01-01 05:39:07.645 3871-5527/com.blueberryfon.filepod W/System.err: at com.dropbox.core.DbxRequestUtil.startPostRaw(DbxRequestUtil.java:235)
01-01 05:39:07.645 3871-5527/com.blueberryfon.filepod W/System.err: ... 10 more

 

Thanks

Re: java.lang.UnsupportedOperationException

Greg-DB
Dropboxer

Thanks! That's helpful. This seems to be a network issue again. The Dropbox API servers are working properly though, so this indicate an issue with your network connection.

Specifically, based on the error "failed to connect to api.dropboxapi.com/192.168.1.1" it appears your computer thinks api.dropboxapi.com translates to 192.168.1.1. That's not correct. 192.168.1.1 is not a Dropbox IP address, but rather a private local address. You'll need to debug why your computer is resolving api.dropboxapi.com to 192.168.1.1.

Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropboxer
  • User avatar
    TejaVarma Explorer | Level 4
What do Dropbox user levels mean?
Need more support?