mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-30 12:32:17 -05:00
Finished cleaning up rebase conflicts post Keyserver exception refactor
This commit is contained in:
parent
1ff3962acc
commit
58da3d12b0
@ -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<ImportKeysListEntry> search(String query) throws QueryException,
|
||||
public ArrayList<ImportKeysListEntry> search(String query) throws QueryFailedException,
|
||||
QueryNeedsRepairException {
|
||||
ArrayList<ImportKeysListEntry> results = new ArrayList<ImportKeysListEntry>();
|
||||
|
||||
@ -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();
|
||||
|
@ -34,7 +34,7 @@ public class KeybaseKeyserver extends Keyserver {
|
||||
private String mQuery;
|
||||
|
||||
@Override
|
||||
public ArrayList<ImportKeysListEntry> search(String query) throws QueryException,
|
||||
public ArrayList<ImportKeysListEntry> search(String query) throws QueryFailedException,
|
||||
QueryNeedsRepairException {
|
||||
ArrayList<ImportKeysListEntry> results = new ArrayList<ImportKeysListEntry>();
|
||||
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<ImportKeysListEntry> search(String query) throws QueryException,
|
||||
abstract List<ImportKeysListEntry> 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;
|
||||
|
||||
|
@ -211,7 +211,7 @@ public class ImportKeysListFragment extends ListFragment implements
|
||||
|
||||
@Override
|
||||
public Loader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>>
|
||||
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;
|
||||
|
||||
|
@ -94,7 +94,7 @@ public class ImportKeysListKeybaseLoader
|
||||
|
||||
mEntryList.addAll(searchResult);
|
||||
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, null);
|
||||
} catch (Keyserver.QueryException e) {
|
||||
} catch (Keyserver.QueryFailedException e) {
|
||||
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e);
|
||||
} catch (Keyserver.QueryNeedsRepairException e) {
|
||||
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e);
|
||||
|
@ -116,7 +116,7 @@ public class ImportKeysListServerLoader
|
||||
mEntryList.addAll(searchResult);
|
||||
}
|
||||
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, null);
|
||||
} catch (Keyserver.QueryException e) {
|
||||
} catch (Keyserver.QueryFailedException e) {
|
||||
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e);
|
||||
} catch (Keyserver.QueryNeedsRepairException e) {
|
||||
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e);
|
||||
|
Loading…
Reference in New Issue
Block a user