Example usage for org.apache.http.auth AuthenticationException getMessage

List of usage examples for org.apache.http.auth AuthenticationException getMessage

Introduction

In this page you can find the example usage for org.apache.http.auth AuthenticationException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.muckebox.android.net.RefreshHelper.java

public static Integer refreshArtists() {
    try {//from  ww  w .  j  a v  a  2  s  .  c o m
        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 {/* ww w.  j a v  a  2s  .co m*/
        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 {/*from ww  w .j  av  a 2s.  co  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:com.amalto.workbench.utils.HttpClientUtil.java

private static void authenticate(String username, String password, HttpUriRequest request,
        HttpContext preemptiveContext) {
    try {/*from  w ww  .  ja v  a 2 s  .  c o m*/
        BasicScheme basicScheme = new BasicScheme();
        Header authenticateHeader = basicScheme
                .authenticate(new UsernamePasswordCredentials(username, password), request, preemptiveContext);
        request.addHeader(authenticateHeader);
    } catch (AuthenticationException e) {
        log.error(e.getMessage(), e);
    }
}

From source file:com.arcbees.vcs.AbstractVcsApi.java

protected void includeAuthentication(HttpRequest request, Credentials credentials) throws IOException {
    try {//from  ww w. j a  va 2s .  c o  m
        request.addHeader(new BasicScheme().authenticate(credentials, request, null));
    } catch (AuthenticationException e) {
        throw new IOException("Failed to set authentication for request. " + e.getMessage(), e);
    }
}

From source file:nl.esciencecenter.octopus.webservice.mac.MacSchemeTest.java

@Test
public void testAuthenticateInvalidAlgorithm() throws URISyntaxException {
    String id = "eyJzYWx0IjogIjU3MjY0NCIsICJleHBpcmVzIjogMTM4Njc3MjEwOC4yOTIyNTUsICJ1c2VyaWQiOiAiam9ibWFuYWdlciJ9KBJRMeTW2G9I6jlYwRj6j8koAek=";
    String key = "_B1YfcqEYpZxyTx_-411-QdBOSI=";
    MacCredential credentials = new MacCredential(id, key, new URI("http://localhost"));
    credentials.setAlgorithm("blowfish");
    HttpGet request = new HttpGet("http://localhost");
    try {/*from   w  w  w  . j  a va 2  s .  c  o m*/
        scheme.authenticate(credentials, request, null);
        fail();
    } catch (AuthenticationException e) {
        assertEquals("Algorithm is not supported", e.getMessage());
    }
}

From source file:jetbrains.buildServer.commitPublisher.github.api.impl.GitHubApiImpl.java

private void includeAuthentication(@NotNull HttpRequest request) throws IOException {
    try {//ww w. j  a v  a  2  s. c  o m
        setAuthentication(request);
    } catch (AuthenticationException e) {
        throw new IOException("Failed to set authentication for request. " + e.getMessage(), e);
    }
}

From source file:org.callimachusproject.client.HttpAuthenticator.java

private void generateAuthResponse(final HttpRequest request, final AuthState authState,
        final HttpContext context) throws HttpException, IOException {
    AuthScheme authScheme = authState.getAuthScheme();
    Credentials creds = authState.getCredentials();
    switch (authState.getState()) {
    case FAILURE:
        return;/*  www .j a  v  a  2s . c  o m*/
    case SUCCESS:
        ensureAuthScheme(authScheme);
        if (authScheme.isConnectionBased()) {
            return;
        }
        break;
    case CHALLENGED:
        final Queue<AuthOption> authOptions = authState.getAuthOptions();
        if (authOptions != null) {
            while (!authOptions.isEmpty()) {
                final AuthOption authOption = authOptions.remove();
                authScheme = authOption.getAuthScheme();
                creds = authOption.getCredentials();
                authState.update(authScheme, creds);
                if (this.log.isDebugEnabled()) {
                    this.log.debug("Generating response to an authentication challenge using "
                            + authScheme.getSchemeName() + " scheme");
                }
                try {
                    final Header header = doAuth(authScheme, creds, request, context);
                    request.addHeader(header);
                    break;
                } catch (final AuthenticationException ex) {
                    if (this.log.isWarnEnabled()) {
                        this.log.warn(authScheme + " authentication error: " + ex.getMessage());
                    }
                }
            }
            return;
        } else {
            ensureAuthScheme(authScheme);
        }
    }
    if (authScheme != null) {
        try {
            final Header header = doAuth(authScheme, creds, request, context);
            request.addHeader(header);
        } catch (final AuthenticationException ex) {
            if (this.log.isErrorEnabled()) {
                this.log.error(authScheme + " authentication error: " + ex.getMessage());
            }
        }
    }
}

From source file:org.klnusbaum.udj.network.EventCommService.java

private void enterEvent(Intent intent, AccountManager am, Account account, boolean attemptReauth) {
    if (!Utils.isNetworkAvailable(this)) {
        doLoginFail(am, account, EventJoinError.NO_NETWORK_ERROR);
        return;/*from w w  w.  ja  v a 2  s  .  co  m*/
    }

    long userId, eventId;
    String authToken;
    //TODO hanle error if account isn't provided
    try {
        userId = Long.valueOf(am.getUserData(account, Constants.USER_ID_DATA));
        //TODO handle if event id isn't provided
        authToken = am.blockingGetAuthToken(account, "", true);
        eventId = intent.getLongExtra(Constants.EVENT_ID_EXTRA, Constants.NO_EVENT_ID);
    } catch (OperationCanceledException e) {
        Log.e(TAG, "Operation canceled exception in EventCommService");
        doLoginFail(am, account, EventJoinError.AUTHENTICATION_ERROR);
        return;
    } catch (AuthenticatorException e) {
        Log.e(TAG, "Authenticator exception in EventCommService");
        doLoginFail(am, account, EventJoinError.AUTHENTICATION_ERROR);
        return;
    } catch (IOException e) {
        Log.e(TAG, "IO exception in EventCommService");
        doLoginFail(am, account, EventJoinError.AUTHENTICATION_ERROR);
        return;
    }

    try {
        ServerConnection.joinEvent(eventId, userId, authToken);
        setEventData(intent, am, account);
        ContentResolver cr = getContentResolver();
        UDJEventProvider.eventCleanup(cr);
        HashMap<Long, Long> previousRequests = ServerConnection.getAddRequests(userId, eventId, authToken);
        UDJEventProvider.setPreviousAddRequests(cr, previousRequests);
        JSONObject previousVotes = ServerConnection.getVoteRequests(userId, eventId, authToken);
        UDJEventProvider.setPreviousVoteRequests(cr, previousVotes);
        Intent joinedEventIntent = new Intent(Constants.JOINED_EVENT_ACTION);
        am.setUserData(account, Constants.LAST_EVENT_ID_DATA, String.valueOf(eventId));
        am.setUserData(account, Constants.EVENT_STATE_DATA, String.valueOf(Constants.IN_EVENT));
        sendBroadcast(joinedEventIntent);
    } catch (IOException e) {
        Log.e(TAG, "IO exception when joining event");
        Log.e(TAG, e.getMessage());
        doLoginFail(am, account, EventJoinError.SERVER_ERROR);
    } catch (JSONException e) {
        Log.e(TAG, "JSON exception when joining event");
        Log.e(TAG, e.getMessage());
        doLoginFail(am, account, EventJoinError.SERVER_ERROR);
    } catch (AuthenticationException e) {
        handleLoginAuthException(intent, am, account, authToken, attemptReauth);
    } catch (EventOverException e) {
        Log.e(TAG, "Event Over Exception when joining event");
        //Log.e(TAG, e.getMessage());
        doLoginFail(am, account, EventJoinError.EVENT_OVER_ERROR);
    } catch (AlreadyInEventException e) {
        Log.e(TAG, "Already In Event Exception when joining event");
        try {
            ServerConnection.leaveEvent(e.getEventId(), userId, authToken);
            enterEvent(intent, am, account, true);
        } catch (AuthenticationException f) {
            handleLoginAuthException(intent, am, account, authToken, attemptReauth);
        } catch (IOException f) {
            Log.e(TAG, "IO exception when attempting to leave one event before " + "joining another");
            Log.e(TAG, f.getMessage());
            doLoginFail(am, account, EventJoinError.SERVER_ERROR);
        }
    }
}

From source file:info.ajaxplorer.client.http.RestRequest.java

private void authenticate() throws AuthenticationException {
    loginStateChanged = false;//  ww w .ja va 2 s .  com
    AjxpAPI API = AjxpAPI.getInstance();
    try {
        if (authStep.equals("RENEW-TOKEN")) {

            JSONObject jObject = this.getJSonContent(API.getGetSecureTokenUri());
            RestStateHolder.getInstance().setSECURE_TOKEN(jObject.getString("SECURE_TOKEN"));
            loginStateChanged = true;

        } else {

            String seed = this.getStringContent(API.getGetLoginSeedUri());
            if (seed != null)
                seed = seed.trim();
            if (seed.indexOf("captcha") > -1) {
                throw new AuthenticationException(AUTH_ERROR_LOCKEDOUT);
            }
            if (!RestStateHolder.getInstance().isServerSet()) {
                throw new AuthenticationException(AUTH_ERROR_NOSERVER);
            }
            String user = RestStateHolder.getInstance().getServer().getUser();
            String password = RestStateHolder.getInstance().getServer().getPassword();
            if (!seed.trim().equals("-1")) {
                password = RestRequest.md5(password) + seed;
                password = RestRequest.md5(password);
            }
            Document doc = this.getDocumentContent(API.makeLoginUri(user, password, seed));
            if (doc.getElementsByTagName("logging_result").getLength() > 0) {
                String result = doc.getElementsByTagName("logging_result").item(0).getAttributes()
                        .getNamedItem("value").getNodeValue();
                if (result.equals("1")) {
                    //Log.d("RestRequest Authentication", "LOGGING SUCCEED! REFRESHING TOKEN");
                    String newToken = doc.getElementsByTagName("logging_result").item(0).getAttributes()
                            .getNamedItem("secure_token").getNodeValue();
                    RestStateHolder.getInstance().setSECURE_TOKEN(newToken);
                    loginStateChanged = true;
                } else {
                    //Log.d("RestRequest Authentication", "Login Failed");
                    throw new AuthenticationException(AUTH_ERROR_LOGIN_FAILED);
                }
            }

        }
    } catch (AuthenticationException e) {
        throw e;
    } catch (Exception e) {
        throw new AuthenticationException(e.getMessage());
    }
}