diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java index 202b750e4..5969455bd 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java @@ -166,12 +166,12 @@ public class HkpKeyserver extends Keyserver { mPort = port; } - private String query(String request) throws QueryException, HttpError { + private String query(String request) throws QueryFailedException, HttpError { InetAddress ips[]; try { ips = InetAddress.getAllByName(mHost); } catch (UnknownHostException e) { - throw new QueryException(e.toString()); + throw new QueryFailedException(e.toString()); } for (int i = 0; i < ips.length; ++i) { try { @@ -196,11 +196,11 @@ public class HkpKeyserver extends Keyserver { } } - throw new QueryException("querying server(s) for '" + mHost + "' failed"); + throw new QueryFailedException("querying server(s) for '" + mHost + "' failed"); } @Override - public ArrayList search(String query) throws QueryException, + public ArrayList search(String query) throws QueryFailedException, QueryNeedsRepairException { ArrayList results = new ArrayList(); @@ -231,7 +231,7 @@ public class HkpKeyserver extends Keyserver { throw new QueryTooShortException(); } } - throw new QueryException("querying server(s) for '" + mHost + "' failed"); + throw new QueryFailedException("querying server(s) for '" + mHost + "' failed"); } final Matcher matcher = PUB_KEY_LINE.matcher(data); @@ -287,7 +287,7 @@ public class HkpKeyserver extends Keyserver { } @Override - public String get(String keyIdHex) throws QueryException { + public String get(String keyIdHex) throws QueryFailedException { HttpClient client = new DefaultHttpClient(); try { String query = "http://" + mHost + ":" + mPort + @@ -296,7 +296,7 @@ public class HkpKeyserver extends Keyserver { HttpGet get = new HttpGet(query); HttpResponse response = client.execute(get); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { - throw new QueryException("not found"); + throw new QueryFailedException("not found"); } HttpEntity entity = response.getEntity(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyserver.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyserver.java index ec4b61671..f9b6abf18 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyserver.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyserver.java @@ -34,7 +34,7 @@ public class KeybaseKeyserver extends Keyserver { private String mQuery; @Override - public ArrayList search(String query) throws QueryException, + public ArrayList search(String query) throws QueryFailedException, QueryNeedsRepairException { ArrayList results = new ArrayList(); @@ -65,13 +65,13 @@ public class KeybaseKeyserver extends Keyserver { } } catch (Exception e) { Log.e(Constants.TAG, "keybase result parsing error", e); - throw new QueryException("Unexpected structure in keybase search result: " + e.getMessage()); + throw new QueryFailedException("Unexpected structure in keybase search result: " + e.getMessage()); } return results; } - private JSONObject getUser(String keybaseId) throws QueryException { + private JSONObject getUser(String keybaseId) throws QueryFailedException { try { return getFromKeybase("_/api/1.0/user/lookup.json?username=", keybaseId); } catch (Exception e) { @@ -79,11 +79,11 @@ public class KeybaseKeyserver extends Keyserver { if (keybaseId != null) { detail = ". Query was for user '" + keybaseId + "'"; } - throw new QueryException(e.getMessage() + detail); + throw new QueryFailedException(e.getMessage() + detail); } } - private ImportKeysListEntry makeEntry(JSONObject match) throws QueryException, JSONException { + private ImportKeysListEntry makeEntry(JSONObject match) throws QueryFailedException, JSONException { final ImportKeysListEntry entry = new ImportKeysListEntry(); entry.setQuery(mQuery); @@ -128,7 +128,7 @@ public class KeybaseKeyserver extends Keyserver { return entry; } - private JSONObject getFromKeybase(String path, String query) throws QueryException { + private JSONObject getFromKeybase(String path, String query) throws QueryFailedException { try { String url = "https://keybase.io/" + path + URLEncoder.encode(query, "utf8"); Log.d(Constants.TAG, "keybase query: " + url); @@ -144,29 +144,29 @@ public class KeybaseKeyserver extends Keyserver { try { JSONObject json = new JSONObject(text); if (JWalk.getInt(json, "status", "code") != 0) { - throw new QueryException("Keybase autocomplete search failed"); + throw new QueryFailedException("Keybase autocomplete search failed"); } return json; } catch (JSONException e) { - throw new QueryException("Keybase.io query returned broken JSON"); + throw new QueryFailedException("Keybase.io query returned broken JSON"); } } else { String message = readAll(conn.getErrorStream(), conn.getContentEncoding()); - throw new QueryException("Keybase.io query error (status=" + response + + throw new QueryFailedException("Keybase.io query error (status=" + response + "): " + message); } } catch (Exception e) { - throw new QueryException("Keybase.io query error"); + throw new QueryFailedException("Keybase.io query error"); } } @Override - public String get(String id) throws QueryException { + public String get(String id) throws QueryFailedException { try { JSONObject user = getUser(id); return JWalk.getString(user, "them", "public_keys", "primary", "bundle"); } catch (Exception e) { - throw new QueryException(e.getMessage()); + throw new QueryFailedException(e.getMessage()); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java index 7313a159b..868f543f0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java @@ -24,10 +24,10 @@ import java.io.InputStream; import java.util.List; public abstract class Keyserver { - public static class QueryException extends Exception { + public static class QueryFailedException extends Exception { private static final long serialVersionUID = 2703768928624654512L; - public QueryException(String message) { + public QueryFailedException(String message) { super(message); } } @@ -41,16 +41,17 @@ public abstract class Keyserver { } public static class QueryTooShortException extends QueryNeedsRepairException { + private static final long serialVersionUID = 2703768928624654514L; } public static class AddKeyException extends Exception { private static final long serialVersionUID = -507574859137295530L; } - abstract List search(String query) throws QueryException, + abstract List search(String query) throws QueryFailedException, QueryNeedsRepairException; - abstract String get(String keyIdHex) throws QueryException; + abstract String get(String keyIdHex) throws QueryFailedException; abstract void add(String armoredKey) throws AddKeyException; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java index d297d8b3f..d9bd9b782 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java @@ -211,7 +211,7 @@ public class ImportKeysListFragment extends ListFragment implements @Override public Loader>> - onCreateLoader(int id, Bundle args) { + onCreateLoader(int id, Bundle args) { switch (id) { case LOADER_ID_BYTES: { InputData inputData = getInputData(mKeyBytes, mDataUri); @@ -285,15 +285,15 @@ public class ImportKeysListFragment extends ListFragment implements } else if (error instanceof Keyserver.QueryTooShortException) { AppMsg.makeText(getActivity(), R.string.error_keyserver_insufficient_query, AppMsg.STYLE_ALERT).show(); - } else if (error instanceof Keyserver.QueryException) { - String alert = getActivity().getString(R.string.error_searching_keys); - alert = alert + " (" + error.getLocalizedMessage() + ")"; - AppMsg.makeText(getActivity(), alert, AppMsg.STYLE_ALERT).show(); } else if (error instanceof Keyserver.TooManyResponsesException) { AppMsg.makeText(getActivity(), R.string.error_keyserver_too_many_responses, AppMsg.STYLE_ALERT).show(); - } else if (error instanceof Keyserver.QueryException) { - Log.d(Constants.TAG, "Key server query failed: " + error.getLocalizedMessage()); + } else if (error instanceof Keyserver.QueryFailedException) { + Log.d(Constants.TAG, + "Unrecoverable keyserver query error: " + error.getLocalizedMessage()); + String alert = getActivity().getString(R.string.error_searching_keys); + alert = alert + " (" + error.getLocalizedMessage() + ")"; + AppMsg.makeText(getActivity(), alert, AppMsg.STYLE_ALERT).show(); } break; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListKeybaseLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListKeybaseLoader.java index 3f15e64f0..e8c5da5a7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListKeybaseLoader.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListKeybaseLoader.java @@ -94,7 +94,7 @@ public class ImportKeysListKeybaseLoader mEntryList.addAll(searchResult); mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, null); - } catch (Keyserver.QueryException e) { + } catch (Keyserver.QueryFailedException e) { mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, e); } catch (Keyserver.QueryNeedsRepairException e) { mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, e); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java index 4b2af14a9..4eb6f158b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java @@ -116,7 +116,7 @@ public class ImportKeysListServerLoader mEntryList.addAll(searchResult); } mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, null); - } catch (Keyserver.QueryException e) { + } catch (Keyserver.QueryFailedException e) { mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, e); } catch (Keyserver.QueryNeedsRepairException e) { mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, e);