List of usage examples for org.apache.http.auth AuthenticationException printStackTrace
public void printStackTrace()
From source file:com.sinfonier.util.JSonUtils.java
public static void sendPostDucksBoard(Map<String, Object> json, String url, String apiKey) { HttpClient httpClient = new DefaultHttpClient(); Gson gson = new GsonBuilder().create(); String payload = gson.toJson(json); HttpPost post = new HttpPost(url); post.setEntity(new ByteArrayEntity(payload.getBytes(Charset.forName("UTF-8")))); post.setHeader("Content-type", "application/json"); try {//from w ww .jav a 2 s .c o m post.setHeader(new BasicScheme().authenticate(new UsernamePasswordCredentials(apiKey, "x"), post)); } catch (AuthenticationException e) { e.printStackTrace(); } try { HttpResponse response = httpClient.execute(post); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.deliciousdroid.platform.ContactManager.java
/** * Add a list of status messages to the contacts provider. * /*from ww w.jav a2 s .com*/ * @param context the context to use * @param accountName the username of the logged in user * @param statuses the list of statuses to store */ @TargetApi(15) public static void insertStreamStatuses(Context context, String username) { final ContentValues values = new ContentValues(); final ContentResolver resolver = context.getContentResolver(); final BatchOperation batchOperation = new BatchOperation(context, resolver); List<Long> currentContacts = lookupAllContacts(resolver); for (long id : currentContacts) { String friendUsername = lookupUsername(resolver, id); long watermark = lookupHighWatermark(resolver, id); long newWatermark = watermark; try { List<Status> statuses = DeliciousFeed.fetchFriendStatuses(friendUsername); for (Status status : statuses) { if (status.getTimeStamp().getTime() > watermark) { if (status.getTimeStamp().getTime() > newWatermark) newWatermark = status.getTimeStamp().getTime(); values.clear(); values.put(StreamItems.RAW_CONTACT_ID, id); values.put(StreamItems.TEXT, status.getStatus()); values.put(StreamItems.TIMESTAMP, status.getTimeStamp().getTime()); values.put(StreamItems.ACCOUNT_NAME, username); values.put(StreamItems.ACCOUNT_TYPE, Constants.ACCOUNT_TYPE); values.put(StreamItems.RES_ICON, R.drawable.ic_main); values.put(StreamItems.RES_PACKAGE, context.getPackageName()); values.put(StreamItems.RES_LABEL, R.string.label); batchOperation.add(ContactOperations.newInsertCpo(StreamItems.CONTENT_URI, false) .withValues(values).build()); // A sync adapter should batch operations on multiple contacts, // because it will make a dramatic performance difference. if (batchOperation.size() >= 50) { batchOperation.execute(); } } } values.clear(); values.put(RawContacts.SYNC1, Long.toString(newWatermark)); batchOperation.add(ContactOperations.newUpdateCpo(RawContacts.CONTENT_URI, false).withValues(values) .withSelection(RawContacts._ID + "=?", new String[] { Long.toString(id) }).build()); batchOperation.execute(); } catch (AuthenticationException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:org.muckebox.android.net.RefreshHelper.java
public static Integer refreshArtists() { try {/* w w w .j av a2s. com*/ JSONArray json = ApiHelper.callApiForArray("artists"); ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>( json.length() + 1); operations.add(ContentProviderOperation.newDelete(MuckeboxProvider.URI_ARTISTS).build()); for (int i = 0; i < json.length(); ++i) { JSONObject o = json.getJSONObject(i); operations.add(ContentProviderOperation.newInsert(MuckeboxProvider.URI_ARTISTS) .withValue(ArtistEntry.SHORT_ID, o.getInt("id")) .withValue(ArtistEntry.SHORT_NAME, o.getString("name")).build()); } Muckebox.getAppContext().getContentResolver().applyBatch(MuckeboxProvider.AUTHORITY, operations); } catch (AuthenticationException e) { return R.string.error_authentication; } catch (SSLException e) { return R.string.error_ssl; } catch (IOException e) { Log.d(LOG_TAG, "IOException: " + e.getMessage()); return R.string.error_reload_artists; } catch (JSONException e) { return R.string.error_json; } catch (RemoteException e) { e.printStackTrace(); return R.string.error_reload_artists; } catch (OperationApplicationException e) { e.printStackTrace(); return R.string.error_reload_artists; } return null; }
From source file:org.muckebox.android.net.RefreshHelper.java
public static Integer refreshAlbums() { try {/*from w ww.j a v a 2 s . com*/ JSONArray json = ApiHelper.callApiForArray("albums"); ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>( json.length() + 1); operations.add(ContentProviderOperation.newDelete(MuckeboxProvider.URI_ALBUMS).build()); for (int i = 0; i < json.length(); ++i) { JSONObject o = json.getJSONObject(i); operations.add(ContentProviderOperation.newInsert(MuckeboxProvider.URI_ALBUMS) .withValue(AlbumEntry.SHORT_ID, o.getInt("id")) .withValue(AlbumEntry.SHORT_TITLE, o.getString("title")) .withValue(AlbumEntry.SHORT_ARTIST_ID, o.getInt("artist_id")) .withValue(AlbumEntry.SHORT_CREATED, o.getInt("created")).build()); } Muckebox.getAppContext().getContentResolver().applyBatch(MuckeboxProvider.AUTHORITY, operations); Log.d(LOG_TAG, "Got " + json.length() + " albums"); } catch (AuthenticationException e) { return R.string.error_authentication; } catch (SSLException e) { return R.string.error_ssl; } catch (IOException e) { Log.d(LOG_TAG, "IOException: " + e.getMessage()); return R.string.error_reload_albums; } catch (JSONException e) { return R.string.error_json; } catch (RemoteException e) { e.printStackTrace(); return R.string.error_reload_albums; } catch (OperationApplicationException e) { e.printStackTrace(); return R.string.error_reload_albums; } return null; }
From source file:org.muckebox.android.net.RefreshHelper.java
public static Integer refreshTracks(long albumId) { try {// www . ja va 2 s.c o m ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(1); JSONArray json = ApiHelper.callApiForArray("tracks", null, new String[] { "album" }, new String[] { Long.toString(albumId) }); operations.ensureCapacity(operations.size() + json.length() + 1); operations.add(ContentProviderOperation .newDelete(Uri.withAppendedPath(MuckeboxProvider.URI_TRACKS_ALBUM, Long.toString(albumId))) .build()); for (int j = 0; j < json.length(); ++j) { JSONObject o = json.getJSONObject(j); ContentValues values = new ContentValues(); values.put(TrackEntry.SHORT_ID, o.getInt("id")); values.put(TrackEntry.SHORT_ARTIST_ID, o.getInt("artist_id")); values.put(TrackEntry.SHORT_ALBUM_ID, o.getInt("album_id")); values.put(TrackEntry.SHORT_TITLE, o.getString("title")); if (!o.isNull("tracknumber")) values.put(TrackEntry.SHORT_TRACKNUMBER, o.getInt("tracknumber")); if (!o.isNull("discnumber")) values.put(TrackEntry.SHORT_DISCNUMBER, o.getInt("discnumber")); values.put(TrackEntry.SHORT_LABEL, o.getString("label")); values.put(TrackEntry.SHORT_CATALOGNUMBER, o.getString("catalognumber")); values.put(TrackEntry.SHORT_LENGTH, o.getInt("length")); values.put(TrackEntry.SHORT_DATE, o.getString("date")); operations.add(ContentProviderOperation .newDelete( Uri.withAppendedPath(MuckeboxProvider.URI_TRACKS, Integer.toString(o.getInt("id")))) .build()); operations.add( ContentProviderOperation.newInsert(MuckeboxProvider.URI_TRACKS).withValues(values).build()); } Log.d(LOG_TAG, "Got " + json.length() + " Tracks"); Muckebox.getAppContext().getContentResolver().applyBatch(MuckeboxProvider.AUTHORITY, operations); } catch (AuthenticationException e) { return R.string.error_authentication; } catch (SSLException e) { return R.string.error_ssl; } catch (IOException e) { Log.d(LOG_TAG, "IOException: " + e.getMessage()); return R.string.error_reload_tracks; } catch (JSONException e) { return R.string.error_json; } catch (RemoteException e) { e.printStackTrace(); return R.string.error_reload_tracks; } catch (OperationApplicationException e) { e.printStackTrace(); return R.string.error_reload_tracks; } return null; }
From source file:org.restcomm.connect.java.sdk.ExceptionHandler.java
public ExceptionHandler(final CloseableHttpResponse response) { this.response = response; int StatusCode; StatusCode = response.getStatusLine().getStatusCode(); try {//www .jav a 2s . c o m if (StatusCode == 401) throw new AuthenticationException("The Credentials Provided Are Incorrect"); if (StatusCode == 404) throw new ResourceNotFoundException("The Requested Resource Is Not Available"); } catch (AuthenticationException e) { e.printStackTrace(); } catch (ResourceNotFoundException e) { e.printStackTrace(); } }
From source file:com.pindroid.service.AccountService.java
@Override protected void onHandleIntent(Intent intent) { mAccountManager = AccountManager.get(this); Account[] accounts = mAccountManager.getAccountsByType(Constants.ACCOUNT_TYPE); ArrayList<String> accountsList = new ArrayList<String>(); for (int i = 0; i < accounts.length; i++) { accountsList.add(accounts[i].name); }/*from w w w . java 2 s. c o m*/ BookmarkManager.TruncateBookmarks(accountsList, this, true); TagManager.TruncateOldTags(accountsList, this); if (accounts.length > 0) { for (Account a : accounts) { Log.d("AS Handle", "Getting Token for " + a.name); try { String token = PinboardApi.getSecretToken(a, this); mAccountManager.setUserData(a, Constants.PREFS_SECRET_TOKEN, token); } catch (AuthenticationException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (TooManyRequestsException e) { e.printStackTrace(); } } } }
From source file:pt.up.mobile.authenticator.Authenticator.java
@Override public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle loginOptions) throws NetworkErrorException { Log.v(TAG, "getAuthToken()"); // If the caller requested an authToken type we don't support, then // return an error if (!authTokenType.equals(Constants.AUTHTOKEN_TYPE)) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ERROR_MESSAGE, "invalid authTokenType"); return result; }/*from www .ja v a 2 s . c o m*/ try { final AccountManager am = AccountManager.get(mContext); final String peek = am.peekAuthToken(account, authTokenType); if (peek != null) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNT_TYPE); result.putString(AccountManager.KEY_AUTHTOKEN, peek); return result; } // Extract the username and password from the Account Manager, and // ask // the server for an appropriate AuthToken. final String password = am.getPassword(account); if (password != null) { String[] reply; reply = SifeupAPI.authenticate(account.name, password, mContext); final String authToken = reply[1]; if (!TextUtils.isEmpty(authToken)) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNT_TYPE); result.putString(AccountManager.KEY_AUTHTOKEN, authToken); return result; } } } catch (AuthenticationException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); throw new NetworkErrorException(); } // If we get here, then we couldn't access the user's password - so we // need to re-prompt them for their credentials. We do that by creating // an intent to display our AuthenticatorActivity panel. final Intent intent = new Intent(mContext, AuthenticatorActivity.class); intent.putExtra(AuthenticatorActivity.PARAM_CONFIRM_CREDENTIALS, true); intent.putExtra(AuthenticatorActivity.PARAM_USERNAME, account.name); intent.putExtra(AuthenticatorActivity.PARAM_AUTHTOKEN_TYPE, authTokenType); intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); final Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); return bundle; }
From source file:org.dvbviewer.controller.ui.fragments.StatusList.java
@Override public Loader<Status> onCreateLoader(int arg0, Bundle arg1) { AsyncLoader<Status> loader = new AsyncLoader<Status>(getActivity()) { @Override/* w w w . j a v a 2 s. co m*/ public Status loadInBackground() { Status result = null; try { String statusXml = ServerRequest.getRSString(ServerConsts.URL_STATUS); StatusHandler statusHandler = new StatusHandler(); result = statusHandler.parse(statusXml); String versionXml = ServerRequest.getRSString(ServerConsts.URL_VERSION); VersionHandler versionHandler = new VersionHandler(); String version = versionHandler.parse(versionXml); StatusItem versionItem = new StatusItem(); versionItem.setNameRessource(R.string.status_rs_version); versionItem.setValue(version); result.getItems().add(0, versionItem); } catch (AuthenticationException e) { Log.e(ChannelEpg.class.getSimpleName(), "AuthenticationException"); e.printStackTrace(); showToast(getString(R.string.error_invalid_credentials)); } catch (ParseException e) { Log.e(ChannelEpg.class.getSimpleName(), "ParseException"); e.printStackTrace(); } catch (ClientProtocolException e) { Log.e(ChannelEpg.class.getSimpleName(), "ClientProtocolException"); e.printStackTrace(); } catch (IOException e) { Log.e(ChannelEpg.class.getSimpleName(), "IOException"); e.printStackTrace(); } catch (URISyntaxException e) { Log.e(ChannelEpg.class.getSimpleName(), "URISyntaxException"); e.printStackTrace(); showToast(getString(R.string.error_invalid_url) + "\n\n" + ServerConsts.REC_SERVICE_URL); } catch (IllegalStateException e) { Log.e(ChannelEpg.class.getSimpleName(), "IllegalStateException"); e.printStackTrace(); showToast(getString(R.string.error_invalid_url) + "\n\n" + ServerConsts.REC_SERVICE_URL); } catch (IllegalArgumentException e) { Log.e(ChannelEpg.class.getSimpleName(), "IllegalArgumentException"); showToast(getString(R.string.error_invalid_url) + "\n\n" + ServerConsts.REC_SERVICE_URL); } catch (Exception e) { Log.e(ChannelEpg.class.getSimpleName(), "Exception"); e.printStackTrace(); } return result; } }; return loader; }
From source file:ca.etsmtl.applets.etsmobile.ProfileActivity.java
private void getBandwith(String phase, String appt) { appt_input.setEnabled(false);/*from www . ja v a 2s .c om*/ phase_input.setEnabled(false); final Editor edit = prefs.edit(); creds.setPhase(phase); creds.setAppt(appt); edit.putString(UserCredentials.REZ, phase); edit.putString(UserCredentials.APPT, appt); edit.commit(); // get bandwidth from cooptel, parse html, extract floats, etc etc new AsyncTask<String, Void, float[]>() { final Pattern usageRegex = Pattern.compile( "<TR><TD>(.*)</TD><TD>(.*)</TD><TD ALIGN=\"RIGHT\">(.*)</TD><TD ALIGN=\"RIGHT\">(.*)</TD></TR>"); final Pattern quotaRegex = Pattern.compile( "<TR><TD>Quota permis pour la période</TD><TD ALIGN=\"RIGHT\">(.*)</TD></TD></TR>"); @Override protected float[] doInBackground(String... params) { final float[] result = new float[2]; try { final HttpGet get = new HttpGet(URI.create( String.format("http://www2.cooptel.qc.ca/services/temps/?mois=%d&cmd=Visualiser", Calendar.getInstance().get(Calendar.MONTH) + 1))); final BasicScheme scheme = new BasicScheme(); final Credentials credentials = new UsernamePasswordCredentials( "ets-res" + params[0] + "-" + params[1], "ets" + params[1]); try { final Header h = scheme.authenticate(credentials, get); get.addHeader(h); final HttpClient client = new DefaultHttpClient(); final HttpResponse re = client.execute(get); // if HTTP200 if (re.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { final String ent = EntityUtils.toString(re.getEntity()); final Matcher matcher = usageRegex.matcher(ent); float total = 0; // String[] usageResult = matcher.; // parse all results while (matcher.find()) { final Number upload = Float.parseFloat(matcher.group(3)); final Number download = Float.parseFloat(matcher.group(4)); total += upload.floatValue(); total += download.floatValue(); } final Matcher quotaResult = quotaRegex.matcher(ent); float totalBandwithAvail = 0; if (quotaResult.find()) { totalBandwithAvail = Float.parseFloat(quotaResult.group(1)); } result[0] = total / 1024; result[1] = totalBandwithAvail / 1024; } } catch (final AuthenticationException e) { e.printStackTrace(); } } catch (final IOException e) { e.printStackTrace(); } return result; } @Override protected void onPostExecute(float[] result) { handlerBandwith.obtainMessage(2, result).sendToTarget(); super.onPostExecute(result); } }.execute(phase, appt); }