Package com.box.boxjavalibv2.exceptions

Examples of com.box.boxjavalibv2.exceptions.AuthFatalFailureException


     * @throws AuthFatalFailureException
     */
    private BoxOAuthToken getAuthData(int[] numRetry) throws AuthFatalFailureException {
        int num = numRetry[0];
        if (num * WAIT > mWaitTimeOut) {
            throw new AuthFatalFailureException();
        }

        if (getAndSetLock(false)) {
            return mOAuthToken;
        }
        else {
            if (getTokenState() == OAuthTokenState.FAIL) {
                throw new AuthFatalFailureException();
            }
            doWait();
            numRetry[0]++;
            return getAuthData(numRetry);
        }
View Full Code Here


            unlock();
        }
        catch (Exception e) {
            setTokenState(OAuthTokenState.FAIL);
            throw new AuthFatalFailureException(true);
        }
    }
View Full Code Here

            } else {
                doWait(WAIT);
                num++;
            }
        }
        throw new AuthFatalFailureException(getRefreshFailException());
    }
View Full Code Here

        long num = 0;
        while (num * WAIT <= mWaitTimeOut) {
            if (getAndSetLock(false)) {
                if (getTokenState() == OAuthTokenState.PRE_CREATION) {
                    if (!mAutoRefresh) {
                        throw new AuthFatalFailureException(getRefreshFailException());
                    } else {
                        refresh();
                        return guaranteedGetAuthData();
                    }
                } else if (getTokenState() == OAuthTokenState.FAIL) {
                    throw new AuthFatalFailureException(getRefreshFailException());
                } else {
                    return mOAuthToken;
                }
            } else {
                doWait(WAIT);
                num++;
            }
        }
        throw new AuthFatalFailureException(getRefreshFailException());
    }
View Full Code Here

            getAuthData();
        } else {
            try {
                if (getTokenState() == OAuthTokenState.FAIL || !mAutoRefresh) {
                    internalSetTokenState(OAuthTokenState.FAIL);
                    throw new AuthFatalFailureException(getRefreshFailException());
                } else {
                    doRefresh();
                }
            } finally {
                unlock();
View Full Code Here

    protected void doRefresh() throws AuthFatalFailureException {
        internalSetTokenState(OAuthTokenState.REFRESHING);

        if (mOAuthToken == null) {
            setRefreshFail(new BoxRestException("OAuthToken is null"));
            throw new AuthFatalFailureException(getRefreshFailException());
        }

        String refreshToken = mOAuthToken.getRefreshToken();
        try {
            mOAuthToken = mClient.getOAuthManager().refreshOAuth(refreshToken, mClientId, mClientSecret, mDeviceId, mDeviceName);
            internalSetTokenState(OAuthTokenState.AVAILABLE);
            setRefreshFail(null);
            if (refreshListener != null) {
                refreshListener.onRefresh(mOAuthToken);
            }
        } catch (BoxRestException e) {
            // A BoxRestException indicates a network error or a json parsing error. In this case, there is no reason to enter a failure state. Just throw an
            // exception and set the token state back to AVAILABLE so the app can retry if it wishes.
            internalSetTokenState(OAuthTokenState.AVAILABLE);
            throw new AuthFatalFailureException(e, refreshToken);
        } catch (BoxServerException e) {
            // A BoxServerException indicates an error from the server. This could be a 500, 403, 400, etc. The only case in which this is a permanent failure
            // is if we get a 400, which means the user's refresh token is invalid. In that case, we call setRefreshFail to enter a failure state until the user
            // re-logs-in. In the case of any other status, we set the token state back to AVAILABLE to allow the app to retry if it wishes.
            if (e.getStatusCode() == HttpStatus.SC_BAD_REQUEST) {
                setRefreshFail(e);
            } else {
                internalSetTokenState(OAuthTokenState.AVAILABLE);
            }
            throw new AuthFatalFailureException(e, refreshToken);
        }
    }
View Full Code Here

    }

    @Override
    public BoxOAuthToken refreshOAuth(final BoxOAuthRequestObject requestObject) throws BoxRestException, BoxServerException, AuthFatalFailureException {
        if (refreshShouldFail) {
            throw new AuthFatalFailureException();
        }
        // Let's say refreshing a token takes 1 second.
        try {
            Thread.sleep(1000);
        }
View Full Code Here

        try {
            final Map<String, Object> headers = new HashMap<String, Object>();
            // parameter type is String
            headers.put("CamelBox.folderId", testFolder.getId());
            // parameter type is com.box.boxjavalibv2.requests.requestobjects.BoxSharedLinkRequestObject
            final BoxSharedLinkRequestEntity sharedLink = new BoxSharedLinkRequestEntity(
                    BoxSharedLinkAccess.COLLABORATORS);
            headers.put("CamelBox.sharedLinkRequest",
                    BoxSharedLinkRequestObject.createSharedLinkRequestObject(sharedLink));

            BoxFolder result = requestBodyAndHeaders("direct://CREATESHAREDLINK", null, headers);
View Full Code Here

    private BoxCollaboration createCollaboration() throws InterruptedException {
        final Map<String, Object> headers = new HashMap<String, Object>();
        // parameter type is String
        headers.put("CamelBox.folderId", testFolderId);
        // parameter type is com.box.boxjavalibv2.requests.requestobjects.BoxCollabRequestObject
        final BoxCollabRequestObject collabObject = BoxCollabRequestObject.createCollabObject(testFolderId, null,
                "camel.test@localhost.com", BoxCollaborationRole.VIEWER);
        headers.put("CamelBox.collabRequest", collabObject);

        BoxCollaboration result = requestBodyAndHeaders("direct://CREATECOLLABORATION",
                null, headers);
View Full Code Here

        try {
            final Map<String, Object> headers = new HashMap<String, Object>();
            // parameter type is String
            headers.put("CamelBox.collabId", collaboration.getId());
            // parameter type is com.box.boxjavalibv2.requests.requestobjects.BoxCollabRequestObject
            final BoxCollabRequestObject requestObject = BoxCollabRequestObject.updateCollabObjects(
                    BoxCollaborationRole.EDITOR);
            headers.put("CamelBox.collabRequest", requestObject);

            BoxCollaboration result = requestBodyAndHeaders("direct://UPDATECOLLABORATION", null, headers);
            assertNotNull("updateCollaboration result", result);
View Full Code Here

TOP

Related Classes of com.box.boxjavalibv2.exceptions.AuthFatalFailureException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.