List of usage examples for org.apache.http.auth AuthenticationException AuthenticationException
public AuthenticationException()
From source file:com.deliciousdroid.client.DeliciousFeed.java
/** * Retrieves a list of contacts in a users network. * //from w w w . j a v a 2 s .co m * @param account The account being synced. * @return The list of contacts received from the server. * @throws JSONException If an error was encountered in deserializing the JSON object returned from * the server. * @throws IOException If a server error was encountered. * @throws AuthenticationException If an authentication error was encountered. */ public static List<User> fetchFriendUpdates(Account account) throws JSONException, IOException, AuthenticationException, FeedForbiddenException { final ArrayList<User> friendList = new ArrayList<User>(); final HttpGet post = new HttpGet(FETCH_FRIEND_UPDATES_URI + account.name); final HttpResponse resp = HttpClientFactory.getThreadSafeClient().execute(post); final String response = EntityUtils.toString(resp.getEntity()); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { final JSONArray friends = new JSONArray(response); Log.d(TAG, response); for (int i = 0; i < friends.length(); i++) { friendList.add(User.valueOf(friends.getJSONObject(i))); } } else { if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { Log.e(TAG, "Authentication exception in fetching remote contacts"); throw new AuthenticationException(); } else if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_FORBIDDEN) { Log.e(TAG, "Fetching contact updates forbidden"); throw new FeedForbiddenException(); } else { Log.e(TAG, "Server error in fetching remote contacts: " + resp.getStatusLine()); throw new IOException(); } } return friendList; }
From source file:org.dvbviewer.controller.io.ServerRequest.java
/** * Execute get.//from w ww.j a v a 2 s . com * * @param client the client * @param request the request * @return the http response * @throws IOException Signals that an I/O exception has occurred. * @throws ClientProtocolException the client protocol exception * @throws AuthenticationException the authentication exception * @author RayBa * @date 05.07.2012 */ private static HttpResponse executeGet(DefaultHttpClient client, HttpGet request, boolean log) throws Exception { if (log) { Log.d(ServerRequest.class.getSimpleName(), "request: " + request.getRequestLine()); } HttpResponse response = client.execute(request); StatusLine status = response.getStatusLine(); Log.d(ServerRequest.class.getSimpleName(), "statusCode: " + status.getStatusCode()); switch (status.getStatusCode()) { case HttpStatus.SC_UNAUTHORIZED: throw new AuthenticationException(); default: break; } return response; }
From source file:info.dc585.hpt.NetworkUtilities.java
/** * * @return @throws JSONException/*from www . ja v a 2 s .com*/ * @throws IOException * @throws AuthenticationException */ public static JSONArray getTopHackers() throws JSONException, IOException, AuthenticationException { // Send the updated friends data to the server Log.i(TAG, "Syncing to: " + SYNC_TOP_HACKERS_URI); final HttpGet get = new HttpGet(SYNC_TOP_HACKERS_URI); final HttpResponse resp = getHttpClient().execute(get); final String response = EntityUtils.toString(resp.getEntity()); if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { Log.e(TAG, "Authentication exception in sending dirty contacts"); throw new AuthenticationException(); } else { Log.e(TAG, "Server error in sending dirty contacts: " + resp.getStatusLine()); throw new IOException(); } } // Our request to the server was successful - so we assume // that they accepted all the changes we sent up, and // that the response includes the contacts that we need // to update on our side... Log.d(TAG, response); final JSONArray hackerList = new JSONArray(response); return hackerList; }
From source file:com.deliciousdroid.client.DeliciousFeed.java
/** * Retrieves a list of bookmark updates for contacts in a users network. * // w w w . j a v a2 s . c om * @param account The account being synced. * @return The list of bookmark updates received from the server. * @throws JSONException If an error was encountered in deserializing the JSON object returned from * the server. * @throws IOException If a server error was encountered. * @throws AuthenticationException If an authentication error was encountered. */ public static List<User.Status> fetchFriendStatuses(Account account) throws JSONException, IOException, AuthenticationException { final ArrayList<User.Status> statusList = new ArrayList<User.Status>(); final HttpGet post = new HttpGet(FETCH_STATUS_URI + account.name + "?count=15"); final HttpResponse resp = HttpClientFactory.getThreadSafeClient().execute(post); final String response = EntityUtils.toString(resp.getEntity()); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { final JSONArray statuses = new JSONArray(response); Log.d(TAG, response); for (int i = 0; i < statuses.length(); i++) { statusList.add(User.Status.valueOf(statuses.getJSONObject(i))); } } else { if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { Log.e(TAG, "Authentication exception in fetching friend status list"); throw new AuthenticationException(); } else { Log.e(TAG, "Server error in fetching friend status list"); throw new IOException(); } } return statusList; }
From source file:org.ohmage.auth.AuthenticatorActivityTest.java
public void testSignInWithOhmage_invalidAccount_showsSignInWithOhmage() throws Exception { when(fakeOhmageService.getAccessToken(fakeEmail, fakePassword)).thenThrow(new AuthenticationException()); final Response fakeResponse = new Response(401, "", new ArrayList<Header>() { }, null);//from ww w . j a v a 2s. c o m doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { ((CancelableCallback) invocation.getArguments()[2]) .failure(RetrofitError.httpError("", fakeResponse, null, null)); return null; } }).when(fakeOhmageService).getAccessToken(eq(fakeEmail), eq(fakePassword), any(CancelableCallback.class)); onView(withId(R.id.sign_in_email_button)).perform(click()); onView(withId(R.id.email)).perform(scrollTo(), typeText(fakeEmail)); onView(withId(R.id.password)).perform(scrollTo(), typeText(fakePassword)); onView(withId(R.id.sign_in_email_button)).perform(click()); onView(withId(R.id.email)).check(matches(isDisplayed())); onView(withId(R.id.password)).check(matches(isDisplayed())); onView(withId(R.id.sign_in_email_button)).check(matches(isDisplayed())); }
From source file:com.deliciousdroid.client.DeliciousFeed.java
public static List<User.Status> fetchFriendStatuses(String friendUsername) throws JSONException, IOException, AuthenticationException { final ArrayList<User.Status> statusList = new ArrayList<User.Status>(); final HttpGet post = new HttpGet(FETCH_BOOKMARKS_URI + friendUsername + "?count=5"); final HttpResponse resp = HttpClientFactory.getThreadSafeClient().execute(post); final String response = EntityUtils.toString(resp.getEntity()); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { final JSONArray statuses = new JSONArray(response); Log.d(TAG, response);/* w ww .j av a2 s. c om*/ for (int i = 0; i < statuses.length(); i++) { statusList.add(User.Status.valueOf(statuses.getJSONObject(i))); } } else { if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { Log.e(TAG, "Authentication exception in fetching friend status list"); throw new AuthenticationException(); } else { Log.e(TAG, "Server error in fetching friend status list"); throw new IOException(); } } return statusList; }
From source file:com.clearcenter.mobile_demo.mdRest.java
static public String GetSystemInfo(String host, String token, long last_sample) throws JSONException, ParseException, IOException, AuthenticationException { try {/*from w ww .ja v a 2s.c o m*/ URL url = new URL("https://" + host + URL_SYSINFO + "/" + last_sample); Log.v(TAG, "GetSystemInfo: host: " + host + ", token: " + token + ", URL: " + url); HttpsURLConnection http = CreateConnection(url); http.setRequestMethod("GET"); http.setRequestProperty("Cookie", token); final StringBuffer response = ProcessRequest(http); // Process response JSONObject json_data = null; try { //Log.i(TAG, "response: " + response.toString()); json_data = new JSONObject(response.toString()); } catch (JSONException e) { Log.e(TAG, "JSONException", e); return ""; } if (json_data.has("result")) { Integer result = RESULT_UNKNOWN; try { result = Integer.valueOf(json_data.getString("result")); } catch (NumberFormatException e) { } Log.d(TAG, "result: " + result.toString()); if (result == RESULT_SUCCESS && json_data.has("data")) { //Log.i(TAG, "data: " + json_data.getString("data")); return json_data.getString("data"); } if (result == RESULT_ACCESS_DENIED) throw new AuthenticationException(); // New cookies? final String cookie = http.getHeaderField("Set-Cookie"); if (cookie != null) { Log.d(TAG, "New cookie!"); } // All other results are failures... throw new IOException(); } } catch (MalformedURLException e) { Log.e(TAG, "MalformedURLException", e); throw new ParseException(); } Log.i(TAG, "Malformed result"); throw new IOException(); }
From source file:com.deliciousdroid.client.DeliciousFeed.java
/** * Retrieves a list of tags for a Delicious user. * //from w ww . jav a 2 s .c o m * @param username Username of the Delicious user. * @return The list of tags received from the server. * @throws JSONException If an error was encountered in deserializing the JSON object returned from * the server. * @throws IOException If a server error was encountered. * @throws AuthenticationException If an authentication error was encountered. */ public static Cursor fetchFriendTags(String username) throws JSONException, IOException, AuthenticationException { final HttpGet post = new HttpGet(FETCH_TAGS_URI + username + "?count=100"); final MatrixCursor tagCursor = new MatrixCursor(new String[] { Tag._ID, Tag.Name, Tag.Count }); final HttpResponse resp = HttpClientFactory.getThreadSafeClient().execute(post); final String response = EntityUtils.toString(resp.getEntity()); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { final JSONObject tags = new JSONObject(response); Iterator<?> i = tags.keys(); while (i.hasNext()) { Object e = i.next(); tagCursor.addRow(new Object[] { 0, e.toString(), tags.getInt(e.toString()) }); } Log.d(TAG, response); } else { if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { Log.e(TAG, "Authentication exception in fetching friend status list"); throw new AuthenticationException(); } else { Log.e(TAG, "Server error in fetching friend status list"); throw new IOException(); } } return tagCursor; }